Zero out the pointers to the holder related kobjects so that bd_unlink_disk_holder does the right thing when dm cleans up the delayed holders after add_disk fails. Fixes: 89f871af1b26 ("dm: delay registering the gendisk") Reported-by: Yu Kuai <yukuai1@xxxxxxxxxxxxxxx> Signed-off-by: Christoph Hellwig <hch@xxxxxx> --- block/genhd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/genhd.c b/block/genhd.c index 6123005154b2a..734c2e74f42e3 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -530,8 +530,10 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, bd_unregister_all_holders(disk); out_put_slave_dir: kobject_put(disk->slave_dir); + disk->slave_dir = NULL; out_put_holder_dir: kobject_put(disk->part0->bd_holder_dir); + disk->part0->bd_holder_dir = NULL; out_del_integrity: blk_integrity_del(disk); out_del_block_link: -- 2.30.2