mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Corey Minyard <minyard@acm.org>,
	openipmi-developer@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Subject: Re: [PATCH v1] ipmi: use %*ph to print small buffer
Date: Fri, 11 Oct 2019 07:58:14 -0700	[thread overview]
Message-ID: <4eaca9a1bcbf9d87c1fb3c9135876c3ecb72a91b.camel@perches.com> (raw)
In-Reply-To: <20191011145213.65082-1-andriy.shevchenko@linux.intel.com>

On Fri, 2019-10-11 at 17:52 +0300, Andy Shevchenko wrote:
> 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.
[]
> diff --git 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,

Now you might as well remove the #ifdef DEBUG above this
and the empty function in the #else too.



  reply	other threads:[~2019-10-11 14:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-11 14:52 Andy Shevchenko
2019-10-11 14:58 ` Joe Perches [this message]
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  1:21         ` kbuild test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4eaca9a1bcbf9d87c1fb3c9135876c3ecb72a91b.camel@perches.com \
    --to=joe@perches.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minyard@acm.org \
    --cc=openipmi-developer@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®