drivers/net/ethernet/marvell/prestera/prestera_devlink.c:20:43: warning: '%d' directive output may be truncated writing between 1 and 5 bytes into a region of size between 4 and 12

From: kernel test robot
Date: Fri Jan 10 2025 - 18:02:53 EST


Hi Vadym,

FYI, the error/warning still remains.

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: e0daef7de1acecdb64c1fa31abc06529abb98710
commit: 34dd1710f5a3c9a7dc78e1ff6de69a19d407db25 net: marvell: prestera: Add basic devlink support
date: 4 years, 4 months ago
config: powerpc64-randconfig-002-20231105 (https://download.01.org/0day-ci/archive/20250111/202501110646.aGxZ97Ug-lkp@xxxxxxxxx/config)
compiler: powerpc64-linux-gcc (GCC) 12.4.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250111/202501110646.aGxZ97Ug-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/202501110646.aGxZ97Ug-lkp@xxxxxxxxx/

All warnings (new ones prefixed by >>):

drivers/net/ethernet/marvell/prestera/prestera_devlink.c: In function 'prestera_dl_info_get':
>> drivers/net/ethernet/marvell/prestera/prestera_devlink.c:20:43: warning: '%d' directive output may be truncated writing between 1 and 5 bytes into a region of size between 4 and 12 [-Wformat-truncation=]
20 | snprintf(buf, sizeof(buf), "%d.%d.%d",
| ^~
drivers/net/ethernet/marvell/prestera/prestera_devlink.c:20:36: note: directive argument in the range [0, 65535]
20 | snprintf(buf, sizeof(buf), "%d.%d.%d",
| ^~~~~~~~~~
drivers/net/ethernet/marvell/prestera/prestera_devlink.c:20:9: note: 'snprintf' output between 6 and 18 bytes into a destination of size 16
20 | snprintf(buf, sizeof(buf), "%d.%d.%d",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 | sw->dev->fw_rev.maj,
| ~~~~~~~~~~~~~~~~~~~~
22 | sw->dev->fw_rev.min,
| ~~~~~~~~~~~~~~~~~~~~
23 | sw->dev->fw_rev.sub);
| ~~~~~~~~~~~~~~~~~~~~

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for HOTPLUG_PCI_POWERNV
Depends on [n]: PCI [=y] && HOTPLUG_PCI [=n] && PPC_POWERNV [=y] && EEH [=y]
Selected by [y]:
- OCXL [=y] && PPC_POWERNV [=y] && PCI [=y] && EEH [=y]


vim +20 drivers/net/ethernet/marvell/prestera/prestera_devlink.c

7
8 static int prestera_dl_info_get(struct devlink *dl,
9 struct devlink_info_req *req,
10 struct netlink_ext_ack *extack)
11 {
12 struct prestera_switch *sw = devlink_priv(dl);
13 char buf[16];
14 int err;
15
16 err = devlink_info_driver_name_put(req, PRESTERA_DRV_NAME);
17 if (err)
18 return err;
19
> 20 snprintf(buf, sizeof(buf), "%d.%d.%d",
21 sw->dev->fw_rev.maj,
22 sw->dev->fw_rev.min,
23 sw->dev->fw_rev.sub);
24
25 return devlink_info_version_running_put(req,
26 DEVLINK_INFO_VERSION_GENERIC_FW,
27 buf);
28 }
29

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