public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sd: fix sysfs writes to "provisioning_mode" and "zeroing_mode"
@ 2017-05-15 19:13 Ewan D. Milne
  2017-05-15 20:14 ` Bart Van Assche
  0 siblings, 1 reply; 6+ messages in thread
From: Ewan D. Milne @ 2017-05-15 19:13 UTC (permalink / raw)
  To: linux-scsi

From: "Ewan D. Milne" <emilne@redhat.com>

Change to use strlen() of the desired string for the length
parameter to strncmp().  Otherwise one cannot simply use a
command like 'echo "writesame_16" > .../provisioning_mode'.
This patch makes sysfs writes consistent with other usage.

Signed-off-by: Ewan D. Milne <emilne@redhat.com>
---
 drivers/scsi/sd.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index f9d1432..a5eacea 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -402,15 +402,20 @@ provisioning_mode_store(struct device *dev, struct device_attribute *attr,
 	if (sdp->type != TYPE_DISK)
 		return -EINVAL;
 
-	if (!strncmp(buf, lbp_mode[SD_LBP_UNMAP], 20))
+	if (!strncmp(buf, lbp_mode[SD_LBP_UNMAP],
+		     strlen(lbp_mode[SD_LBP_UNMAP])))
 		sd_config_discard(sdkp, SD_LBP_UNMAP);
-	else if (!strncmp(buf, lbp_mode[SD_LBP_WS16], 20))
+	else if (!strncmp(buf, lbp_mode[SD_LBP_WS16],
+			  strlen(lbp_mode[SD_LBP_WS16])))
 		sd_config_discard(sdkp, SD_LBP_WS16);
-	else if (!strncmp(buf, lbp_mode[SD_LBP_WS10], 20))
+	else if (!strncmp(buf, lbp_mode[SD_LBP_WS10],
+			  strlen(lbp_mode[SD_LBP_WS10])))
 		sd_config_discard(sdkp, SD_LBP_WS10);
-	else if (!strncmp(buf, lbp_mode[SD_LBP_ZERO], 20))
+	else if (!strncmp(buf, lbp_mode[SD_LBP_ZERO],
+			  strlen(lbp_mode[SD_LBP_ZERO])))
 		sd_config_discard(sdkp, SD_LBP_ZERO);
-	else if (!strncmp(buf, lbp_mode[SD_LBP_DISABLE], 20))
+	else if (!strncmp(buf, lbp_mode[SD_LBP_DISABLE],
+			  strlen(lbp_mode[SD_LBP_DISABLE])))
 		sd_config_discard(sdkp, SD_LBP_DISABLE);
 	else
 		return -EINVAL;
@@ -444,13 +449,17 @@ zeroing_mode_store(struct device *dev, struct device_attribute *attr,
 	if (!capable(CAP_SYS_ADMIN))
 		return -EACCES;
 
-	if (!strncmp(buf, zeroing_mode[SD_ZERO_WRITE], 20))
+	if (!strncmp(buf, zeroing_mode[SD_ZERO_WRITE],
+		     strlen(zeroing_mode[SD_ZERO_WRITE])))
 		sdkp->zeroing_mode = SD_ZERO_WRITE;
-	else if (!strncmp(buf, zeroing_mode[SD_ZERO_WS], 20))
+	else if (!strncmp(buf, zeroing_mode[SD_ZERO_WS],
+			  strlen(zeroing_mode[SD_ZERO_WS])))
 		sdkp->zeroing_mode = SD_ZERO_WS;
-	else if (!strncmp(buf, zeroing_mode[SD_ZERO_WS16_UNMAP], 20))
+	else if (!strncmp(buf, zeroing_mode[SD_ZERO_WS16_UNMAP],
+			  strlen(zeroing_mode[SD_ZERO_WS16_UNMAP])))
 		sdkp->zeroing_mode = SD_ZERO_WS16_UNMAP;
-	else if (!strncmp(buf, zeroing_mode[SD_ZERO_WS10_UNMAP], 20))
+	else if (!strncmp(buf, zeroing_mode[SD_ZERO_WS10_UNMAP],
+			  strlen(zeroing_mode[SD_ZERO_WS10_UNMAP])))
 		sdkp->zeroing_mode = SD_ZERO_WS10_UNMAP;
 	else
 		return -EINVAL;
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-05-16 12:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-15 19:13 [PATCH] sd: fix sysfs writes to "provisioning_mode" and "zeroing_mode" Ewan D. Milne
2017-05-15 20:14 ` Bart Van Assche
2017-05-15 21:02   ` Ewan D. Milne
2017-05-15 21:14     ` Bart Van Assche
2017-05-15 21:18       ` Martin K. Petersen
2017-05-16 12:52         ` Ewan D. Milne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox