diff options
author | Alex Elder <elder@dreamhost.com> | 2012-02-02 09:13:30 -0500 |
---|---|---|
committer | Alex Elder <elder@dreamhost.com> | 2012-03-22 11:47:48 -0400 |
commit | 27cc25943fb359241546e7bb7a3ab1c2f35796a2 (patch) | |
tree | b5b957d4732a9fc3cc4b9eff33344eb5faabde2e | |
parent | 60571c7d556b10db7e555bd4b6765647af5c41e8 (diff) |
rbd: simplify error handling in rbd_add()
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>
Signed-off-by: Sage Weil <sage@newdream.net>
-rw-r--r-- | 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 606d59aece2b..8ac26ab09aa0 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c | |||
@@ -2224,28 +2224,24 @@ static ssize_t rbd_add(struct bus_type *bus, | |||
2224 | const char *buf, | 2224 | const char *buf, |
2225 | size_t count) | 2225 | size_t count) |
2226 | { | 2226 | { |
2227 | struct ceph_osd_client *osdc; | ||
2228 | struct rbd_device *rbd_dev; | 2227 | struct rbd_device *rbd_dev; |
2229 | ssize_t rc = -ENOMEM; | 2228 | char *mon_dev_name = NULL; |
2230 | int irc; | 2229 | char *options = NULL; |
2231 | char *mon_dev_name; | 2230 | struct ceph_osd_client *osdc; |
2232 | char *options; | 2231 | int rc = -ENOMEM; |
2233 | 2232 | ||
2234 | if (!try_module_get(THIS_MODULE)) | 2233 | if (!try_module_get(THIS_MODULE)) |
2235 | return -ENODEV; | 2234 | return -ENODEV; |
2236 | 2235 | ||
2236 | rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL); | ||
2237 | if (!rbd_dev) | ||
2238 | goto err_nomem; | ||
2237 | mon_dev_name = kmalloc(count, GFP_KERNEL); | 2239 | mon_dev_name = kmalloc(count, GFP_KERNEL); |
2238 | if (!mon_dev_name) | 2240 | if (!mon_dev_name) |
2239 | goto err_out_mod; | 2241 | goto err_nomem; |
2240 | |||
2241 | options = kmalloc(count, GFP_KERNEL); | 2242 | options = kmalloc(count, GFP_KERNEL); |
2242 | if (!options) | 2243 | if (!options) |
2243 | goto err_mon_dev; | 2244 | goto err_nomem; |
2244 | |||
2245 | /* new rbd_device object */ | ||
2246 | rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL); | ||
2247 | if (!rbd_dev) | ||
2248 | goto err_out_opt; | ||
2249 | 2245 | ||
2250 | /* static rbd_device initialization */ | 2246 | /* static rbd_device initialization */ |
2251 | spin_lock_init(&rbd_dev->lock); | 2247 | spin_lock_init(&rbd_dev->lock); |
@@ -2294,12 +2290,10 @@ static ssize_t rbd_add(struct bus_type *bus, | |||
2294 | rbd_dev->poolid = rc; | 2290 | rbd_dev->poolid = rc; |
2295 | 2291 | ||
2296 | /* register our block device */ | 2292 | /* register our block device */ |
2297 | irc = register_blkdev(0, rbd_dev->name); | 2293 | rc = register_blkdev(0, rbd_dev->name); |
2298 | if (irc < 0) { | 2294 | if (rc < 0) |
2299 | rc = irc; | ||
2300 | goto err_out_client; | 2295 | goto err_out_client; |
2301 | } | 2296 | rbd_dev->major = rc; |
2302 | rbd_dev->major = irc; | ||
2303 | 2297 | ||
2304 | rc = rbd_bus_add_dev(rbd_dev); | 2298 | rc = rbd_bus_add_dev(rbd_dev); |
2305 | if (rc) | 2299 | if (rc) |
@@ -2332,15 +2326,15 @@ err_out_client: | |||
2332 | rbd_put_client(rbd_dev); | 2326 | rbd_put_client(rbd_dev); |
2333 | err_put_id: | 2327 | err_put_id: |
2334 | rbd_id_put(rbd_dev); | 2328 | rbd_id_put(rbd_dev); |
2335 | kfree(rbd_dev); | 2329 | err_nomem: |
2336 | err_out_opt: | ||
2337 | kfree(options); | 2330 | kfree(options); |
2338 | err_mon_dev: | ||
2339 | kfree(mon_dev_name); | 2331 | kfree(mon_dev_name); |
2340 | err_out_mod: | 2332 | kfree(rbd_dev); |
2333 | |||
2341 | dout("Error adding device %s\n", buf); | 2334 | dout("Error adding device %s\n", buf); |
2342 | module_put(THIS_MODULE); | 2335 | module_put(THIS_MODULE); |
2343 | return rc; | 2336 | |
2337 | return (ssize_t) rc; | ||
2344 | } | 2338 | } |
2345 | 2339 | ||
2346 | static struct rbd_device *__rbd_get_dev(unsigned long id) | 2340 | static struct rbd_device *__rbd_get_dev(unsigned long id) |