diff mbox

rtc: rtc-rs5c372: use %*ph to dump small buffers

Message ID 1409929669-5041-1-git-send-email-andriy.shevchenko@linux.intel.com
State Accepted
Headers show

Commit Message

Andy Shevchenko Sept. 5, 2014, 3:07 p.m. UTC
Instead of pushing each byte let's reduce stack usage by using %*ph specifier.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/rtc/rtc-rs5c372.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Comments

Andrew Morton Sept. 24, 2014, 10:45 p.m. UTC | #1
On Fri,  5 Sep 2014 18:07:49 +0300 Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Instead of pushing each byte let's reduce stack usage by using %*ph specifier.
> 
> ...
>
> --- a/drivers/rtc/rtc-rs5c372.c
> +++ b/drivers/rtc/rtc-rs5c372.c
> @@ -142,12 +142,11 @@ static int rs5c_get_regs(struct rs5c372 *rs5c)
>  	}
>  
>  	dev_dbg(&client->dev,
> -		"%02x %02x %02x (%02x) %02x %02x %02x (%02x), "
> -		"%02x %02x %02x, %02x %02x %02x; %02x %02x\n",
> -		rs5c->regs[0],  rs5c->regs[1],  rs5c->regs[2],  rs5c->regs[3],
> -		rs5c->regs[4],  rs5c->regs[5],  rs5c->regs[6],  rs5c->regs[7],
> -		rs5c->regs[8],  rs5c->regs[9],  rs5c->regs[10], rs5c->regs[11],
> -		rs5c->regs[12], rs5c->regs[13], rs5c->regs[14], rs5c->regs[15]);
> +		"%3ph (%02x) %3ph (%02x), %3ph, %3ph; %02x %02x\n",
> +		rs5c->regs + 0, rs5c->regs[3],
> +		rs5c->regs + 4, rs5c->regs[7],
> +		rs5c->regs + 8, rs5c->regs + 11,
> +		rs5c->regs[14], rs5c->regs[15]);
>  
>  	return 0;
>  }

Has this been runtime tested?  This appears to be the only use of %ph
in the kernel and I wonder if it actually works (and why we added
it...)

The documentation (at lib/vsprintf.c:pointer()) for %ph is pretty poor.
Some usage examples would help.
diff mbox

Patch

diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
index ccf54f0..28871cd 100644
--- a/drivers/rtc/rtc-rs5c372.c
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -142,12 +142,11 @@  static int rs5c_get_regs(struct rs5c372 *rs5c)
 	}
 
 	dev_dbg(&client->dev,
-		"%02x %02x %02x (%02x) %02x %02x %02x (%02x), "
-		"%02x %02x %02x, %02x %02x %02x; %02x %02x\n",
-		rs5c->regs[0],  rs5c->regs[1],  rs5c->regs[2],  rs5c->regs[3],
-		rs5c->regs[4],  rs5c->regs[5],  rs5c->regs[6],  rs5c->regs[7],
-		rs5c->regs[8],  rs5c->regs[9],  rs5c->regs[10], rs5c->regs[11],
-		rs5c->regs[12], rs5c->regs[13], rs5c->regs[14], rs5c->regs[15]);
+		"%3ph (%02x) %3ph (%02x), %3ph, %3ph; %02x %02x\n",
+		rs5c->regs + 0, rs5c->regs[3],
+		rs5c->regs + 4, rs5c->regs[7],
+		rs5c->regs + 8, rs5c->regs + 11,
+		rs5c->regs[14], rs5c->regs[15]);
 
 	return 0;
 }