Skip to content

Commit

Permalink
[SCSI] bsg: fix bsg_mutex hang with device removal
Browse files Browse the repository at this point in the history
We don't need to hold bsg_mutex during bsg_complete_all_commands(). It
leads to a problem that we block bsg_unregister_queue during
bsg_complete_all_commands (untill all the outstanding commands
complete).

Thanks to Pete Wyckoff for finding the bug and testing the patch.

The detailed bug report is:

http://marc.info/?l=linux-scsi&m=121182137132145&w=2

Tested-by: Pete Wyckoff <[email protected]>
Signed-off-by: FUJITA Tomonori <[email protected]>
Signed-off-by: James Bottomley <[email protected]>
  • Loading branch information
fujita authored and James Bottomley committed Jul 12, 2008
1 parent 30e9ba9 commit 3f27e3e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions block/bsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,13 @@ static int bsg_put_device(struct bsg_device *bd)
mutex_lock(&bsg_mutex);

do_free = atomic_dec_and_test(&bd->ref_count);
if (!do_free)
if (!do_free) {
mutex_unlock(&bsg_mutex);
goto out;
}

hlist_del(&bd->dev_list);
mutex_unlock(&bsg_mutex);

dprintk("%s: tearing down\n", bd->name);

Expand All @@ -741,10 +746,8 @@ static int bsg_put_device(struct bsg_device *bd)
*/
ret = bsg_complete_all_commands(bd);

hlist_del(&bd->dev_list);
kfree(bd);
out:
mutex_unlock(&bsg_mutex);
kref_put(&q->bsg_dev.ref, bsg_kref_release_function);
if (do_free)
blk_put_queue(q);
Expand Down

0 comments on commit 3f27e3e

Please sign in to comment.