aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/scsi_sysfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/scsi_sysfs.c')
-rw-r--r--drivers/scsi/scsi_sysfs.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 64c96c7828ee..6d7362e7367e 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -730,6 +730,14 @@ sdev_store_delete(struct device *dev, struct device_attribute *attr,
730 const char *buf, size_t count) 730 const char *buf, size_t count)
731{ 731{
732 struct kernfs_node *kn; 732 struct kernfs_node *kn;
733 struct scsi_device *sdev = to_scsi_device(dev);
734
735 /*
736 * We need to try to get module, avoiding the module been removed
737 * during delete.
738 */
739 if (scsi_device_get(sdev))
740 return -ENODEV;
733 741
734 kn = sysfs_break_active_protection(&dev->kobj, &attr->attr); 742 kn = sysfs_break_active_protection(&dev->kobj, &attr->attr);
735 WARN_ON_ONCE(!kn); 743 WARN_ON_ONCE(!kn);
@@ -744,9 +752,10 @@ sdev_store_delete(struct device *dev, struct device_attribute *attr,
744 * state into SDEV_DEL. 752 * state into SDEV_DEL.
745 */ 753 */
746 device_remove_file(dev, attr); 754 device_remove_file(dev, attr);
747 scsi_remove_device(to_scsi_device(dev)); 755 scsi_remove_device(sdev);
748 if (kn) 756 if (kn)
749 sysfs_unbreak_active_protection(kn); 757 sysfs_unbreak_active_protection(kn);
758 scsi_device_put(sdev);
750 return count; 759 return count;
751}; 760};
752static DEVICE_ATTR(delete, S_IWUSR, NULL, sdev_store_delete); 761static DEVICE_ATTR(delete, S_IWUSR, NULL, sdev_store_delete);