mlxsw: spectrum: Avoid -Wformat-truncation warnings
authorFlorian Fainelli <f.fainelli@gmail.com>
Fri, 22 Feb 2019 04:09:26 +0000 (20:09 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 5 Apr 2019 20:29:09 +0000 (22:29 +0200)
[ Upstream commit ab2c4e2581ad32c28627235ff0ae8c5a5ea6899f ]

Give precision identifiers to the two snprintf() formatting the priority
and TC strings to avoid producing these two warnings:

drivers/net/ethernet/mellanox/mlxsw/spectrum.c: In function
'mlxsw_sp_port_get_prio_strings':
drivers/net/ethernet/mellanox/mlxsw/spectrum.c:2132:37: warning: '%d'
directive output may be truncated writing between 1 and 3 bytes into a
region of size between 0 and 31 [-Wformat-truncation=]
   snprintf(*p, ETH_GSTRING_LEN, "%s_%d",
                                     ^~
drivers/net/ethernet/mellanox/mlxsw/spectrum.c:2132:3: note: 'snprintf'
output between 3 and 36 bytes into a destination of size 32
   snprintf(*p, ETH_GSTRING_LEN, "%s_%d",
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     mlxsw_sp_port_hw_prio_stats[i].str, prio);
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlxsw/spectrum.c: In function
'mlxsw_sp_port_get_tc_strings':
drivers/net/ethernet/mellanox/mlxsw/spectrum.c:2143:37: warning: '%d'
directive output may be truncated writing between 1 and 11 bytes into a
region of size between 0 and 31 [-Wformat-truncation=]
   snprintf(*p, ETH_GSTRING_LEN, "%s_%d",
                                     ^~
drivers/net/ethernet/mellanox/mlxsw/spectrum.c:2143:3: note: 'snprintf'
output between 3 and 44 bytes into a destination of size 32
   snprintf(*p, ETH_GSTRING_LEN, "%s_%d",
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     mlxsw_sp_port_hw_tc_stats[i].str, tc);
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/mellanox/mlxsw/spectrum.c

index 22a5916e477e8baa798e283fe23854ffe0bb5300..cc847e0cac2d0971d9f22947cdf46b2aa3dbd8ad 100644 (file)
@@ -1565,7 +1565,7 @@ static void mlxsw_sp_port_get_prio_strings(u8 **p, int prio)
        int i;
 
        for (i = 0; i < MLXSW_SP_PORT_HW_PRIO_STATS_LEN; i++) {
-               snprintf(*p, ETH_GSTRING_LEN, "%s_%d",
+               snprintf(*p, ETH_GSTRING_LEN, "%.29s_%.1d",
                         mlxsw_sp_port_hw_prio_stats[i].str, prio);
                *p += ETH_GSTRING_LEN;
        }
@@ -1576,7 +1576,7 @@ static void mlxsw_sp_port_get_tc_strings(u8 **p, int tc)
        int i;
 
        for (i = 0; i < MLXSW_SP_PORT_HW_TC_STATS_LEN; i++) {
-               snprintf(*p, ETH_GSTRING_LEN, "%s_%d",
+               snprintf(*p, ETH_GSTRING_LEN, "%.29s_%.1d",
                         mlxsw_sp_port_hw_tc_stats[i].str, tc);
                *p += ETH_GSTRING_LEN;
        }