linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: storage: Add usb_stor_dbg, reduce object size
@ 2013-04-17  5:44 Joe Perches
  2013-04-17 14:14 ` Alan Stern
  0 siblings, 1 reply; 17+ messages in thread
From: Joe Perches @ 2013-04-17  5:44 UTC (permalink / raw)
  To: Matthew Dharm; +Cc: Greg Kroah-Hartman, linux-usb, usb-storage, LKML

Reduce the size of the objects by consolidating
the duplicated USB_STORAGE into a single function.

Add function usb_stor_dbg to emit debugging messages.
Always validate the format and arguments.
Reduce the number of uses of CONFIG_USB_STORAGE_DEBUG.

Reduces size of objects ~7KB when CONFIG_USB_STORAGE_DEBUG
is set.

$ size drivers/usb/storage/built-in.o*
   text	   data	    bss	    dec	    hex	filename
 140133	  55296	  70312	 265741	  40e0d	drivers/usb/storage/built-in.o.new
 147494	  55248	  70296	 273038	  42a8e	drivers/usb/storage/built-in.o.old

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/usb/storage/debug.c  | 20 +++++++++++++++++++-
 drivers/usb/storage/debug.h  | 14 +++++++++-----
 drivers/usb/storage/isd200.c | 12 ++++++------
 3 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/storage/debug.c b/drivers/usb/storage/debug.c
index a2b5526..b428129 100644
--- a/drivers/usb/storage/debug.c
+++ b/drivers/usb/storage/debug.c
@@ -150,7 +150,7 @@ void usb_stor_show_command(struct scsi_cmnd *srb)
 	default: what = "(unknown command)"; break;
 	}
 	US_DEBUGP("Command %s (%d bytes)\n", what, srb->cmd_len);
-	US_DEBUGP("");
+	US_DEBUGP("bytes: ");
 	for (i = 0; i < srb->cmd_len && i < 16; i++)
 		US_DEBUGPX(" %02x", srb->cmnd[i]);
 	US_DEBUGPX("\n");
@@ -175,3 +175,21 @@ void usb_stor_show_sense(
 	US_DEBUGPX(what, ascq);
 	US_DEBUGPX("\n");
 }
+
+int usb_stor_dbg(const char *fmt, ...)
+{
+	struct va_format vaf;
+	va_list args;
+	int r;
+
+	va_start(args, fmt);
+
+	vaf.fmt = fmt;
+	vaf.va = &args;
+
+	r = printk(KERN_DEBUG USB_STORAGE "%pV", &vaf);
+
+	va_end(args);
+
+	return r;
+}
diff --git a/drivers/usb/storage/debug.h b/drivers/usb/storage/debug.h
index dbb985d..d4280e1 100644
--- a/drivers/usb/storage/debug.h
+++ b/drivers/usb/storage/debug.h
@@ -50,12 +50,16 @@
 void usb_stor_show_command(struct scsi_cmnd *srb);
 void usb_stor_show_sense( unsigned char key,
 		unsigned char asc, unsigned char ascq );
-#define US_DEBUGP(x...) printk( KERN_DEBUG USB_STORAGE x )
-#define US_DEBUGPX(x...) printk( x )
-#define US_DEBUG(x) x 
+__printf(1, 2) int usb_stor_dbg(const char *fmt, ...);
+
+#define US_DEBUGP(fmt, ...)	usb_stor_dbg(fmt, ##__VA_ARGS__)
+#define US_DEBUGPX(fmt, ...)	printk(fmt, ##__VA_ARGS__)
+#define US_DEBUG(x)		x
 #else
-#define US_DEBUGP(x...)
-#define US_DEBUGPX(x...)
+#define US_DEBUGP(fmt, ...)					\
+	do { if (0) printk(fmt, ##__VA_ARGS__); } while (0)
+#define US_DEBUGPX(fmt, ...)					\
+	do { if (0) printk(fmt, ##__VA_ARGS__); } while (0)
 #define US_DEBUG(x)
 #endif
 
diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
index 06a3d22..55571ae 100644
--- a/drivers/usb/storage/isd200.c
+++ b/drivers/usb/storage/isd200.c
@@ -926,10 +926,6 @@ static int isd200_try_enum(struct us_data *us, unsigned char master_slave,
 
 	/* loop until we detect !BSY or timeout */
 	while(1) {
-#ifdef CONFIG_USB_STORAGE_DEBUG
-		char* mstr = master_slave == ATA_ADDRESS_DEVHEAD_STD ?
-			"Master" : "Slave";
-#endif
 
 		status = isd200_action( us, ACTION_ENUM, NULL, master_slave );
 		if ( status != ISD200_GOOD )
@@ -942,9 +938,13 @@ static int isd200_try_enum(struct us_data *us, unsigned char master_slave,
 
 		if (!detect) {
 			if (regs[ATA_REG_STATUS_OFFSET] & ATA_BUSY) {
-				US_DEBUGP("   %s status is still BSY, try again...\n",mstr);
+				US_DEBUGP("   %s status is still BSY, try again...\n",
+					  master_slave == ATA_ADDRESS_DEVHEAD_STD ?
+					  "Master" : "Slave");
 			} else {
-				US_DEBUGP("   %s status !BSY, continue with next operation\n",mstr);
+				US_DEBUGP("   %s status !BSY, continue with next operation\n",
+					  master_slave == ATA_ADDRESS_DEVHEAD_STD ?
+					  "Master" : "Slave");
 				break;
 			}
 		}



^ permalink raw reply related	[flat|nested] 17+ messages in thread
* Re: [PATCH V2] usb: storage: Convert US_DEBUGP to usb_stor_dbg
@ 2013-04-23 18:03 Joe Perches
  0 siblings, 0 replies; 17+ messages in thread
From: Joe Perches @ 2013-04-23 18:03 UTC (permalink / raw)
  To: LKML

cc'ing lkml:

On Mon, 2013-04-22 at 12:35 -0700, David Rientjes wrote:
> On Fri, 19 Apr 2013, Joe Perches wrote:
> 
> > @@ -966,11 +934,13 @@ static int realtek_cr_autosuspend_setup(struct us_data *us)
> >  static void realtek_cr_destructor(void *extra)
> >  {
> >       struct rts51x_chip *chip = (struct rts51x_chip *)extra;
> > -
> > -     US_DEBUGP("%s: <---\n", __func__);
> > +     struct us_data *us;
> >  
> >       if (!chip)
> >               return;
> > +
> > +     us = chip->us;
> > +
> >  #ifdef CONFIG_REALTEK_AUTOPM
> >       if (ss_en) {
> >               del_timer(&chip->rts51x_suspend_timer);
> 
> >From linux-next:
> 
> drivers/usb/storage/realtek_cr.c: In function 'realtek_cr_destructor':
> drivers/usb/storage/realtek_cr.c:942:11: error: 'struct rts51x_chip' has no member named 'us'
> 
> chip->us here is only defined when CONFIG_REALTEK_AUTOPM is enabled.

Thanks.

I'll fix it, but it'll likely be a couple of weeks
until I can.




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

end of thread, other threads:[~2013-04-26  8:59 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-17  5:44 [PATCH] usb: storage: Add usb_stor_dbg, reduce object size Joe Perches
2013-04-17 14:14 ` Alan Stern
2013-04-17 14:39   ` Joe Perches
2013-04-17 15:06     ` Alan Stern
2013-04-17 17:17       ` Joe Perches
2013-04-17 18:47         ` Alan Stern
2013-04-18  0:18           ` Joe Perches
2013-04-18 14:57             ` Alan Stern
2013-04-18 16:11               ` Joe Perches
2013-04-18  3:00           ` [PATCH] usb: storage: Convert US_DEBUGP to usb_stor_dbg Joe Perches
2013-04-19 17:35             ` Greg Kroah-Hartman
2013-04-19 17:44               ` Joe Perches
2013-04-19 18:44               ` [PATCH V2] " Joe Perches
2013-04-22 19:35                 ` David Rientjes
2013-04-25 22:32                   ` Andrew Morton
2013-04-26  8:59                     ` David Rientjes
2013-04-23 18:03 Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).