2003-09-25 18:27:20

by Martin Schwidefsky

[permalink] [raw]
Subject: [PATCH] s390 (9/19): xpram driver.

- Make xpram work on 64 bit machines.
- Use new-style module_param.

diffstat:
drivers/s390/block/xpram.c | 45 ++++++++++++++++++++++++++-------------------
1 files changed, 26 insertions(+), 19 deletions(-)

diff -urN linux-2.6/drivers/s390/block/xpram.c linux-2.6-s390/drivers/s390/block/xpram.c
--- linux-2.6/drivers/s390/block/xpram.c Mon Sep 8 21:50:18 2003
+++ linux-2.6-s390/drivers/s390/block/xpram.c Thu Sep 25 18:33:28 2003
@@ -26,11 +26,12 @@
*/

#include <linux/module.h>
-#include <linux/version.h>
+#include <linux/moduleparam.h>
#include <linux/ctype.h> /* isdigit, isxdigit */
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/slab.h>
+#include <linux/blkdev.h>
#include <linux/blkpg.h>
#include <linux/hdreg.h> /* HDIO_GETGEO */
#include <linux/sysdev.h>
@@ -58,23 +59,23 @@
};

typedef struct {
- unsigned long size; /* size of xpram segment in pages */
- unsigned long offset; /* start page of xpram segment */
+ unsigned int size; /* size of xpram segment in pages */
+ unsigned int offset; /* start page of xpram segment */
} xpram_device_t;

static xpram_device_t xpram_devices[XPRAM_MAX_DEVS];
-static int xpram_sizes[XPRAM_MAX_DEVS];
+static unsigned int xpram_sizes[XPRAM_MAX_DEVS];
static struct gendisk *xpram_disks[XPRAM_MAX_DEVS];
-static unsigned long xpram_pages;
+static unsigned int xpram_pages;
static int xpram_devs;

/*
* Parameter parsing functions.
*/
static int devs = XPRAM_DEVS;
-static unsigned long sizes[XPRAM_MAX_DEVS];
+static unsigned int sizes[XPRAM_MAX_DEVS];

-MODULE_PARM(devs,"i");
+module_param(devs, int, 0);
MODULE_PARM(sizes,"1-" __MODULE_STRING(XPRAM_MAX_DEVS) "i");

MODULE_PARM_DESC(devs, "number of devices (\"partitions\"), " \
@@ -149,7 +150,7 @@
* -EIO: if pgin failed
* -ENXIO: if xpram has vanished
*/
-static int xpram_page_in (unsigned long page_addr, unsigned long xpage_index)
+static int xpram_page_in (unsigned long page_addr, unsigned int xpage_index)
{
int cc;

@@ -180,7 +181,7 @@
return -ENXIO;
}
if (cc == 1) {
- PRINT_ERR("page in failed for page index %ld.\n",
+ PRINT_ERR("page in failed for page index %u.\n",
xpage_index);
return -EIO;
}
@@ -197,7 +198,7 @@
* -EIO: if pgout failed
* -ENXIO: if xpram has vanished
*/
-static long xpram_page_out (unsigned long page_addr, unsigned long xpage_index)
+static long xpram_page_out (unsigned long page_addr, unsigned int xpage_index)
{
int cc;

@@ -228,7 +229,7 @@
return -ENXIO;
}
if (cc == 1) {
- PRINT_ERR("page out failed for page index %ld.\n",
+ PRINT_ERR("page out failed for page index %u.\n",
xpage_index);
return -EIO;
}
@@ -244,6 +245,8 @@
int rc;

mem_page = (unsigned long) __get_free_page(GFP_KERNEL);
+ if (!mem_page)
+ return -ENOMEM;
rc = xpram_page_in(mem_page, 0);
free_page(mem_page);
return rc ? -ENXIO : 0;
@@ -254,13 +257,15 @@
*/
static unsigned long __init xpram_highest_page_index(void)
{
- unsigned long page_index, add_bit;
+ unsigned int page_index, add_bit;
unsigned long mem_page;

mem_page = (unsigned long) __get_free_page(GFP_KERNEL);
+ if (!mem_page)
+ return 0;

page_index = 0;
- add_bit = 1ULL << (sizeof(unsigned long)*8 - 1);
+ add_bit = 1ULL << (sizeof(unsigned int)*8 - 1);
while (add_bit > 0) {
if (xpram_page_in(mem_page, page_index | add_bit) == 0)
page_index |= add_bit;
@@ -279,7 +284,7 @@
{
xpram_device_t *xdev = bio->bi_bdev->bd_disk->private_data;
struct bio_vec *bvec;
- unsigned long index;
+ unsigned int index;
unsigned long page_addr;
unsigned long bytes;
int i;
@@ -290,6 +295,8 @@
if ((bio->bi_size >> 12) > xdev->size)
/* Request size is no page-aligned. */
goto fail;
+ if ((bio->bi_sector >> 3) > 0xffffffffU - xdev->offset)
+ goto fail;
index = (bio->bi_sector >> 3) + xdev->offset;
bio_for_each_segment(bvec, bio, i) {
page_addr = (unsigned long)
@@ -382,13 +389,13 @@
PRINT_INFO(" number of devices (partitions): %d \n", xpram_devs);
for (i = 0; i < xpram_devs; i++) {
if (xpram_sizes[i])
- PRINT_INFO(" size of partition %d: %d kB\n",
+ PRINT_INFO(" size of partition %d: %u kB\n",
i, xpram_sizes[i]);
else
PRINT_INFO(" size of partition %d to be set "
"automatically\n",i);
}
- PRINT_DEBUG(" memory needed (for sized partitions): %ld kB\n",
+ PRINT_DEBUG(" memory needed (for sized partitions): %lu kB\n",
mem_needed);
PRINT_DEBUG(" partitions to be sized automatically: %d\n",
mem_auto_no);
@@ -407,7 +414,7 @@
if (mem_auto_no) {
mem_auto = ((pages - mem_needed / 4) / mem_auto_no) * 4;
PRINT_INFO(" automatically determined "
- "partition size: %ld kB\n", mem_auto);
+ "partition size: %lu kB\n", mem_auto);
for (i = 0; i < xpram_devs; i++)
if (xpram_sizes[i] == 0)
xpram_sizes[i] = mem_auto;
@@ -499,8 +506,8 @@
return -ENODEV;
}
xpram_pages = xpram_highest_page_index();
- PRINT_INFO(" %li pages expanded memory found (%li KB).\n",
- xpram_pages, xpram_pages*4);
+ PRINT_INFO(" %u pages expanded memory found (%lu KB).\n",
+ xpram_pages, (unsigned long) xpram_pages*4);
rc = xpram_setup_sizes(xpram_pages);
if (rc)
return rc;


2003-09-25 19:15:13

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH] s390 (9/19): xpram driver.

On Thu, Sep 25, 2003 at 07:19:17PM +0200, Martin Schwidefsky wrote:
> static xpram_device_t xpram_devices[XPRAM_MAX_DEVS];
> -static int xpram_sizes[XPRAM_MAX_DEVS];
> +static unsigned int xpram_sizes[XPRAM_MAX_DEVS];
> static struct gendisk *xpram_disks[XPRAM_MAX_DEVS];

Btw, you should really consolidate all these per-device arrays
in a struct. Maybe some day you even get rid of the artifical
limit on the number of devices :)