From: Nitin Gupta <ngupta@vflare.org>
To: Greg KH <greg@kroah.com>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH 4/7] Return proper error code on device create failure
Date: Thu, 28 Jan 2010 21:13:40 +0530 [thread overview]
Message-ID: <1264693423-2694-5-git-send-email-ngupta@vflare.org> (raw)
In-Reply-To: <1264693423-2694-1-git-send-email-ngupta@vflare.org>
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: Nitin Gupta <ngupta@vflare.org>
---
drivers/staging/ramzswap/ramzswap_drv.c | 44 +++++++++++++++++++-----------
1 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/drivers/staging/ramzswap/ramzswap_drv.c b/drivers/staging/ramzswap/ramzswap_drv.c
index 2021ad6..3035add 100644
--- a/drivers/staging/ramzswap/ramzswap_drv.c
+++ b/drivers/staging/ramzswap/ramzswap_drv.c
@@ -1300,6 +1300,8 @@ static struct block_device_operations ramzswap_devops = {
static int create_device(struct ramzswap *rzs, int device_id)
{
+ int ret = 0;
+
mutex_init(&rzs->lock);
spin_lock_init(&rzs->stat64_lock);
INIT_LIST_HEAD(&rzs->backing_swap_extent_list);
@@ -1308,7 +1310,8 @@ static int create_device(struct ramzswap *rzs, int device_id)
if (!rzs->queue) {
pr_err("Error allocating disk queue for device %d\n",
device_id);
- return 0;
+ ret = -ENOMEM;
+ goto out;
}
blk_queue_make_request(rzs->queue, ramzswap_make_request);
@@ -1320,7 +1323,8 @@ static int create_device(struct ramzswap *rzs, int device_id)
blk_cleanup_queue(rzs->queue);
pr_warning("Error allocating disk structure for device %d\n",
device_id);
- return 0;
+ ret = -ENOMEM;
+ goto out;
}
rzs->disk->major = ramzswap_major;
@@ -1342,7 +1346,9 @@ static int create_device(struct ramzswap *rzs, int device_id)
add_disk(rzs->disk);
rzs->init_done = 0;
- return 1;
+
+out:
+ return ret;
}
static void destroy_device(struct ramzswap *rzs)
@@ -1358,18 +1364,20 @@ static void destroy_device(struct ramzswap *rzs)
static int __init ramzswap_init(void)
{
- int i, ret;
+ int ret, dev_id;
if (num_devices > max_num_devices) {
pr_warning("Invalid value for num_devices: %u\n",
num_devices);
- return -EINVAL;
+ ret = -EINVAL;
+ goto out;
}
ramzswap_major = register_blkdev(0, "ramzswap");
if (ramzswap_major <= 0) {
pr_warning("Unable to get major number\n");
- return -EBUSY;
+ ret = -EBUSY;
+ goto out;
}
if (!num_devices) {
@@ -1380,21 +1388,25 @@ static int __init ramzswap_init(void)
/* Allocate the device array and initialize each one */
pr_info("Creating %u devices ...\n", num_devices);
devices = kzalloc(num_devices * sizeof(struct ramzswap), GFP_KERNEL);
- if (!devices)
- goto out;
+ if (!devices) {
+ ret = -ENOMEM;
+ goto unregister;
+ }
- for (i = 0; i < num_devices; i++)
- if (!create_device(&devices[i], i)) {
- ret = i;
+ for (dev_id = 0; dev_id < num_devices; dev_id++) {
+ ret = create_device(&devices[dev_id], dev_id);
+ if (ret)
goto free_devices;
- }
+ }
+
return 0;
+
free_devices:
- for (i = 0; i < ret; i++)
- destroy_device(&devices[i]);
-out:
- ret = -ENOMEM;
+ while (dev_id)
+ destroy_device(&devices[--dev_id]);
+unregister:
unregister_blkdev(ramzswap_major, "ramzswap");
+out:
return ret;
}
--
1.6.2.5
next prev parent reply other threads:[~2010-01-28 15:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-28 15:43 [PATCH 0/7][linux-next v2] ramzswap: bug fixes and some cleanups Nitin Gupta
2010-01-28 15:43 ` [PATCH 1/7] Use lock for 64-bit stats Nitin Gupta
2010-01-28 15:43 ` [PATCH 2/7] Flush block device before reset Nitin Gupta
2010-01-28 15:43 ` [PATCH 3/7] Set block size to PAGE_SIZE Nitin Gupta
2010-01-28 15:43 ` Nitin Gupta [this message]
2010-01-28 15:43 ` [PATCH 5/7] Remove redundant check for zero page Nitin Gupta
2010-01-28 15:49 ` [PATCH 6/7] Handle case for invalid backing swap Nitin Gupta
2010-01-28 15:51 ` [PATCH 7/7] Update copyright notice Nitin Gupta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1264693423-2694-5-git-send-email-ngupta@vflare.org \
--to=ngupta@vflare.org \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=penberg@cs.helsinki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®