Skip to contentSkip to conversation

scsi: sd: Use string_choices to fix Coccinelle warnings

PATCH In review Nick Spooner 3 participants 3 messages Apr 23 – Apr 27 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: sd: Use string_choices to fix Coccinelle warnings

Fixes the following Coccinelle warnings reported by string_choices.cocci:

	opportunity for str_enabled_disabled(sdkp -> WCE)
	opportunity for str_on_off(sdkp -> write_prot)
---
 drivers/scsi/sd.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/scsi/sd.c +4 -3
index adc3fa55ca2c..dd284647ed64 100644
@@ -50,6 +50,7 @@
 #include <linux/rw_hint.h>
 #include <linux/major.h>
 #include <linux/mutex.h>
+#include <linux/string_choices.h>
 #include <linux/string_helpers.h>
 #include <linux/slab.h>
 #include <linux/sed-opal.h>
@@ -3084,7 +3085,7 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, unsigned char *buffer)
 		set_disk_ro(sdkp->disk, sdkp->write_prot);
 		if (sdkp->first_scan || old_wp != sdkp->write_prot) {
 			sd_printk(KERN_NOTICE, sdkp, "Write Protect is %s\n",
-				  sdkp->write_prot ? "on" : "off");
+				  str_on_off(sdkp->write_prot));
 			sd_printk(KERN_DEBUG, sdkp, "Mode Sense: %4ph\n", buffer);
 		}
 	}
@@ -3235,8 +3236,8 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer)
 		    old_rcd != sdkp->RCD || old_dpofua != sdkp->DPOFUA)
 			sd_printk(KERN_NOTICE, sdkp,
 				  "Write cache: %s, read cache: %s, %s\n",
-				  sdkp->WCE ? "enabled" : "disabled",
-				  sdkp->RCD ? "disabled" : "enabled",
+				  str_enabled_disabled(sdkp->WCE),
+				  str_disabled_enabled(sdkp->RCD),
 				  sdkp->DPOFUA ? "supports DPO and FUA"
 				  : "doesn't support DPO or FUA");
 
Signature · 1 line
2.53.0
#1 lore raw
Quoted 22 lines · Nick Spooner
drivers/scsi/sd.c +2 -1
index adc3fa55ca2c..dd284647ed64 100644
@@ -50,6 +50,7 @@
  #include <linux/rw_hint.h>
  #include <linux/major.h>
  #include <linux/mutex.h>
+#include <linux/string_choices.h>
  #include <linux/string_helpers.h>
  #include <linux/slab.h>
  #include <linux/sed-opal.h>
@@ -3084,7 +3085,7 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, unsigned char *buffer)
  		set_disk_ro(sdkp->disk, sdkp->write_prot);
  		if (sdkp->first_scan || old_wp != sdkp->write_prot) {
  			sd_printk(KERN_NOTICE, sdkp, "Write Protect is %s\n",
-				  sdkp->write_prot ? "on" : "off");
+				  str_on_off(sdkp->write_prot));
  			sd_printk(KERN_DEBUG, sdkp, "Mode Sense: %4ph\n", buffer);
  		}
  	}

drivers/scsi/sd.c sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer) · line 3242

Quoted 9 lines
drivers/scsi/sd.c +2 -2
@@ -3235,8 +3236,8 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer)
  		    old_rcd != sdkp->RCD || old_dpofua != sdkp->DPOFUA)
  			sd_printk(KERN_NOTICE, sdkp,
  				  "Write cache: %s, read cache: %s, %s\n",
-				  sdkp->WCE ? "enabled" : "disabled",
-				  sdkp->RCD ? "disabled" : "enabled",
+				  str_enabled_disabled(sdkp->WCE),
+				  str_disabled_enabled(sdkp->RCD),
  				  sdkp->DPOFUA ? "supports DPO and FUA"
  				  : "doesn't support DPO or FUA");

My opinion is that the sd code is easier to read *without* this patch. But that's just my opinion. Maybe there are other opinions.

Bart.

#2 lore raw

Bart,

Quoted 1 line

My opinion is that the sd code is easier to read *without* this patch.

Yep, I agree.

Signature · 1 line
Martin K. Petersen