From: Alex Elder <elder@dreamhost.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH 3/3] rbd: simplify error handling in rbd_add()
Date: Tue, 28 Feb 2012 19:53:00 -0800 [thread overview]
Message-ID: <4F4DA11C.1000400@dreamhost.com> (raw)
In-Reply-To: <4F4DA086.7050601@dreamhost.com>
If a couple pointers are initialized to NULL then a single
"out_nomem" label can be used for all of the memory allocation
failure cases in rbd_add().
Also, get rid of the "irc" local variable there. There is no
real need for "rc" to be type ssize_t, and it can be used in
the spot "irc" was.
Signed-off-by: Alex Elder <elder@dreamhost.com>
---
drivers/block/rbd.c | 40 +++++++++++++++++-----------------------
1 files changed, 17 insertions(+), 23 deletions(-)
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 1488a52..29bbac1 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -2223,28 +2223,24 @@ static ssize_t rbd_add(struct bus_type *bus,
const char *buf,
size_t count)
{
- struct ceph_osd_client *osdc;
struct rbd_device *rbd_dev;
- ssize_t rc = -ENOMEM;
- int irc;
- char *mon_dev_name;
- char *options;
+ char *mon_dev_name = NULL;
+ char *options = NULL;
+ struct ceph_osd_client *osdc;
+ int rc = -ENOMEM;
if (!try_module_get(THIS_MODULE))
return -ENODEV;
+ rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL);
+ if (!rbd_dev)
+ goto err_nomem;
mon_dev_name = kmalloc(count, GFP_KERNEL);
if (!mon_dev_name)
- goto err_out_mod;
-
+ goto err_nomem;
options = kmalloc(count, GFP_KERNEL);
if (!options)
- goto err_mon_dev;
-
- /* new rbd_device object */
- rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL);
- if (!rbd_dev)
- goto err_out_opt;
+ goto err_nomem;
/* static rbd_device initialization */
spin_lock_init(&rbd_dev->lock);
@@ -2291,12 +2287,10 @@ static ssize_t rbd_add(struct bus_type *bus,
rbd_dev->poolid = rc;
/* register our block device */
- irc = register_blkdev(0, rbd_dev->name);
- if (irc < 0) {
- rc = irc;
+ rc = register_blkdev(0, rbd_dev->name);
+ if (rc < 0)
goto err_out_client;
- }
- rbd_dev->major = irc;
+ rbd_dev->major = rc;
rc = rbd_bus_add_dev(rbd_dev);
if (rc)
@@ -2329,15 +2323,15 @@ err_out_client:
rbd_put_client(rbd_dev);
err_put_id:
rbd_id_put(rbd_dev);
- kfree(rbd_dev);
-err_out_opt:
+err_nomem:
kfree(options);
-err_mon_dev:
kfree(mon_dev_name);
-err_out_mod:
+ kfree(rbd_dev);
+
dout("Error adding device %s\n", buf);
module_put(THIS_MODULE);
- return rc;
+
+ return (ssize_t) rc;
}
static struct rbd_device *__rbd_get_dev(unsigned long id)
--
1.7.5.4
next prev parent reply other threads:[~2012-02-29 3:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-29 3:50 [PATCH 0/3] rbd: minor cleanups in rbd_add() Alex Elder
2012-02-29 3:52 ` [PATCH 1/3] rbd: have rbd_get_client() return a rbd_client Alex Elder
2012-02-29 3:52 ` [PATCH 2/3] rbd: reduce memory used for rbd_dev fields Alex Elder
2012-02-29 3:53 ` Alex Elder [this message]
2012-03-02 21:00 ` [PATCH 0/3] rbd: minor cleanups in rbd_add() Sage Weil
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=4F4DA11C.1000400@dreamhost.com \
--to=elder@dreamhost.com \
--cc=ceph-devel@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.