2024-01-11 12:31:03

by kernel test robot

[permalink] [raw]
Subject: include/linux/printk.h:434:44: warning: '%s' directive argument is null

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: de927f6c0b07d9e698416c5b287c521b07694cac
commit: 337015573718b161891a3473d25f59273f2e626b printk: Userspace format indexing support
date: 2 years, 6 months ago
config: x86_64-randconfig-002-20240105 (https://download.01.org/0day-ci/archive/20240111/[email protected]/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240111/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

In file included from include/linux/kernel.h:19,
from arch/x86/include/asm/percpu.h:27,
from arch/x86/include/asm/current.h:6,
from include/linux/sched.h:12,
from include/linux/blkdev.h:5,
from drivers/scsi/scsi_devinfo.c:3:
drivers/scsi/scsi_devinfo.c: In function 'scsi_dev_info_list_add_str':
>> include/linux/printk.h:434:44: warning: '%s' directive argument is null [-Wformat-overflow=]
434 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
| ^
include/linux/printk.h:430:3: note: in definition of macro 'printk_index_wrap'
430 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~~~~
drivers/scsi/scsi_devinfo.c:551:4: note: in expansion of macro 'printk'
551 | printk(KERN_ERR "%s: bad dev info string '%s' '%s'"
| ^~~~~~
drivers/scsi/scsi_devinfo.c:552:14: note: format string is defined here
552 | " '%s'\n", __func__, vendor, model,
| ^~


vim +434 include/linux/printk.h

406
407 /*
408 * Some subsystems have their own custom printk that applies a va_format to a
409 * generic format, for example, to include a device number or other metadata
410 * alongside the format supplied by the caller.
411 *
412 * In order to store these in the way they would be emitted by the printk
413 * infrastructure, the subsystem provides us with the start, fixed string, and
414 * any subsequent text in the format string.
415 *
416 * We take a variable argument list as pr_fmt/dev_fmt/etc are sometimes passed
417 * as multiple arguments (eg: `"%s: ", "blah"`), and we must only take the
418 * first one.
419 *
420 * subsys_fmt_prefix must be known at compile time, or compilation will fail
421 * (since this is a mistake). If fmt or level is not known at compile time, no
422 * index entry will be made (since this can legitimately happen).
423 */
424 #define printk_index_subsys_emit(subsys_fmt_prefix, level, fmt, ...) \
425 __printk_index_emit(fmt, level, subsys_fmt_prefix)
426
427 #define printk_index_wrap(_p_func, _fmt, ...) \
428 ({ \
429 __printk_index_emit(_fmt, NULL, NULL); \
430 _p_func(_fmt, ##__VA_ARGS__); \
431 })
432
433
> 434 #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
435 #define printk_deferred(fmt, ...) \
436 printk_index_wrap(_printk_deferred, fmt, ##__VA_ARGS__)
437

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


2024-01-11 16:28:01

by Petr Mladek

[permalink] [raw]
Subject: Re: include/linux/printk.h:434:44: warning: '%s' directive argument is null

On Thu 2024-01-11 20:29:05, kernel test robot wrote:
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: de927f6c0b07d9e698416c5b287c521b07694cac
> commit: 337015573718b161891a3473d25f59273f2e626b printk: Userspace format indexing support
> date: 2 years, 6 months ago
> config: x86_64-randconfig-002-20240105 (https://download.01.org/0day-ci/archive/20240111/[email protected]/config)
> compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240111/[email protected]/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 <[email protected]>
> | Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
>
> All warnings (new ones prefixed by >>):
>
> In file included from include/linux/kernel.h:19,
> from arch/x86/include/asm/percpu.h:27,
> from arch/x86/include/asm/current.h:6,
> from include/linux/sched.h:12,
> from include/linux/blkdev.h:5,
> from drivers/scsi/scsi_devinfo.c:3:
> drivers/scsi/scsi_devinfo.c: In function 'scsi_dev_info_list_add_str':
> >> include/linux/printk.h:434:44: warning: '%s' directive argument is null [-Wformat-overflow=]
> 434 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
> | ^
> include/linux/printk.h:430:3: note: in definition of macro 'printk_index_wrap'
> 430 | _p_func(_fmt, ##__VA_ARGS__); \
> | ^~~~~~~
> drivers/scsi/scsi_devinfo.c:551:4: note: in expansion of macro 'printk'
> 551 | printk(KERN_ERR "%s: bad dev info string '%s' '%s'"
> | ^~~~~~
> drivers/scsi/scsi_devinfo.c:552:14: note: format string is defined here
> 552 | " '%s'\n", __func__, vendor, model,
> | ^~

This should get fixed by
https://lore.kernel.org/all/[email protected]/

Best Regards,
Petr