Skip to content

Commit e91455b

Browse files
jankaraaxboe
authored andcommitted
bdev: Fixup error handling in blkdev_get()
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]>
1 parent fd03177 commit e91455b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

fs/block_dev.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,10 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder)
17501750

17511751
/* finish claiming */
17521752
mutex_lock(&bdev->bd_mutex);
1753-
bd_finish_claiming(bdev, whole, holder);
1753+
if (!res)
1754+
bd_finish_claiming(bdev, whole, holder);
1755+
else
1756+
bd_abort_claiming(bdev, whole, holder);
17541757
/*
17551758
* Block event polling for write claims if requested. Any
17561759
* write holder makes the write_holder state stick until

0 commit comments

Comments
 (0)