aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
Diffstat (limited to 'block')
-rw-r--r--block/bsg.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/block/bsg.c b/block/bsg.c
index 8917c5174dc2..d8e0cb8dd6be 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -705,6 +705,7 @@ static struct bsg_device *bsg_alloc_device(void)
705static int bsg_put_device(struct bsg_device *bd) 705static int bsg_put_device(struct bsg_device *bd)
706{ 706{
707 int ret = 0; 707 int ret = 0;
708 struct device *dev = bd->queue->bsg_dev.dev;
708 709
709 mutex_lock(&bsg_mutex); 710 mutex_lock(&bsg_mutex);
710 711
@@ -730,6 +731,7 @@ static int bsg_put_device(struct bsg_device *bd)
730 kfree(bd); 731 kfree(bd);
731out: 732out:
732 mutex_unlock(&bsg_mutex); 733 mutex_unlock(&bsg_mutex);
734 put_device(dev);
733 return ret; 735 return ret;
734} 736}
735 737
@@ -789,21 +791,27 @@ static struct bsg_device *bsg_get_device(struct inode *inode, struct file *file)
789 struct bsg_device *bd; 791 struct bsg_device *bd;
790 struct bsg_class_device *bcd; 792 struct bsg_class_device *bcd;
791 793
792 bd = __bsg_get_device(iminor(inode));
793 if (bd)
794 return bd;
795
796 /* 794 /*
797 * find the class device 795 * find the class device
798 */ 796 */
799 mutex_lock(&bsg_mutex); 797 mutex_lock(&bsg_mutex);
800 bcd = idr_find(&bsg_minor_idr, iminor(inode)); 798 bcd = idr_find(&bsg_minor_idr, iminor(inode));
799 if (bcd)
800 get_device(bcd->dev);
801 mutex_unlock(&bsg_mutex); 801 mutex_unlock(&bsg_mutex);
802 802
803 if (!bcd) 803 if (!bcd)
804 return ERR_PTR(-ENODEV); 804 return ERR_PTR(-ENODEV);
805 805
806 return bsg_add_device(inode, bcd->queue, file); 806 bd = __bsg_get_device(iminor(inode));
807 if (bd)
808 return bd;
809
810 bd = bsg_add_device(inode, bcd->queue, file);
811 if (IS_ERR(bd))
812 put_device(bcd->dev);
813
814 return bd;
807} 815}
808 816
809static int bsg_open(struct inode *inode, struct file *file) 817static int bsg_open(struct inode *inode, struct file *file)
@@ -942,7 +950,6 @@ void bsg_unregister_queue(struct request_queue *q)
942 class_device_unregister(bcd->class_dev); 950 class_device_unregister(bcd->class_dev);
943 put_device(bcd->dev); 951 put_device(bcd->dev);
944 bcd->class_dev = NULL; 952 bcd->class_dev = NULL;
945 bcd->dev = NULL;
946 mutex_unlock(&bsg_mutex); 953 mutex_unlock(&bsg_mutex);
947} 954}
948EXPORT_SYMBOL_GPL(bsg_unregister_queue); 955EXPORT_SYMBOL_GPL(bsg_unregister_queue);