drivers/net/dsa/lantiq_gswip.c:907:44: warning: '%d' directive output may be truncated writing between 1 and 10 bytes into a region of size 6

From: kernel test robot
Date: Wed Nov 29 2023 - 16:37:01 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 3b47bc037bd44f142ac09848e8d3ecccc726be99
commit: 14fceff4771e51b23b4485b575cf9e5b3414b89b net: dsa: Add Lantiq / Intel DSA driver for vrx200
date: 5 years ago
config: x86_64-randconfig-r015-20230905 (https://download.01.org/0day-ci/archive/20231130/202311300155.M0VzROAp-lkp@xxxxxxxxx/config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231130/202311300155.M0VzROAp-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/202311300155.M0VzROAp-lkp@xxxxxxxxx/

All warnings (new ones prefixed by >>):

drivers/net/dsa/lantiq_gswip.c: In function 'gswip_probe':
>> drivers/net/dsa/lantiq_gswip.c:907:44: warning: '%d' directive output may be truncated writing between 1 and 10 bytes into a region of size 6 [-Wformat-truncation=]
snprintf(gphyname, sizeof(gphyname), "gphy%d", i);
^~
drivers/net/dsa/lantiq_gswip.c:907:39: note: directive argument in the range [0, 2147483647]
snprintf(gphyname, sizeof(gphyname), "gphy%d", i);
^~~~~~~~
drivers/net/dsa/lantiq_gswip.c:907:2: note: 'snprintf' output between 6 and 15 bytes into a destination of size 10
snprintf(gphyname, sizeof(gphyname), "gphy%d", i);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +907 drivers/net/dsa/lantiq_gswip.c

897
898 static int gswip_gphy_fw_probe(struct gswip_priv *priv,
899 struct gswip_gphy_fw *gphy_fw,
900 struct device_node *gphy_fw_np, int i)
901 {
902 struct device *dev = priv->dev;
903 u32 gphy_mode;
904 int ret;
905 char gphyname[10];
906
> 907 snprintf(gphyname, sizeof(gphyname), "gphy%d", i);
908
909 gphy_fw->clk_gate = devm_clk_get(dev, gphyname);
910 if (IS_ERR(gphy_fw->clk_gate)) {
911 dev_err(dev, "Failed to lookup gate clock\n");
912 return PTR_ERR(gphy_fw->clk_gate);
913 }
914
915 ret = of_property_read_u32(gphy_fw_np, "reg", &gphy_fw->fw_addr_offset);
916 if (ret)
917 return ret;
918
919 ret = of_property_read_u32(gphy_fw_np, "lantiq,gphy-mode", &gphy_mode);
920 /* Default to GE mode */
921 if (ret)
922 gphy_mode = GPHY_MODE_GE;
923
924 switch (gphy_mode) {
925 case GPHY_MODE_FE:
926 gphy_fw->fw_name = priv->gphy_fw_name_cfg->fe_firmware_name;
927 break;
928 case GPHY_MODE_GE:
929 gphy_fw->fw_name = priv->gphy_fw_name_cfg->ge_firmware_name;
930 break;
931 default:
932 dev_err(dev, "Unknown GPHY mode %d\n", gphy_mode);
933 return -EINVAL;
934 }
935
936 gphy_fw->reset = of_reset_control_array_get_exclusive(gphy_fw_np);
937 if (IS_ERR(priv->gphy_fw)) {
938 if (PTR_ERR(priv->gphy_fw) != -EPROBE_DEFER)
939 dev_err(dev, "Failed to lookup gphy reset\n");
940 return PTR_ERR(priv->gphy_fw);
941 }
942
943 return gswip_gphy_fw_load(priv, gphy_fw);
944 }
945

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