This is a note to let you know that I've just added the patch titled block/brd: add error handling support for add_disk() to the 5.15-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: block-brd-add-error-handling-support-for-add_disk.patch and it can be found in the queue-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. commit 4ae62873c2c500df620def815e4923049836e82d Author: Luis Chamberlain <mcgrof@xxxxxxxxxx> Date: Fri Oct 15 16:52:07 2021 -0700 block/brd: add error handling support for add_disk() [ Upstream commit e1528830bd4ebf435d91c154e309e6e028336210 ] We never checked for errors on add_disk() as this function returned void. Now that this is fixed, use the shiny new error handling. Signed-off-by: Luis Chamberlain <mcgrof@xxxxxxxxxx> Link: https://lore.kernel.org/r/20211015235219.2191207-2-mcgrof@xxxxxxxxxx Signed-off-by: Jens Axboe <axboe@xxxxxxxxx> Stable-dep-of: 67205f80be99 ("brd: mark as nowait compatible") Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> diff --git a/drivers/block/brd.c b/drivers/block/brd.c index 2427b2261e516..63ac5cd523408 100644 --- a/drivers/block/brd.c +++ b/drivers/block/brd.c @@ -370,6 +370,7 @@ static int brd_alloc(int i) struct brd_device *brd; struct gendisk *disk; char buf[DISK_NAME_LEN]; + int err = -ENOMEM; mutex_lock(&brd_devices_mutex); list_for_each_entry(brd, &brd_devices, brd_list) { @@ -420,16 +421,20 @@ static int brd_alloc(int i) /* Tell the block layer that this is not a rotational device */ blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue); blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, disk->queue); - add_disk(disk); + err = add_disk(disk); + if (err) + goto out_cleanup_disk; return 0; +out_cleanup_disk: + blk_cleanup_disk(disk); out_free_dev: mutex_lock(&brd_devices_mutex); list_del(&brd->brd_list); mutex_unlock(&brd_devices_mutex); kfree(brd); - return -ENOMEM; + return err; } static void brd_probe(dev_t dev)