提交 de1a21a0 编写于 作者: N Nitin Gupta 提交者: Greg Kroah-Hartman

Staging: ramzswap: Return proper error code on device create failure

Currently, we return 0 if create_device() fails and 1 otherwise.
Now, proper error code is returned from create_device() and the
same is propagated as module error code from ramzswap_init().

Also added some cleanups for ramzswap_init(), improving function
structure.
Signed-off-by: NNitin Gupta <ngupta@vflare.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 5d83d5a0
...@@ -1300,6 +1300,8 @@ static struct block_device_operations ramzswap_devops = { ...@@ -1300,6 +1300,8 @@ static struct block_device_operations ramzswap_devops = {
static int create_device(struct ramzswap *rzs, int device_id) static int create_device(struct ramzswap *rzs, int device_id)
{ {
int ret = 0;
mutex_init(&rzs->lock); mutex_init(&rzs->lock);
spin_lock_init(&rzs->stat64_lock); spin_lock_init(&rzs->stat64_lock);
INIT_LIST_HEAD(&rzs->backing_swap_extent_list); INIT_LIST_HEAD(&rzs->backing_swap_extent_list);
...@@ -1308,7 +1310,8 @@ static int create_device(struct ramzswap *rzs, int device_id) ...@@ -1308,7 +1310,8 @@ static int create_device(struct ramzswap *rzs, int device_id)
if (!rzs->queue) { if (!rzs->queue) {
pr_err("Error allocating disk queue for device %d\n", pr_err("Error allocating disk queue for device %d\n",
device_id); device_id);
return 0; ret = -ENOMEM;
goto out;
} }
blk_queue_make_request(rzs->queue, ramzswap_make_request); blk_queue_make_request(rzs->queue, ramzswap_make_request);
...@@ -1320,7 +1323,8 @@ static int create_device(struct ramzswap *rzs, int device_id) ...@@ -1320,7 +1323,8 @@ static int create_device(struct ramzswap *rzs, int device_id)
blk_cleanup_queue(rzs->queue); blk_cleanup_queue(rzs->queue);
pr_warning("Error allocating disk structure for device %d\n", pr_warning("Error allocating disk structure for device %d\n",
device_id); device_id);
return 0; ret = -ENOMEM;
goto out;
} }
rzs->disk->major = ramzswap_major; rzs->disk->major = ramzswap_major;
...@@ -1342,7 +1346,9 @@ static int create_device(struct ramzswap *rzs, int device_id) ...@@ -1342,7 +1346,9 @@ static int create_device(struct ramzswap *rzs, int device_id)
add_disk(rzs->disk); add_disk(rzs->disk);
rzs->init_done = 0; rzs->init_done = 0;
return 1;
out:
return ret;
} }
static void destroy_device(struct ramzswap *rzs) static void destroy_device(struct ramzswap *rzs)
...@@ -1358,18 +1364,20 @@ static void destroy_device(struct ramzswap *rzs) ...@@ -1358,18 +1364,20 @@ static void destroy_device(struct ramzswap *rzs)
static int __init ramzswap_init(void) static int __init ramzswap_init(void)
{ {
int i, ret; int ret, dev_id;
if (num_devices > max_num_devices) { if (num_devices > max_num_devices) {
pr_warning("Invalid value for num_devices: %u\n", pr_warning("Invalid value for num_devices: %u\n",
num_devices); num_devices);
return -EINVAL; ret = -EINVAL;
goto out;
} }
ramzswap_major = register_blkdev(0, "ramzswap"); ramzswap_major = register_blkdev(0, "ramzswap");
if (ramzswap_major <= 0) { if (ramzswap_major <= 0) {
pr_warning("Unable to get major number\n"); pr_warning("Unable to get major number\n");
return -EBUSY; ret = -EBUSY;
goto out;
} }
if (!num_devices) { if (!num_devices) {
...@@ -1380,21 +1388,25 @@ static int __init ramzswap_init(void) ...@@ -1380,21 +1388,25 @@ static int __init ramzswap_init(void)
/* Allocate the device array and initialize each one */ /* Allocate the device array and initialize each one */
pr_info("Creating %u devices ...\n", num_devices); pr_info("Creating %u devices ...\n", num_devices);
devices = kzalloc(num_devices * sizeof(struct ramzswap), GFP_KERNEL); devices = kzalloc(num_devices * sizeof(struct ramzswap), GFP_KERNEL);
if (!devices) if (!devices) {
goto out; ret = -ENOMEM;
goto unregister;
}
for (i = 0; i < num_devices; i++) for (dev_id = 0; dev_id < num_devices; dev_id++) {
if (!create_device(&devices[i], i)) { ret = create_device(&devices[dev_id], dev_id);
ret = i; if (ret)
goto free_devices; goto free_devices;
} }
return 0; return 0;
free_devices: free_devices:
for (i = 0; i < ret; i++) while (dev_id)
destroy_device(&devices[i]); destroy_device(&devices[--dev_id]);
out: unregister:
ret = -ENOMEM;
unregister_blkdev(ramzswap_major, "ramzswap"); unregister_blkdev(ramzswap_major, "ramzswap");
out:
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册