linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Corey Minyard <minyard@acm.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: openipmi-developer@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, Joe Perches <joe@perches.com>,
	Andy Shevchenko <andy.shevchenko@gmail.com>
Subject: Re: [PATCH v2] ipmi: use %*ph to print small buffer
Date: Mon, 14 Oct 2019 14:57:28 -0500	[thread overview]
Message-ID: <20191014195728.GG25427@t560> (raw)
In-Reply-To: <20191011155036.36748-1-andriy.shevchenko@linux.intel.com>

On Fri, Oct 11, 2019 at 06:50:36PM +0300, Andy Shevchenko wrote:
> 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.

This is an improvment, thanks, it is in queue in the next tree and
queued for the next merge window.

Thanks, Andy and Jes, for sorting this out while I was on vacation,

-corey

> 
> This completely eliminates ipmi_debug_msg() in favour of Dynamic Debug.
> 
> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> - eliminate ipmi_debug_msg() in favour of Dynamic Debug (Joe)
>  drivers/char/ipmi/ipmi_msghandler.c | 27 ++++-----------------------
>  1 file changed, 4 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
> index 2aab80e19ae0..1768b81aaf78 100644
> --- a/drivers/char/ipmi/ipmi_msghandler.c
> +++ b/drivers/char/ipmi/ipmi_msghandler.c
> @@ -44,25 +44,6 @@ static void need_waiter(struct ipmi_smi *intf);
>  static int handle_one_recv_msg(struct ipmi_smi *intf,
>  			       struct ipmi_smi_msg *msg);
>  
> -#ifdef DEBUG
> -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);
> -}
> -#else
> -static void ipmi_debug_msg(const char *title, unsigned char *data,
> -			   unsigned int len)
> -{ }
> -#endif
> -
>  static bool initialized;
>  static bool drvregistered;
>  
> @@ -2267,7 +2248,7 @@ static int i_ipmi_request(struct ipmi_user     *user,
>  		ipmi_free_smi_msg(smi_msg);
>  		ipmi_free_recv_msg(recv_msg);
>  	} else {
> -		ipmi_debug_msg("Send", smi_msg->data, smi_msg->data_size);
> +		pr_debug("Send: %*ph\n", smi_msg->data_size, smi_msg->data);
>  
>  		smi_send(intf, intf->handlers, smi_msg, priority);
>  	}
> @@ -3730,7 +3711,7 @@ static int handle_ipmb_get_msg_cmd(struct ipmi_smi *intf,
>  		msg->data[10] = ipmb_checksum(&msg->data[6], 4);
>  		msg->data_size = 11;
>  
> -		ipmi_debug_msg("Invalid command:", msg->data, msg->data_size);
> +		pr_debug("Invalid command: %*ph\n", msg->data_size, msg->data);
>  
>  		rcu_read_lock();
>  		if (!intf->in_shutdown) {
> @@ -4217,7 +4198,7 @@ static int handle_one_recv_msg(struct ipmi_smi *intf,
>  	int requeue;
>  	int chan;
>  
> -	ipmi_debug_msg("Recv:", msg->rsp, msg->rsp_size);
> +	pr_debug("Recv: %*ph\n", msg->rsp_size, msg->rsp);
>  
>  	if ((msg->data_size >= 2)
>  	    && (msg->data[0] == (IPMI_NETFN_APP_REQUEST << 2))
> @@ -4576,7 +4557,7 @@ smi_from_recv_msg(struct ipmi_smi *intf, struct ipmi_recv_msg *recv_msg,
>  	smi_msg->data_size = recv_msg->msg.data_len;
>  	smi_msg->msgid = STORE_SEQ_IN_MSGID(seq, seqid);
>  
> -	ipmi_debug_msg("Resend: ", smi_msg->data, smi_msg->data_size);
> +	pr_debug("Resend: %*ph\n", smi_msg->data_size, smi_msg->data);
>  
>  	return smi_msg;
>  }
> -- 
> 2.23.0
> 

      reply	other threads:[~2019-10-14 19:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-11 15:50 [PATCH v2] ipmi: use %*ph to print small buffer Andy Shevchenko
2019-10-14 19:57 ` Corey Minyard [this message]

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=20191014195728.GG25427@t560 \
    --to=minyard@acm.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).