mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sandipan Das <sandipan.das@amd.com>
To: Jean Delvare <jdelvare@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] perf/x86/amd/uncore: Avoid a false positive warning about snprintf truncation in amd_uncore_umc_ctx_init
Date: Tue, 5 Nov 2024 15:04:02 +0530	[thread overview]
Message-ID: <5907e4cf-d71f-4c5e-8504-a0177819ebb0@amd.com> (raw)
In-Reply-To: <20241105095253.18f34b4d@endymion.delvare>

On 11/5/2024 2:22 PM, Jean Delvare wrote:
> Fix the following warning:
>   CC [M]  arch/x86/events/amd/uncore.o
> arch/x86/events/amd/uncore.c: In function ‘amd_uncore_umc_ctx_init’:
> arch/x86/events/amd/uncore.c:951:52: warning: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size 8 [-Wformat-truncation=]
>     snprintf(pmu->name, sizeof(pmu->name), "amd_umc_%d", index);
>                                                     ^~
> arch/x86/events/amd/uncore.c:951:43: note: directive argument in the range [0, 2147483647]
>     snprintf(pmu->name, sizeof(pmu->name), "amd_umc_%d", index);
>                                            ^~~~~~~~~~~~
> arch/x86/events/amd/uncore.c:951:4: note: ‘snprintf’ output between 10 and 19 bytes into a destination of size 16
>     snprintf(pmu->name, sizeof(pmu->name), "amd_umc_%d", index);
>     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> As far as I can see, there can't be more than UNCORE_GROUP_MAX (256)
> groups and each group can't have more than 255 PMU, so the number
> printed by this %d can't exceed 65279, that's only 5 digits and would
> fit into the buffer. So it's a false positive warning. But we can
> make the compiler happy by declaring index as a 16-bit number.
> 
> Signed-off-by: Jean Delvare <jdelvare@suse.de>
> ---
> Changes in v2:
>  * Use the proper printf conversion specifier, to be on the safe side.
> 
> An alternative fix would be to extend UNCORE_NAME_LEN to 20, the
> downside being an increased memory consumption. Depends whether we
> expect UNCORE_GROUP_MAX to ever be increased, or groups to ever
> support more than 255 PMU.
> 

Its very unlikely for UNCORE_GROUP_MAX to change and the current
solution looks good to me.

Reviewed-by: Sandipan Das <sandipan.das@amd.com>


  reply	other threads:[~2024-11-05  9:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-05  8:52 Jean Delvare
2024-11-05  9:34 ` Sandipan Das [this message]
2024-11-11 10:58 ` [tip: perf/core] " tip-bot2 for Jean Delvare

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=5907e4cf-d71f-4c5e-8504-a0177819ebb0@amd.com \
    --to=sandipan.das@amd.com \
    --cc=jdelvare@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    /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®