[PATCH 4/4] Disallow changing the device state via sysfs into "deleted"

Bart Van Assche
2013-07-02T13:08:11Z

Changing the state of a SCSI device via sysfs into "cancel" or
"deleted" prevents removal of these devices by scsi_remove_host().
Hence do not allow this.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: James Bottomley <JBottomley@Parallels.com>
Cc: Mike Christie <michaelc@cs.wisc.edu>
Cc: Hannes Reinecke <hare@suse.de>
Cc: David Milburn <dmilburn@redhat.com>
---
drivers/scsi/scsi_sysfs.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 1711617..292df85 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -605,10 +605,8 @@ store_state_field(struct device *dev, struct device_attribute *attr,
break;
}
}
- if (!state)
- return -EINVAL;
-
- if (scsi_device_set_state(sdev, state))
+ if (state == 0 || state == SDEV_CANCEL || state == SDEV_DEL ||
+ scsi_device_set_state(sdev, state))
return -EINVAL;
return count;
}
--
1.7.10.4