diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2008-03-30 21:03:38 -0400 |
---|---|---|
committer | James Bottomley <James.Bottomley@HansenPartnership.com> | 2008-04-18 12:47:19 -0400 |
commit | d45ac4fa8f277e1ec5acfb67ce5d6406555760cf (patch) | |
tree | f620055da979b1af58bfdac16f35f90cd67e6f13 /block | |
parent | 0e4ff797d7f2f2bb860b8f31dc5d1f2273b2f05a (diff) |
[SCSI] bsg: takes a ref to struct device in fops->open
bsg_register_queue() takes a ref to struct device that a caller
passes. For example, bsg takes a ref to the sdev_gendev for scsi
devices. However, bsg doesn't inrease the refcount in fops->open. So
while an application opens a bsg device, the scsi device that the bsg
device holds can go away (bsg also takes a ref to a queue, but it
doesn't prevent the device from going away).
With this patch, bsg increases the refcount of struct device in
fops->open and decreases it in fops->release.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Diffstat (limited to 'block')
-rw-r--r-- | block/bsg.c | 19 |
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) | |||
705 | static int bsg_put_device(struct bsg_device *bd) | 705 | static 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); |
731 | out: | 732 | out: |
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 | ||
809 | static int bsg_open(struct inode *inode, struct file *file) | 817 | static 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 | } |
948 | EXPORT_SYMBOL_GPL(bsg_unregister_queue); | 955 | EXPORT_SYMBOL_GPL(bsg_unregister_queue); |