Commit d3a95cca authored by Guoqing Jiang's avatar Guoqing Jiang Committed by Jens Axboe

block/rnbd: call kobject_put in the failure path

Per the comment of kobject_init_and_add, we need to cleanup the memory
by call kobject_put.

Also we need to call kobject_del for the other failure cases if the
kobject_init_and_add doesn't fail.
Signed-off-by: default avatarGuoqing Jiang <guoqing.jiang@cloud.ionos.com>
Signed-off-by: default avatarJack Wang <jinpu.wang@cloud.ionos.com>
Reviewed-by: default avatarMd Haris Iqbal <haris.iqbal@cloud.ionos.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 765c5c56
...@@ -450,9 +450,11 @@ static int rnbd_clt_add_dev_kobj(struct rnbd_clt_dev *dev) ...@@ -450,9 +450,11 @@ static int rnbd_clt_add_dev_kobj(struct rnbd_clt_dev *dev)
ret = kobject_init_and_add(&dev->kobj, &rnbd_dev_ktype, gd_kobj, "%s", ret = kobject_init_and_add(&dev->kobj, &rnbd_dev_ktype, gd_kobj, "%s",
"rnbd"); "rnbd");
if (ret) if (ret) {
rnbd_clt_err(dev, "Failed to create device sysfs dir, err: %d\n", rnbd_clt_err(dev, "Failed to create device sysfs dir, err: %d\n",
ret); ret);
kobject_put(&dev->kobj);
}
return ret; return ret;
} }
......
...@@ -47,13 +47,17 @@ int rnbd_srv_create_dev_sysfs(struct rnbd_srv_dev *dev, ...@@ -47,13 +47,17 @@ int rnbd_srv_create_dev_sysfs(struct rnbd_srv_dev *dev,
ret = kobject_init_and_add(&dev->dev_kobj, &dev_ktype, ret = kobject_init_and_add(&dev->dev_kobj, &dev_ktype,
rnbd_devs_kobj, dev_name); rnbd_devs_kobj, dev_name);
if (ret) if (ret) {
kobject_put(&dev->dev_kobj);
return ret; return ret;
}
dev->dev_sessions_kobj = kobject_create_and_add("sessions", dev->dev_sessions_kobj = kobject_create_and_add("sessions",
&dev->dev_kobj); &dev->dev_kobj);
if (!dev->dev_sessions_kobj) if (!dev->dev_sessions_kobj) {
goto put_dev_kobj; ret = -ENOMEM;
goto free_dev_kobj;
}
bdev_kobj = &disk_to_dev(bdev->bd_disk)->kobj; bdev_kobj = &disk_to_dev(bdev->bd_disk)->kobj;
ret = sysfs_create_link(&dev->dev_kobj, bdev_kobj, "block_dev"); ret = sysfs_create_link(&dev->dev_kobj, bdev_kobj, "block_dev");
...@@ -64,7 +68,8 @@ int rnbd_srv_create_dev_sysfs(struct rnbd_srv_dev *dev, ...@@ -64,7 +68,8 @@ int rnbd_srv_create_dev_sysfs(struct rnbd_srv_dev *dev,
put_sess_kobj: put_sess_kobj:
kobject_put(dev->dev_sessions_kobj); kobject_put(dev->dev_sessions_kobj);
put_dev_kobj: free_dev_kobj:
kobject_del(&dev->dev_kobj);
kobject_put(&dev->dev_kobj); kobject_put(&dev->dev_kobj);
return ret; return ret;
} }
...@@ -196,18 +201,17 @@ int rnbd_srv_create_dev_session_sysfs(struct rnbd_srv_sess_dev *sess_dev) ...@@ -196,18 +201,17 @@ int rnbd_srv_create_dev_session_sysfs(struct rnbd_srv_sess_dev *sess_dev)
ret = kobject_init_and_add(&sess_dev->kobj, &rnbd_srv_sess_dev_ktype, ret = kobject_init_and_add(&sess_dev->kobj, &rnbd_srv_sess_dev_ktype,
sess_dev->dev->dev_sessions_kobj, "%s", sess_dev->dev->dev_sessions_kobj, "%s",
sess_dev->sess->sessname); sess_dev->sess->sessname);
if (ret) if (ret) {
kobject_put(&sess_dev->kobj);
return ret; return ret;
}
ret = sysfs_create_group(&sess_dev->kobj, ret = sysfs_create_group(&sess_dev->kobj,
&rnbd_srv_default_dev_session_attr_group); &rnbd_srv_default_dev_session_attr_group);
if (ret) if (ret) {
goto err; kobject_del(&sess_dev->kobj);
kobject_put(&sess_dev->kobj);
return 0; }
err:
kobject_put(&sess_dev->kobj);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment