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

From: Joe Perches
Date: Mon Nov 22 2010 - 22:40:20 EST


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

Signed-off-by: Joe Perches <joe@xxxxxxxxxxx>
---
drivers/scsi/sd.c | 24 ++++++++++++++++++++++++
include/scsi/scsi_cmnd.h | 4 ++++
include/scsi/scsi_device.h | 6 ------
3 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 9564961..5a15e1b 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -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;
+}
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index a5e885a..e055815 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -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 */
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 85867dc..6f6fb36 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -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,


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/