Skip to contentSkip to conversation

scsi: Use vsprint extension %pV, save ~16KB

PATCH New Joe Perches 1 participant 1 message Nov 23, 2010 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: Use vsprint extension %pV, save ~16KB

Make a function out of the scmd_printk macro.
Use %pV in the scmd_printk function to reduce string duplication. Move the function prototype to include/scsi/scsi_cmnd.h

allyesconfig x86 size
text data bss dec hex filename
5329860 125779 1279944 6735583 66c6df drivers/scsi/built-in.o.new
5345681 125779 1281912 6753372 670c5c drivers/scsi/built-in.o.old

---
 drivers/scsi/sd.c          |   24 ++++++++++++++++++++++++
 include/scsi/scsi_cmnd.h   |    4 ++++
 include/scsi/scsi_device.h |    6 ------
 3 files changed, 28 insertions(+), 6 deletions(-)
drivers/scsi/sd.c +24 -0
index 9564961..5a15e1b 100644
@@ -2711,3 +2711,27 @@ static void sd_print_result(struct scsi_disk *sdkp, int result)
 	scsi_show_result(result);
 }
 
+/* scmd_printk utility routine */
+
+int scmd_printk(const char *prefix, const struct scsi_cmnd *scmd,
+		const char *fmt, ...)
+{
+	int rtn;
+	struct va_format vaf;
+	va_list args;
+	
+	va_start(args, fmt);
+
+	vaf.fmt = fmt;
+	vaf.va = &args;
+
+	if (scmd->request->rq_disk)
+		rtn = sdev_printk(prefix, scmd->device, "[%s] %pV",
+				  scmd->request->rq_disk->disk_name, &vaf);
+	else
+		rtn = sdev_printk(prefix, scmd->device, "%pV", &vaf);
+
+	va_end(args);
+
+	return rtn;
+}
include/scsi/scsi_cmnd.h +4 -0
index a5e885a..e055815 100644
@@ -302,4 +302,8 @@ static inline void set_driver_byte(struct scsi_cmnd *cmd, char status)
 	cmd->result |= status << 24;
 }
 
+__attribute__((format (printf, 3, 4)))
+int scmd_printk(const char *prefix, const struct scsi_cmnd *scmd,
+		const char *fmt, ...);
+
 #endif /* _SCSI_SCSI_CMND_H */
include/scsi/scsi_device.h +0 -6
index 85867dc..6f6fb36 100644
@@ -214,12 +214,6 @@ struct scsi_dh_data {
 #define sdev_printk(prefix, sdev, fmt, a...)	\
 	dev_printk(prefix, &(sdev)->sdev_gendev, fmt, ##a)
 
-#define scmd_printk(prefix, scmd, fmt, a...)				\
-        (scmd)->request->rq_disk ?					\
-	sdev_printk(prefix, (scmd)->device, "[%s] " fmt,		\
-		    (scmd)->request->rq_disk->disk_name, ##a) :		\
-	sdev_printk(prefix, (scmd)->device, fmt, ##a)
-
 enum scsi_target_state {
 	STARGET_CREATED = 1,
 	STARGET_RUNNING,