drivers/platform/mellanox/mlxreg-hotplug.c:87:54: warning: '%d' directive output may be truncated writing 1 byte into a region of size between 0 and 31

From: kernel test robot
Date: Sun Jan 07 2024 - 19:49:16 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 0dd3ee31125508cd67f7e7172247f05b7fd1753a
commit: 92d020f97966b1724cfcac93e89176d0eb3aca61 platform/mellanox: mlxreg-hotplug: Add environmental data to uevent
date: 3 years, 6 months ago
config: x86_64-randconfig-001-20240107 (https://download.01.org/0day-ci/archive/20240108/202401080811.VjYaZS68-lkp@xxxxxxxxx/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/20240108/202401080811.VjYaZS68-lkp@xxxxxxxxx/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@xxxxxxxxx>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401080811.VjYaZS68-lkp@xxxxxxxxx/

All warnings (new ones prefixed by >>):

In file included from include/linux/bits.h:23,
from include/linux/bitops.h:5,
from drivers/platform/mellanox/mlxreg-hotplug.c:8:
drivers/platform/mellanox/mlxreg-hotplug.c: In function 'mlxreg_hotplug_attr_init':
include/linux/bits.h:26:28: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
26 | __builtin_constant_p((l) > (h)), (l) > (h), 0)))
| ^
include/linux/build_bug.h:16:62: note: in definition of macro 'BUILD_BUG_ON_ZERO'
16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK'
39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
drivers/platform/mellanox/mlxreg-hotplug.c:214:17: note: in expansion of macro 'GENMASK'
214 | item->mask = GENMASK((regval & item->mask) - 1, 0);
| ^~~~~~~
include/linux/bits.h:26:40: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
26 | __builtin_constant_p((l) > (h)), (l) > (h), 0)))
| ^
include/linux/build_bug.h:16:62: note: in definition of macro 'BUILD_BUG_ON_ZERO'
16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
| ^
include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK'
39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
| ^~~~~~~~~~~~~~~~~~~
drivers/platform/mellanox/mlxreg-hotplug.c:214:17: note: in expansion of macro 'GENMASK'
214 | item->mask = GENMASK((regval & item->mask) - 1, 0);
| ^~~~~~~
drivers/platform/mellanox/mlxreg-hotplug.c: In function 'mlxreg_hotplug_udev_event_send':
>> drivers/platform/mellanox/mlxreg-hotplug.c:87:54: warning: '%d' directive output may be truncated writing 1 byte into a region of size between 0 and 31 [-Wformat-truncation=]
87 | snprintf(event_str, MLXREG_CORE_LABEL_MAX_SIZE, "%s=%d", label, !!action);
| ^~
drivers/platform/mellanox/mlxreg-hotplug.c:87:50: note: directive argument in the range [0, 1]
87 | snprintf(event_str, MLXREG_CORE_LABEL_MAX_SIZE, "%s=%d", label, !!action);
| ^~~~~~~
drivers/platform/mellanox/mlxreg-hotplug.c:87:2: note: 'snprintf' output between 3 and 34 bytes into a destination of size 32
87 | snprintf(event_str, MLXREG_CORE_LABEL_MAX_SIZE, "%s=%d", label, !!action);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +87 drivers/platform/mellanox/mlxreg-hotplug.c

77
78 static int
79 mlxreg_hotplug_udev_event_send(struct kobject *kobj,
80 struct mlxreg_core_data *data, bool action)
81 {
82 char event_str[MLXREG_CORE_LABEL_MAX_SIZE + 2];
83 char label[MLXREG_CORE_LABEL_MAX_SIZE] = { 0 };
84
85 mlxreg_hotplug_udev_envp[0] = event_str;
86 string_upper(label, data->label);
> 87 snprintf(event_str, MLXREG_CORE_LABEL_MAX_SIZE, "%s=%d", label, !!action);
88
89 return kobject_uevent_env(kobj, KOBJ_CHANGE, mlxreg_hotplug_udev_envp);
90 }
91

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