Skip to content

Commit

Permalink
block: add back the bd_holder_dir reference in bd_link_disk_holder
Browse files Browse the repository at this point in the history
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: fbd9a39 ("block: remove the extra kobject reference in bd_link_disk_holder")
Reported-by: Tushar Sugandhi <[email protected]>
Reviewed-by: Mike Snitzer <[email protected]>
Signed-off-by: Christoph Hellwig <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Christoph Hellwig authored and axboe committed Aug 21, 2021
1 parent e70344c commit 759e0fd
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions block/holder.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk)
}

list_add(&holder->list, &disk->slave_bdevs);
/*
* del_gendisk drops the initial reference to bd_holder_dir, so we need
* to keep our own here to allow for cleanup past that point.
*/
kobject_get(bdev->bd_holder_dir);

out_unlock:
mutex_unlock(&disk->open_mutex);
return ret;
Expand Down Expand Up @@ -138,6 +144,7 @@ void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk)
if (!WARN_ON_ONCE(holder == NULL) && !--holder->refcnt) {
if (disk->slave_dir)
__unlink_disk_holder(bdev, disk);
kobject_put(bdev->bd_holder_dir);
list_del_init(&holder->list);
kfree(holder);
}
Expand Down

0 comments on commit 759e0fd

Please sign in to comment.