Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

block: rnbd-clt: Fix leaked ID in init_dev()

If kstrdup() fails in init_dev(), then the newly allocated ID is lost.

Fixes: 64e8a6ece1a5 ("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>

authored by

Thomas Fourier and committed by
Jens Axboe
c9b5645f c258f5c4

+8 -5
+8 -5
drivers/block/rnbd/rnbd-clt.c
··· 1423 1423 goto out_alloc; 1424 1424 } 1425 1425 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; 1429 1431 pr_err("Failed to initialize device '%s' from session %s, allocating idr failed, err: %d\n", 1430 1432 pathname, sess->sessname, ret); 1431 1433 goto out_queues; ··· 1436 1434 dev->pathname = kstrdup(pathname, GFP_KERNEL); 1437 1435 if (!dev->pathname) { 1438 1436 ret = -ENOMEM; 1439 - goto out_queues; 1437 + goto out_ida; 1440 1438 } 1441 1439 1442 - dev->clt_device_id = ret; 1443 1440 dev->sess = sess; 1444 1441 dev->access_mode = access_mode; 1445 1442 dev->nr_poll_queues = nr_poll_queues; ··· 1454 1453 1455 1454 return dev; 1456 1455 1456 + out_ida: 1457 + ida_free(&index_ida, dev->clt_device_id); 1457 1458 out_queues: 1458 1459 kfree(dev->hw_queues); 1459 1460 out_alloc: