mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-11-01 06:46:35 +01:00
block: rnbd-clt: Fix leaked ID in init_dev()
If kstrdup() fails in init_dev(), then the newly allocated ID is lost.
Fixes: 64e8a6ece1 ("block/rnbd-clt: Dynamically alloc buffer for pathname & blk_symlink_name")
Signed-off-by: Thomas Fourier <[email protected]>
Acked-by: Jack Wang <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
This commit is contained in:
1 parent
c258f5c450
commit
c9b5645fd8
1 file changed
+8
-5
@@ -1423,9 +1423,11 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess,
|
||||
goto out_alloc;
|
||||
}
|
||||
|
||||
ret = ida_alloc_max(&index_ida, (1 << (MINORBITS - RNBD_PART_BITS)) - 1,
|
||||
GFP_KERNEL);
|
||||
if (ret < 0) {
|
||||
dev->clt_device_id = ida_alloc_max(&index_ida,
|
||||
(1 << (MINORBITS - RNBD_PART_BITS)) - 1,
|
||||
GFP_KERNEL);
|
||||
if (dev->clt_device_id < 0) {
|
||||
ret = dev->clt_device_id;
|
||||
pr_err("Failed to initialize device '%s' from session %s, allocating idr failed, err: %d\n",
|
||||
pathname, sess->sessname, ret);
|
||||
goto out_queues;
|
||||
@@ -1434,10 +1436,9 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess,
|
||||
dev->pathname = kstrdup(pathname, GFP_KERNEL);
|
||||
if (!dev->pathname) {
|
||||
ret = -ENOMEM;
|
||||
goto out_queues;
|
||||
goto out_ida;
|
||||
}
|
||||
|
||||
dev->clt_device_id = ret;
|
||||
dev->sess = sess;
|
||||
dev->access_mode = access_mode;
|
||||
dev->nr_poll_queues = nr_poll_queues;
|
||||
@@ -1453,6 +1454,8 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess,
|
||||
|
||||
return dev;
|
||||
|
||||
out_ida:
|
||||
ida_free(&index_ida, dev->clt_device_id);
|
||||
out_queues:
|
||||
kfree(dev->hw_queues);
|
||||
out_alloc:
|
||||
|
||||
Reference in new issue
Block a user