Skip to content

Commit c49b088

Browse files
author
Ming Lei
committed
block: fix memory leak for elevator on add_disk failure
JIRA: https://issues.redhat.com/browse/RHEL-112997 Conflicts: code base difference commit 02341a0 Author: Yu Kuai <yukuai3@huawei.com> Date: Sat Oct 22 10:16:15 2022 +0800 block: fix memory leak for elevator on add_disk failure The default elevator is allocated in the beginning of device_add_disk(), however, it's not freed in the following error path. Fixes: 50e34d7 ("block: disable the elevator int del_gendisk") Signed-off-by: Yu Kuai <yukuai3@huawei.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jason Yan <yanaijie@huawei.com> Link: https://lore.kernel.org/r/20221022021615.2756171-1-yukuai1@huaweicloud.com Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Ming Lei <ming.lei@redhat.com>
1 parent 91129fe commit c49b088

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

block/genhd.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,10 @@ int __must_check add_disk_fwnode(struct device *parent, struct gendisk *disk,
435435
* Otherwise just allocate the device numbers for both the whole device
436436
* and all partitions from the extended dev_t space.
437437
*/
438+
ret = -EINVAL;
438439
if (disk->major) {
439440
if (WARN_ON(!disk->minors))
440-
return -EINVAL;
441+
goto out_exit_elevator;
441442

442443
if (disk->minors > DISK_MAX_PARTS) {
443444
pr_err("block: can't allocate more than %d partitions\n",
@@ -447,14 +448,14 @@ int __must_check add_disk_fwnode(struct device *parent, struct gendisk *disk,
447448
if (disk->first_minor > MINORMASK ||
448449
disk->minors > MINORMASK + 1 ||
449450
disk->first_minor + disk->minors > MINORMASK + 1)
450-
return -EINVAL;
451+
goto out_exit_elevator;
451452
} else {
452453
if (WARN_ON(disk->minors))
453-
return -EINVAL;
454+
goto out_exit_elevator;
454455

455456
ret = blk_alloc_ext_minor();
456457
if (ret < 0)
457-
return ret;
458+
goto out_exit_elevator;
458459
disk->major = BLOCK_EXT_MAJOR;
459460
disk->first_minor = ret;
460461
}
@@ -563,6 +564,9 @@ int __must_check add_disk_fwnode(struct device *parent, struct gendisk *disk,
563564
out_free_ext_minor:
564565
if (disk->major == BLOCK_EXT_MAJOR)
565566
blk_free_ext_minor(disk->first_minor);
567+
out_exit_elevator:
568+
if (disk->queue->elevator)
569+
elevator_exit(disk->queue);
566570
return ret;
567571
}
568572
EXPORT_SYMBOL_GPL(add_disk_fwnode);

0 commit comments

Comments
 (0)