Skip to content

Commit

Permalink
bdev: Fixup error handling in blkdev_get()
Browse files Browse the repository at this point in the history
Commit 89e524c ("loop: Fix mount(2) failure due to race with
LOOP_SET_FD") converted blkdev_get() to use the new helpers for
finishing claiming of a block device. However the conversion botched the
error handling in blkdev_get() and thus the bdev has been marked as held
even in case __blkdev_get() returned error. This led to occasional
warnings with block/001 test from blktests like:

kernel: WARNING: CPU: 5 PID: 907 at fs/block_dev.c:1899 __blkdev_put+0x396/0x3a0

Correct the error handling.

CC: [email protected]
Fixes: 89e524c ("loop: Fix mount(2) failure due to race with LOOP_SET_FD")
Signed-off-by: Jan Kara <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
jankara authored and axboe committed Aug 8, 2019
1 parent fd03177 commit e91455b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,10 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder)

/* finish claiming */
mutex_lock(&bdev->bd_mutex);
bd_finish_claiming(bdev, whole, holder);
if (!res)
bd_finish_claiming(bdev, whole, holder);
else
bd_abort_claiming(bdev, whole, holder);
/*
* Block event polling for write claims if requested. Any
* write holder makes the write_holder state stick until
Expand Down

0 comments on commit e91455b

Please sign in to comment.