From: Nathan Chancellor <nathan@kernel.org>
To: Arnd Bergmann <arnd@kernel.org>
Cc: llvm@lists.linux.dev, "Hans de Goede" <hdegoede@redhat.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Maximilian Luz" <luzmaximilian@gmail.com>,
"Arnd Bergmann" <arnd@arndb.de>,
"Nick Desaulniers" <ndesaulniers@google.com>,
"Bill Wendling" <morbo@google.com>,
"Justin Stitt" <justinstitt@google.com>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Andy Shevchenko" <andy.shevchenko@gmail.com>,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 5/9] surface3_power: avoid format string truncation warning
Date: Tue, 26 Mar 2024 16:05:11 -0700 [thread overview]
Message-ID: <20240326230511.GA2796782@dev-arch.thelio-3990X> (raw)
In-Reply-To: <20240326223825.4084412-6-arnd@kernel.org>
On Tue, Mar 26, 2024 at 11:38:04PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> clang warns about printing a pair of escaped strings into a buffer that is
> too short:
>
> drivers/platform/surface/surface3_power.c:248:3: error: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 12 [-Werror,-Wformat-truncation-non-kprintf]
> 248 | snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%6pE", buf + 7, buf);
> | ^
>
> Change the format string two print two less bytes so it always fits. The string
> is still truncated, so there is no change in behavior, but the compiler no
> longer warns about it.
>
> Fixes: 85f7582cd484 ("platform/surface: Move Surface 3 Power OpRegion driver to platform/surface")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> Not entirely sure about this one, as I've never used escaped strings, and
> don't know if gcc is correct to warn here, or if the kernel defines it
> differently from the standard.
As far as I understand it, this is a false positive because clang does
not understand the kernel's %p extensions. GCC does not warn for
overflow or truncation when %p is involved but the clang developers
chose to intentionally deviate from GCC in that aspect while sticking it
under a separate diagnostic that we could disable. I sent a patch that
did so some time ago but I guess Masahiro never applied it...
https://lore.kernel.org/20231002-disable-wformat-truncation-overflow-non-kprintf-v1-1-35179205c8d9@kernel.org/
Consider dropping the changes that fix non-kprintf warnings and
including that patch as part of this series.
> ---
> drivers/platform/surface/surface3_power.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/platform/surface/surface3_power.c b/drivers/platform/surface/surface3_power.c
> index 4c0f92562a79..72f904761fde 100644
> --- a/drivers/platform/surface/surface3_power.c
> +++ b/drivers/platform/surface/surface3_power.c
> @@ -245,7 +245,7 @@ static int mshw0011_bix(struct mshw0011_data *cdata, struct bix *bix)
> dev_err(&client->dev, "Error reading serial no: %d\n", ret);
> return ret;
> } else {
> - snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%6pE", buf + 7, buf);
> + snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%4pE", buf + 7, buf);
> }
>
> /* get cycle count */
> --
> 2.39.2
>
next prev parent reply other threads:[~2024-03-26 23:05 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-26 22:37 [PATCH 0/9] enabled -Wformat-truncation for clang Arnd Bergmann
2024-03-26 22:38 ` [PATCH 1/9] fbdev: shmobile: fix snprintf truncation Arnd Bergmann
2024-03-26 22:42 ` Laurent Pinchart
2024-03-27 8:13 ` Helge Deller
2024-03-26 22:38 ` [PATCH 2/9] enetc: avoid truncating error message Arnd Bergmann
2024-03-26 22:38 ` [PATCH 3/9] qed: avoid truncating work queue length Arnd Bergmann
2024-03-27 14:04 ` [EXTERNAL] " Subbaraya Sundeep Bhatta
2024-03-27 15:34 ` Arnd Bergmann
2024-03-27 17:08 ` Subbaraya Sundeep Bhatta
2024-03-26 22:38 ` [PATCH 4/9] mlx5: avoid truncating error message Arnd Bergmann
2024-03-27 14:08 ` [EXTERNAL] " Subbaraya Sundeep Bhatta
2024-03-26 22:38 ` [PATCH 5/9] surface3_power: avoid format string truncation warning Arnd Bergmann
2024-03-26 23:05 ` Nathan Chancellor [this message]
2024-03-27 10:58 ` Andy Shevchenko
2024-04-01 6:24 ` Uwe Kleine-König
2024-03-26 22:38 ` [PATCH 6/9] Input: IMS: fix printf string overflow Arnd Bergmann
2024-03-28 20:29 ` Dmitry Torokhov
2024-03-26 22:38 ` [PATCH 7/9] scsi: mylex: fix sysfs buffer lengths Arnd Bergmann
2024-03-27 7:40 ` Hannes Reinecke
2024-03-26 22:38 ` [PATCH 8/9] ALSA: aoa: avoid false-positive format truncation warning Arnd Bergmann
2024-03-27 9:54 ` Takashi Iwai
2024-03-26 22:38 ` [PATCH 9/9] kbuild: enable -Wformat-truncation on clang Arnd Bergmann
2024-03-27 0:47 ` [PATCH 0/9] enabled -Wformat-truncation for clang Jakub Kicinski
2024-03-29 19:30 ` patchwork-bot+netdevbpf
2024-04-02 1:48 ` (subset) " Martin K. Petersen
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=20240326230511.GA2796782@dev-arch.thelio-3990X \
--to=nathan@kernel.org \
--cc=andy.shevchenko@gmail.com \
--cc=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=justinstitt@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=luzmaximilian@gmail.com \
--cc=morbo@google.com \
--cc=ndesaulniers@google.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=u.kleine-koenig@pengutronix.de \
/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