All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] ipmi: use %*ph to print small buffer
@ 2019-10-11 14:52 Andy Shevchenko
  2019-10-11 14:58 ` Joe Perches
  0 siblings, 1 reply; 12+ messages in thread
From: Andy Shevchenko @ 2019-10-11 14:52 UTC (permalink / raw)
  To: Corey Minyard, openipmi-developer, linux-kernel
  Cc: Andy Shevchenko, Andy Shevchenko

From: Andy Shevchenko <andy.shevchenko@gmail.com>

Use %*ph format to print small buffer as hex string.

The change is safe since the specifier can handle up to 64 bytes and taking
into account the buffer size of 100 bytes on stack the function has never been
used to dump more than 32 bytes. Note, this also avoids potential buffer
overflow if the length of the input buffer is bigger.

Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/char/ipmi/ipmi_msghandler.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 2aab80e19ae0..d0cefd95fa57 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -48,14 +48,7 @@ static int handle_one_recv_msg(struct ipmi_smi *intf,
 static void ipmi_debug_msg(const char *title, unsigned char *data,
 			   unsigned int len)
 {
-	int i, pos;
-	char buf[100];
-
-	pos = snprintf(buf, sizeof(buf), "%s: ", title);
-	for (i = 0; i < len; i++)
-		pos += snprintf(buf + pos, sizeof(buf) - pos,
-				" %2.2x", data[i]);
-	pr_debug("%s\n", buf);
+	pr_debug("%s: %*ph\n", title, len, buf);
 }
 #else
 static void ipmi_debug_msg(const char *title, unsigned char *data,
-- 
2.23.0


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

end of thread, other threads:[~2019-10-14  1:22 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-11 14:52 [PATCH v1] ipmi: use %*ph to print small buffer Andy Shevchenko
2019-10-11 14:58 ` Joe Perches
2019-10-11 15:12   ` Andy Shevchenko
2019-10-11 15:18     ` Joe Perches
2019-10-11 15:36       ` Andy Shevchenko
2019-10-11 15:46       ` [PATCH] ipmi: Convert ipmi_debug_msg to pr_debug and use %*ph Joe Perches
2019-10-11 16:05         ` Andy Shevchenko
2019-10-11 16:15           ` Joe Perches
2019-10-14  0:55         ` kbuild test robot
2019-10-14  0:55           ` kbuild test robot
2019-10-14  1:21         ` kbuild test robot
2019-10-14  1:21           ` kbuild test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.