* [PATCH] tty: serial: samsung_tty: fix -Wformat-overflow warnings for clk_name
@ 2026-11-21 19:21 Bramuel Barack
2026-11-21 19:26 ` sashiko-bot
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Bramuel Barack @ 2026-11-21 19:21 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, Krzysztof Kozlowski,
Peter Griffin
Cc: Alim Akhtar, linux-serial, linux-samsung-soc, linux-arm-kernel,
linux-kernel, Bramuel Barack
MAX_CLK_NAME_LENGTH is currently 15, which only leaves room for a
single-digit index after the 13-character "clk_uart_baud" prefix and
terminating NUL byte. Because the clock indices (cnt, clk_num, clk_sel)
are u8 values (0-255), building with W=1 triggers -Werror=format-overflow
warnings at the sprintf() call sites.
Increase MAX_CLK_NAME_LENGTH to 17 to accommodate the full u8 range and
replace the three sprintf() calls with snprintf().
Signed-off-by: Bramuel Barack <bramwelbarack89@gmail.com>
---
drivers/tty/serial/samsung_tty.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c
index 640f85e2d636..40a21e6825b8 100644
--- a/drivers/tty/serial/samsung_tty.c
+++ b/drivers/tty/serial/samsung_tty.c
@@ -1336,7 +1336,7 @@ static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level,
*
*/
-#define MAX_CLK_NAME_LENGTH 15
+#define MAX_CLK_NAME_LENGTH 17
static inline u8 s3c24xx_serial_getsource(struct uart_port *port)
{
@@ -1386,7 +1386,7 @@ static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport,
!(ourport->cfg->clk_sel & (1 << cnt)))
continue;
- sprintf(clkname, "clk_uart_baud%d", cnt);
+ snprintf(clkname, sizeof(clkname), "clk_uart_baud%u", cnt);
clk = clk_get(ourport->port.dev, clkname);
if (IS_ERR(clk))
continue;
@@ -1778,7 +1778,7 @@ static int s3c24xx_serial_enable_baudclk(struct s3c24xx_uart_port *ourport)
if (!(clk_sel & (1 << clk_num)))
continue;
- sprintf(clk_name, "clk_uart_baud%d", clk_num);
+ snprintf(clk_name, sizeof(clk_name), "clk_uart_baud%u", clk_num);
clk = clk_get(dev, clk_name);
if (IS_ERR(clk))
continue;
@@ -2326,7 +2326,7 @@ s3c24xx_serial_get_options(struct uart_port *port, int *baud,
/* now calculate the baud rate */
clk_sel = s3c24xx_serial_getsource(port);
- sprintf(clk_name, "clk_uart_baud%d", clk_sel);
+ snprintf(clk_name, sizeof(clk_name), "clk_uart_baud%u", clk_sel);
clk = clk_get(port->dev, clk_name);
if (!IS_ERR(clk))
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] tty: serial: samsung_tty: fix -Wformat-overflow warnings for clk_name
2026-11-21 19:21 [PATCH] tty: serial: samsung_tty: fix -Wformat-overflow warnings for clk_name Bramuel Barack
@ 2026-11-21 19:26 ` sashiko-bot
2026-11-22 4:37 ` kernel test robot
2026-11-22 14:13 ` Krzysztof Kozlowski
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-21 19:26 UTC (permalink / raw)
To: Bramuel Barack; +Cc: linux-serial
> MAX_CLK_NAME_LENGTH is currently 15, which only leaves room for a
> single-digit index after the 13-character "clk_uart_baud" prefix and
> terminating NUL byte. Because the clock indices (cnt, clk_num, clk_sel)
> are u8 values (0-255), building with W=1 triggers -Werror=format-overflow
> warnings at the sprintf() call sites.
>
> Increase MAX_CLK_NAME_LENGTH to 17 to accommodate the full u8 range and
> replace the three sprintf() calls with snprintf().
>
> Signed-off-by: Bramuel Barack <bramwelbarack89@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261121192158.44872-1-bramwelbarack89@gmail.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tty: serial: samsung_tty: fix -Wformat-overflow warnings for clk_name
2026-11-21 19:21 [PATCH] tty: serial: samsung_tty: fix -Wformat-overflow warnings for clk_name Bramuel Barack
2026-11-21 19:26 ` sashiko-bot
@ 2026-11-22 4:37 ` kernel test robot
2026-11-22 14:13 ` Krzysztof Kozlowski
2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-11-22 4:37 UTC (permalink / raw)
To: Bramuel Barack, Greg Kroah-Hartman, Jiri Slaby,
Krzysztof Kozlowski, Peter Griffin
Cc: oe-kbuild-all, Alim Akhtar, linux-serial, linux-samsung-soc,
linux-arm-kernel, linux-kernel, Bramuel Barack
Hi Bramuel,
kernel test robot noticed the following build warnings:
[auto build test WARNING on krzk/for-next]
[also build test WARNING on tty/tty-testing tty/tty-next tty/tty-linus usb/usb-testing usb/usb-next usb/usb-linus linus/master v7.4-rc3 next-20261120]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Bramuel-Barack/tty-serial-samsung_tty-fix-Wformat-overflow-warnings-for-clk_name/20261121-222158
base: https://git.kernel.org/pub/scm/linux/kernel/git/krzk/linux.git for-next
patch link: https://lore.kernel.org/r/20261121192158.44872-1-bramwelbarack89%40gmail.com
patch subject: [PATCH] tty: serial: samsung_tty: fix -Wformat-overflow warnings for clk_name
config: parisc-randconfig-1000-20261122 (https://download.01.org/0day-ci/archive/20261122/202611221200.BFeU1ULS-lkp@intel.com/config)
compiler: hppa-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261122/202611221200.BFeU1ULS-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/202611221200.BFeU1ULS-lkp@intel.com/
All warnings (new ones prefixed by >>):
drivers/tty/serial/samsung_tty.c: In function 's3c24xx_serial_set_termios':
>> drivers/tty/serial/samsung_tty.c:1389:52: warning: '%u' directive output may be truncated writing between 1 and 10 bytes into a region of size 4 [-Wformat-truncation=]
snprintf(clkname, sizeof(clkname), "clk_uart_baud%u", cnt);
^~
drivers/tty/serial/samsung_tty.c:1389:38: note: directive argument in the range [0, 2147483647]
snprintf(clkname, sizeof(clkname), "clk_uart_baud%u", cnt);
^~~~~~~~~~~~~~~~~
drivers/tty/serial/samsung_tty.c:1389:3: note: 'snprintf' output between 15 and 24 bytes into a destination of size 17
snprintf(clkname, sizeof(clkname), "clk_uart_baud%u", cnt);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/tty/serial/samsung_tty.c: In function 's3c24xx_serial_probe':
drivers/tty/serial/samsung_tty.c:1781:54: warning: '%u' directive output may be truncated writing between 1 and 10 bytes into a region of size 4 [-Wformat-truncation=]
snprintf(clk_name, sizeof(clk_name), "clk_uart_baud%u", clk_num);
^~
drivers/tty/serial/samsung_tty.c:1781:40: note: directive argument in the range [0, 2147483647]
snprintf(clk_name, sizeof(clk_name), "clk_uart_baud%u", clk_num);
^~~~~~~~~~~~~~~~~
drivers/tty/serial/samsung_tty.c:1781:3: note: 'snprintf' output between 15 and 24 bytes into a destination of size 17
snprintf(clk_name, sizeof(clk_name), "clk_uart_baud%u", clk_num);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +1389 drivers/tty/serial/samsung_tty.c
1370
1371 static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport,
1372 unsigned int req_baud, struct clk **best_clk,
1373 u8 *clk_num)
1374 {
1375 const struct s3c24xx_uart_info *info = ourport->info;
1376 struct clk *clk;
1377 unsigned long rate;
1378 unsigned int baud, quot, best_quot = 0;
1379 char clkname[MAX_CLK_NAME_LENGTH];
1380 int calc_deviation, deviation = (1 << 30) - 1;
1381 u8 cnt;
1382
1383 for (cnt = 0; cnt < info->num_clks; cnt++) {
1384 /* Keep selected clock if provided */
1385 if (ourport->cfg->clk_sel &&
1386 !(ourport->cfg->clk_sel & (1 << cnt)))
1387 continue;
1388
> 1389 snprintf(clkname, sizeof(clkname), "clk_uart_baud%u", cnt);
1390 clk = clk_get(ourport->port.dev, clkname);
1391 if (IS_ERR(clk))
1392 continue;
1393
1394 rate = clk_get_rate(clk);
1395 if (!rate) {
1396 dev_err(ourport->port.dev,
1397 "Failed to get clock rate for %s.\n", clkname);
1398 clk_put(clk);
1399 continue;
1400 }
1401
1402 if (ourport->info->has_divslot) {
1403 unsigned long div = rate / req_baud;
1404
1405 /* The UDIVSLOT register on the newer UARTs allows us to
1406 * get a divisor adjustment of 1/16th on the baud clock.
1407 *
1408 * We don't keep the UDIVSLOT value (the 16ths we
1409 * calculated by not multiplying the baud by 16) as it
1410 * is easy enough to recalculate.
1411 */
1412
1413 quot = div / 16;
1414 baud = rate / div;
1415 } else {
1416 quot = (rate + (8 * req_baud)) / (16 * req_baud);
1417 baud = rate / (quot * 16);
1418 }
1419 quot--;
1420
1421 calc_deviation = abs(req_baud - baud);
1422
1423 if (calc_deviation < deviation) {
1424 /*
1425 * If we find a better clk, release the previous one, if
1426 * any.
1427 */
1428 if (!IS_ERR(*best_clk))
1429 clk_put(*best_clk);
1430 *best_clk = clk;
1431 best_quot = quot;
1432 *clk_num = cnt;
1433 deviation = calc_deviation;
1434 } else {
1435 clk_put(clk);
1436 }
1437 }
1438
1439 return best_quot;
1440 }
1441
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tty: serial: samsung_tty: fix -Wformat-overflow warnings for clk_name
2026-11-21 19:21 [PATCH] tty: serial: samsung_tty: fix -Wformat-overflow warnings for clk_name Bramuel Barack
2026-11-21 19:26 ` sashiko-bot
2026-11-22 4:37 ` kernel test robot
@ 2026-11-22 14:13 ` Krzysztof Kozlowski
2 siblings, 0 replies; 4+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-22 14:13 UTC (permalink / raw)
To: Bramuel Barack, Greg Kroah-Hartman, Jiri Slaby, Peter Griffin
Cc: Alim Akhtar, linux-serial, linux-samsung-soc, linux-arm-kernel,
linux-kernel
On 21/11/2026 20:21, Bramuel Barack wrote:
> MAX_CLK_NAME_LENGTH is currently 15, which only leaves room for a
> single-digit index after the 13-character "clk_uart_baud" prefix and
> terminating NUL byte. Because the clock indices (cnt, clk_num, clk_sel)
> are u8 values (0-255), building with W=1 triggers -Werror=format-overflow
They are not 0-255.
https://lore.kernel.org/all/20240605040719.160778-1-k.son@samsung.com/
> warnings at the sprintf() call sites.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-22 14:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 19:21 [PATCH] tty: serial: samsung_tty: fix -Wformat-overflow warnings for clk_name Bramuel Barack
2026-11-21 19:26 ` sashiko-bot
2026-11-22 4:37 ` kernel test robot
2026-11-22 14:13 ` Krzysztof Kozlowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox