Skip to content

Commit

Permalink
block: fix device_add_disk() kobject_create_and_add() error handling
Browse files Browse the repository at this point in the history
Commit 83cbce9 ("block: add error handling for device_add_disk /
add_disk") added error handling to device_add_disk(), however the goto
label for the kobject_create_and_add() failure did not set the return
value correctly, and so we can end up in a situation where
kobject_create_and_add() fails but we report success.

Fixes: 83cbce9 ("block: add error handling for device_add_disk / add_disk")
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Luis Chamberlain <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
[axboe: fold in followup fix from Wu Bo <[email protected]>]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
mcgrof authored and axboe committed Nov 5, 2021
1 parent 10c4787 commit fe7d064
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,15 @@ int device_add_disk(struct device *parent, struct gendisk *disk,

disk->part0->bd_holder_dir =
kobject_create_and_add("holders", &ddev->kobj);
if (!disk->part0->bd_holder_dir)
if (!disk->part0->bd_holder_dir) {
ret = -ENOMEM;
goto out_del_integrity;
}
disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj);
if (!disk->slave_dir)
if (!disk->slave_dir) {
ret = -ENOMEM;
goto out_put_holder_dir;
}

ret = bd_register_pending_holders(disk);
if (ret < 0)
Expand Down

0 comments on commit fe7d064

Please sign in to comment.