Skip to content

Commit c9b5645

Browse files
Thomas-fourieraxboe
authored andcommitted
block: rnbd-clt: Fix leaked ID in init_dev()
If kstrdup() fails in init_dev(), then the newly allocated ID is lost. Fixes: 64e8a6e ("block/rnbd-clt: Dynamically alloc buffer for pathname & blk_symlink_name") Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com> Acked-by: Jack Wang <jinpu.wang@ionos.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent c258f5c commit c9b5645

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

drivers/block/rnbd/rnbd-clt.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,9 +1423,11 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess,
14231423
goto out_alloc;
14241424
}
14251425

1426-
ret = ida_alloc_max(&index_ida, (1 << (MINORBITS - RNBD_PART_BITS)) - 1,
1427-
GFP_KERNEL);
1428-
if (ret < 0) {
1426+
dev->clt_device_id = ida_alloc_max(&index_ida,
1427+
(1 << (MINORBITS - RNBD_PART_BITS)) - 1,
1428+
GFP_KERNEL);
1429+
if (dev->clt_device_id < 0) {
1430+
ret = dev->clt_device_id;
14291431
pr_err("Failed to initialize device '%s' from session %s, allocating idr failed, err: %d\n",
14301432
pathname, sess->sessname, ret);
14311433
goto out_queues;
@@ -1434,10 +1436,9 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess,
14341436
dev->pathname = kstrdup(pathname, GFP_KERNEL);
14351437
if (!dev->pathname) {
14361438
ret = -ENOMEM;
1437-
goto out_queues;
1439+
goto out_ida;
14381440
}
14391441

1440-
dev->clt_device_id = ret;
14411442
dev->sess = sess;
14421443
dev->access_mode = access_mode;
14431444
dev->nr_poll_queues = nr_poll_queues;
@@ -1453,6 +1454,8 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess,
14531454

14541455
return dev;
14551456

1457+
out_ida:
1458+
ida_free(&index_ida, dev->clt_device_id);
14561459
out_queues:
14571460
kfree(dev->hw_queues);
14581461
out_alloc:

0 commit comments

Comments
 (0)