change allow_restart, manage_start_stop to bool in sysfs
v2 cover change allow_restart, manage_start_stop to bool in sysfs
Changes since V1:
switch kstrtoint to kstrtobool.
add fix for manage_start_stop.
weiping zhang (2):
scsi: sd: change allow_restart to bool in sysfs interface
scsi: sd: change manage_start_stop to bool in sysfs interface
drivers/scsi/sd.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
Signature · 1 line
2.9.4
PATCH v2 1/2 scsi: sd: change allow_restart to bool in sysfs interface
/sys/class/scsi_disk/0:2:0:0/allow_restart can be changed to 0 unexpectly by writing invalid string, like following:
echo asdf > /sys/class/scsi_disk/0:2:0:0/allow_restart
--- drivers/scsi/sd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/scsi/sd.c +5 -1
@@ -253,6 +253,7 @@ static ssize_t allow_restart_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { + bool v;struct scsi_disk *sdkp =to_scsi_disk (dev);struct scsi_device *sdp = sdkp->device;
@@ -262,7 +263,10 @@ allow_restart_store(struct device *dev, struct device_attribute *attr,if (sdp->type !=TYPE_DISK && sdp->type !=TYPE_ZBC )return -EINVAL ; - sdp->allow_restart =simple_strtoul (buf,NULL ,10 ); +if (kstrtobool (buf, &v)) +return -EINVAL ; + + sdp->allow_restart = v ?1 :0 ;return count; }
Signature · 1 line
2.9.4
PATCH v2 2/2 scsi: sd: change manage_start_stop to bool in sysfs interface
In reply to weiping zhang/sys/class/scsi_disk/0:2:0:0/manage_start_stop can be changed to 0 unexpectly by writing invalid string.
--- drivers/scsi/sd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/scsi/sd.c +5 -1
@@ -231,11 +231,15 @@ manage_start_stop_store(struct device *dev, struct device_attribute *attr, {struct scsi_disk *sdkp =to_scsi_disk (dev);struct scsi_device *sdp = sdkp->device; +bool v;if (!capable (CAP_SYS_ADMIN ))return -EACCES ; - sdp->manage_start_stop =simple_strtoul (buf,NULL ,10 ); +if (kstrtobool (buf, &v)) +return -EINVAL ; + + sdp->manage_start_stop = v ?1 :0 ;return count; }
Signature · 1 line
2.9.4
Martin K. Petersen
Appliedweiping,
Quoted 3 lines
weiping zhang (2):
scsi: sd: changeallow_restartto bool in sysfs interface
scsi: sd: changemanage_start_stopto bool in sysfs interface
Applied to 4.15/scsi-queue. Thank you!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering