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>
This commit is contained in:
parent
60571c7d55
commit
27cc25943f
1 changed files with 19 additions and 25 deletions
|
@ -2224,28 +2224,24 @@ static ssize_t rbd_add(struct bus_type *bus,
|
||||||
const char *buf,
|
const char *buf,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
struct ceph_osd_client *osdc;
|
|
||||||
struct rbd_device *rbd_dev;
|
struct rbd_device *rbd_dev;
|
||||||
ssize_t rc = -ENOMEM;
|
char *mon_dev_name = NULL;
|
||||||
int irc;
|
char *options = NULL;
|
||||||
char *mon_dev_name;
|
struct ceph_osd_client *osdc;
|
||||||
char *options;
|
int rc = -ENOMEM;
|
||||||
|
|
||||||
if (!try_module_get(THIS_MODULE))
|
if (!try_module_get(THIS_MODULE))
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
mon_dev_name = kmalloc(count, GFP_KERNEL);
|
|
||||||
if (!mon_dev_name)
|
|
||||||
goto err_out_mod;
|
|
||||||
|
|
||||||
options = kmalloc(count, GFP_KERNEL);
|
|
||||||
if (!options)
|
|
||||||
goto err_mon_dev;
|
|
||||||
|
|
||||||
/* new rbd_device object */
|
|
||||||
rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL);
|
rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL);
|
||||||
if (!rbd_dev)
|
if (!rbd_dev)
|
||||||
goto err_out_opt;
|
goto err_nomem;
|
||||||
|
mon_dev_name = kmalloc(count, GFP_KERNEL);
|
||||||
|
if (!mon_dev_name)
|
||||||
|
goto err_nomem;
|
||||||
|
options = kmalloc(count, GFP_KERNEL);
|
||||||
|
if (!options)
|
||||||
|
goto err_nomem;
|
||||||
|
|
||||||
/* static rbd_device initialization */
|
/* static rbd_device initialization */
|
||||||
spin_lock_init(&rbd_dev->lock);
|
spin_lock_init(&rbd_dev->lock);
|
||||||
|
@ -2294,12 +2290,10 @@ static ssize_t rbd_add(struct bus_type *bus,
|
||||||
rbd_dev->poolid = rc;
|
rbd_dev->poolid = rc;
|
||||||
|
|
||||||
/* register our block device */
|
/* register our block device */
|
||||||
irc = register_blkdev(0, rbd_dev->name);
|
rc = register_blkdev(0, rbd_dev->name);
|
||||||
if (irc < 0) {
|
if (rc < 0)
|
||||||
rc = irc;
|
|
||||||
goto err_out_client;
|
goto err_out_client;
|
||||||
}
|
rbd_dev->major = rc;
|
||||||
rbd_dev->major = irc;
|
|
||||||
|
|
||||||
rc = rbd_bus_add_dev(rbd_dev);
|
rc = rbd_bus_add_dev(rbd_dev);
|
||||||
if (rc)
|
if (rc)
|
||||||
|
@ -2332,15 +2326,15 @@ err_out_client:
|
||||||
rbd_put_client(rbd_dev);
|
rbd_put_client(rbd_dev);
|
||||||
err_put_id:
|
err_put_id:
|
||||||
rbd_id_put(rbd_dev);
|
rbd_id_put(rbd_dev);
|
||||||
kfree(rbd_dev);
|
err_nomem:
|
||||||
err_out_opt:
|
|
||||||
kfree(options);
|
kfree(options);
|
||||||
err_mon_dev:
|
|
||||||
kfree(mon_dev_name);
|
kfree(mon_dev_name);
|
||||||
err_out_mod:
|
kfree(rbd_dev);
|
||||||
|
|
||||||
dout("Error adding device %s\n", buf);
|
dout("Error adding device %s\n", buf);
|
||||||
module_put(THIS_MODULE);
|
module_put(THIS_MODULE);
|
||||||
return rc;
|
|
||||||
|
return (ssize_t) rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct rbd_device *__rbd_get_dev(unsigned long id)
|
static struct rbd_device *__rbd_get_dev(unsigned long id)
|
||||||
|
|
Loading…
Add table
Reference in a new issue