aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--block/bsg.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/block/bsg.c b/block/bsg.c
index f0b7cd343216..7cdec32205d8 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -724,8 +724,13 @@ static int bsg_put_device(struct bsg_device *bd)
724 mutex_lock(&bsg_mutex); 724 mutex_lock(&bsg_mutex);
725 725
726 do_free = atomic_dec_and_test(&bd->ref_count); 726 do_free = atomic_dec_and_test(&bd->ref_count);
727 if (!do_free) 727 if (!do_free) {
728 mutex_unlock(&bsg_mutex);
728 goto out; 729 goto out;
730 }
731
732 hlist_del(&bd->dev_list);
733 mutex_unlock(&bsg_mutex);
729 734
730 dprintk("%s: tearing down\n", bd->name); 735 dprintk("%s: tearing down\n", bd->name);
731 736
@@ -741,10 +746,8 @@ static int bsg_put_device(struct bsg_device *bd)
741 */ 746 */
742 ret = bsg_complete_all_commands(bd); 747 ret = bsg_complete_all_commands(bd);
743 748
744 hlist_del(&bd->dev_list);
745 kfree(bd); 749 kfree(bd);
746out: 750out:
747 mutex_unlock(&bsg_mutex);
748 kref_put(&q->bsg_dev.ref, bsg_kref_release_function); 751 kref_put(&q->bsg_dev.ref, bsg_kref_release_function);
749 if (do_free) 752 if (do_free)
750 blk_put_queue(q); 753 blk_put_queue(q);