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

block: add back the bd_holder_dir reference in bd_link_disk_holder

This essentially reverts "block: remove the extra kobject reference in
bd_link_disk_holder". That commit dropped the extra reference because
the condition in the comment can't be true. But it turns out that
comment did not actually describe the problematic situation, so add
back the extra reference and document it properly.

Fixes: fbd9a39542ec ("block: remove the extra kobject reference in bd_link_disk_holder")
Reported-by: Tushar Sugandhi <tusharsu@linux.microsoft.com>
Reviewed-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
759e0fd4 e70344c0

+7
+7
block/holder.c
··· 106 106 } 107 107 108 108 list_add(&holder->list, &disk->slave_bdevs); 109 + /* 110 + * del_gendisk drops the initial reference to bd_holder_dir, so we need 111 + * to keep our own here to allow for cleanup past that point. 112 + */ 113 + kobject_get(bdev->bd_holder_dir); 114 + 109 115 out_unlock: 110 116 mutex_unlock(&disk->open_mutex); 111 117 return ret; ··· 144 138 if (!WARN_ON_ONCE(holder == NULL) && !--holder->refcnt) { 145 139 if (disk->slave_dir) 146 140 __unlink_disk_holder(bdev, disk); 141 + kobject_put(bdev->bd_holder_dir); 147 142 list_del_init(&holder->list); 148 143 kfree(holder); 149 144 }