public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Nathan Chancellor <nathan@kernel.org>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>,
	Arnd Bergmann <arnd@arndb.de>, kernel test robot <lkp@intel.com>,
	Maximilian Luz <luzmaximilian@gmail.com>,
	llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev,
	linux-kernel@vger.kernel.org, Hans de Goede <hdegoede@redhat.com>
Subject: Re: drivers/platform/surface/surface3_power.c:243:2: warning: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 12
Date: Wed, 29 Jan 2025 22:16:14 +0000	[thread overview]
Message-ID: <20250129221614.6510f165@pumpkin> (raw)
In-Reply-To: <20250129134648.GA3884012@ax162>

On Wed, 29 Jan 2025 06:46:48 -0700
Nathan Chancellor <nathan@kernel.org> wrote:

> On Wed, Jan 29, 2025 at 02:45:38PM +0200, Andy Shevchenko wrote:
> > On Wed, Jan 29, 2025 at 10:09 AM kernel test robot <lkp@intel.com> wrote:  
> > >
> > > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> > > head:   05dbaf8dd8bf537d4b4eb3115ab42a5fb40ff1f5
> > > commit: 85f7582cd484dbf491b6d9bb2af6ef1467a024d2 platform/surface: Move Surface 3 Power OpRegion driver to platform/surface
> > > date:   4 years, 3 months ago
> > > config: x86_64-randconfig-071-20241231 (https://download.01.org/0day-ci/archive/20250129/202501291646.VtwF98qd-lkp@intel.com/config)
> > > compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
> > > reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250129/202501291646.VtwF98qd-lkp@intel.com/reproduce)
> > >
> > > If you fix the issue in a separate patch/commit (i.e. not just a new version of
> > > the same patch/commit), kindly add following tags
> > > | Reported-by: kernel test robot <lkp@intel.com>
> > > | Closes: https://lore.kernel.org/oe-kbuild-all/202501291646.VtwF98qd-lkp@intel.com/
> > >
> > > All warnings (new ones prefixed by >>):
> > >  
> > > >> drivers/platform/surface/surface3_power.c:243:2: warning: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 12 [-Wformat-truncation-non-kprintf]  
> > >      243 |         snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%6pE", buf + 7, buf);  
> > 
> > 3 + 'E' + 6 + 'E' + NUL, that's how the compiler thinks about this
> > formatting string...
> >   
> > >          |         ^
> > >    1 warning generated.  
> > 
> > I do not know how to properly address this because it's false positive
> > due to the compiler not being aware of pointer extensions used in
> > Linux kernel. The w/a is to increase the buffer if we can, but is it
> > practical? OTOH, this warning will be translated to a compilation
> > error in case of default WERROR settings on `make W=1` builds which is
> > also annoying to people what want have that clean.  
> 
> Hmmm, I missed that -Wformat-truncation-non-kprintf was only disabled in
> the non-W=1 block in scripts/Makefile.extrawarn. We never want to see
> these warnings at any level because they will almost always be a false
> positive, that's why the "non-kprintf" flags even exist in the first
> place:
...

There is a separate issue that it doesn't seem to be easy to mark a specific
snprintf() as one that will not actually overflow or where truncation is fine.

Persuading the compiler that the buffer size isn't constant currently works,
but I expect the compiler will start double checking against ARRAY_SIZE(buffer)
'any time soon' which will require the same treatment applied to the buffer
address.

	David

      reply	other threads:[~2025-01-29 22:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-29  8:08 drivers/platform/surface/surface3_power.c:243:2: warning: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 12 kernel test robot
2025-01-29 12:45 ` Andy Shevchenko
2025-01-29 12:50   ` Andy Shevchenko
2025-01-30  8:56     ` Geert Uytterhoeven
2025-01-30 16:50       ` Andy Shevchenko
2025-01-29 13:46   ` Nathan Chancellor
2025-01-29 22:16     ` David Laight [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=20250129221614.6510f165@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=arnd@arndb.de \
    --cc=hdegoede@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=llvm@lists.linux.dev \
    --cc=luzmaximilian@gmail.com \
    --cc=nathan@kernel.org \
    --cc=oe-kbuild-all@lists.linux.dev \
    /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