mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: zhangjiao2 <zhangjiao2@cmss.chinamobile.com>, jonathan.lemon@gmail.com
Cc: vadim.fedorenko@linux.dev, richardcochran@gmail.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ptp: ocp: Fix the wrong format specifier
Date: Thu, 21 Nov 2024 09:28:27 +0100	[thread overview]
Message-ID: <722719e7-6f11-41cc-8a83-0a860bd1f12e@redhat.com> (raw)
In-Reply-To: <20241120062605.35739-1-zhangjiao2@cmss.chinamobile.com>



On 11/20/24 07:26, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> 
> Use '%u' instead of '%d' for unsigned int.
> 
> Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> ---
>  drivers/ptp/ptp_ocp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index 5feecaadde8e..52e46fee8e5e 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -1455,7 +1455,7 @@ ptp_ocp_verify(struct ptp_clock_info *ptp_info, unsigned pin,
>  		 * channels 1..4 are the frequency generators.
>  		 */
>  		if (chan)
> -			snprintf(buf, sizeof(buf), "OUT: GEN%d", chan);
> +			snprintf(buf, sizeof(buf), "OUT: GEN%u", chan);

Note that the above would still cause a warning, as the formatted string
could be theoretically truncated:

../drivers/ptp/ptp_ocp.c:1458:61: warning: ‘%u’ directive output may be
truncated writing between 1 and 10 bytes into a region of size 8
[-Wformat-truncation=]
                         snprintf(buf, sizeof(buf), "OUT: GEN%u", chan);

Since 'chan' range is [1,4] you can probably safely cast it an unsigned
byte, and update the format string accordingly.

/P


      parent reply	other threads:[~2024-11-21  8:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-20  6:26 zhangjiao2
2024-11-20 13:05 ` Vadim Fedorenko
2024-11-21  8:28 ` Paolo Abeni [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=722719e7-6f11-41cc-8a83-0a860bd1f12e@redhat.com \
    --to=pabeni@redhat.com \
    --cc=jonathan.lemon@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    --cc=vadim.fedorenko@linux.dev \
    --cc=zhangjiao2@cmss.chinamobile.com \
    /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®