From: David Laight <David.Laight@ACULAB.COM>
To: 'Hugo Villeneuve' <hugo@hugovil.com>, kernel test robot <lkp@intel.com>
Cc: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"jirislaby@kernel.org" <jirislaby@kernel.org>,
"hvilleneuve@dimonoff.com" <hvilleneuve@dimonoff.com>,
"oe-kbuild-all@lists.linux.dev" <oe-kbuild-all@lists.linux.dev>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-serial@vger.kernel.org" <linux-serial@vger.kernel.org>,
"stable@vger.kernel.org" <stable@vger.kernel.org>,
Andy Shevchenko <andy.shevchenko@gmail.com>
Subject: RE: [PATCH 1/7] serial: sc16is7xx: fix snprintf format specifier in sc16is7xx_regmap_name()
Date: Thu, 7 Dec 2023 19:45:55 +0000 [thread overview]
Message-ID: <16093ec23ca34085824987456eac8f2a@AcuMS.aculab.com> (raw)
In-Reply-To: <20231207125243.c056d5cd0f875ea6dfdfa194@hugovil.com>
From: Hugo Villeneuve
> Sent: 07 December 2023 17:53
...
> > kernel test robot noticed the following build warnings:
> >
> > [auto build test WARNING on d804987153e7bedf503f8e4ba649afe52cfd7f6d]
> >
> > url: https://github.com/intel-lab-lkp/linux/commits/Hugo-Villeneuve/serial-sc16is7xx-fix-
> snprintf-format-specifier-in-sc16is7xx_regmap_name/20231201-031413
> > base: d804987153e7bedf503f8e4ba649afe52cfd7f6d
> > patch link: https://lore.kernel.org/r/20231130191050.3165862-2-hugo%40hugovil.com
> > patch subject: [PATCH 1/7] serial: sc16is7xx: fix snprintf format specifier in
> sc16is7xx_regmap_name()
> > config: x86_64-buildonly-randconfig-001-20231201 (https://download.01.org/0day-
> ci/archive/20231206/202312061443.Cknef7Uq-lkp@intel.com/config)
> > compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
> > reproduce (this is a W=1 build): (https://download.01.org/0day-
> ci/archive/20231206/202312061443.Cknef7Uq-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/202312061443.Cknef7Uq-lkp@intel.com/
> >
> > All warnings (new ones prefixed by >>):
> >
> > drivers/tty/serial/sc16is7xx.c: In function 'sc16is7xx_i2c_probe':
> > >> drivers/tty/serial/sc16is7xx.c:1703:41: warning: '%u' directive output may be truncated writing
> between 1 and 10 bytes into a region of size 2 [-Wformat-truncation=]
> > 1703 | snprintf(buf, sizeof(buf), "port%u", port_id);
> > | ^~
> > In function 'sc16is7xx_regmap_name',
> > inlined from 'sc16is7xx_i2c_probe' at drivers/tty/serial/sc16is7xx.c:1805:17:
> > drivers/tty/serial/sc16is7xx.c:1703:36: note: directive argument in the range [0, 4294967294]
> > 1703 | snprintf(buf, sizeof(buf), "port%u", port_id);
> > | ^~~~~~~~
> > drivers/tty/serial/sc16is7xx.c:1703:9: note: 'snprintf' output between 6 and 15 bytes into a
> destination of size 6
> > 1703 | snprintf(buf, sizeof(buf), "port%u", port_id);
> > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Hi,
> the only solution I could find is to add this line just before snprintf:
>
> BUG_ON(port_id > MAX310X_MAX_PORTS);
>
> it allows us to have the smallest buffer size possible.
Or "port%c", '0' + port_id);
Or maybe:
size_t buflen = sizeof (buf);
OPTIMIZER_HIDE_VAR(buflen);
snprintf(buf, buflen, fmt, args);
See https://godbolt.org/z/Wjz3xG5c4
Maybe there should be snprintf_may_truncate() (etc) in one of the headers.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2023-12-07 19:46 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-30 19:10 [PATCH 0/7] serial: sc16is7xx and max310x: regmap fixes and improvements Hugo Villeneuve
2023-11-30 19:10 ` [PATCH 1/7] serial: sc16is7xx: fix snprintf format specifier in sc16is7xx_regmap_name() Hugo Villeneuve
2023-12-06 6:29 ` kernel test robot
2023-12-07 17:52 ` Hugo Villeneuve
2023-12-07 18:24 ` Andy Shevchenko
2023-12-07 19:02 ` Hugo Villeneuve
2023-12-12 20:03 ` Hugo Villeneuve
2023-12-13 14:43 ` Andy Shevchenko
2023-12-07 19:45 ` David Laight [this message]
2023-12-07 1:44 ` Greg KH
2023-12-07 16:02 ` Hugo Villeneuve
2023-12-07 1:45 ` Greg KH
2023-12-07 16:05 ` Hugo Villeneuve
2023-11-30 19:10 ` [PATCH 2/7] serial: sc16is7xx: remove global regmap from struct sc16is7xx_port Hugo Villeneuve
2023-11-30 19:10 ` [PATCH 3/7] serial: sc16is7xx: remove unused line structure member Hugo Villeneuve
2023-11-30 19:10 ` [PATCH 4/7] serial: sc16is7xx: add macro for max number of UART ports Hugo Villeneuve
2023-11-30 19:10 ` [PATCH 5/7] serial: sc16is7xx: improve sc16is7xx_regmap_name() buffer size computation Hugo Villeneuve
2023-11-30 19:10 ` [PATCH 6/7] serial: max310x: add macro for max number of ports Hugo Villeneuve
2023-12-01 15:59 ` Jan Kundrát
2023-11-30 19:10 ` [PATCH 7/7] serial: max310x: use separate regmap name for each port Hugo Villeneuve
2023-12-01 16:00 ` Jan Kundrát
2023-12-06 14:22 ` kernel test robot
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=16093ec23ca34085824987456eac8f2a@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=andy.shevchenko@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=hugo@hugovil.com \
--cc=hvilleneuve@dimonoff.com \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=lkp@intel.com \
--cc=oe-kbuild-all@lists.linux.dev \
--cc=stable@vger.kernel.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