diff mbox series

[net-next,1/4] mlxsw: spectrum: Avoid -Wformat-truncation warnings

Message ID 20190222040929.16657-2-f.fainelli@gmail.com
State Accepted
Delegated to: David Miller
Headers show
Series -Wformat fixes | expand

Commit Message

Florian Fainelli Feb. 22, 2019, 4:09 a.m. UTC
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>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Ido Schimmel Feb. 22, 2019, 1:25 p.m. UTC | #1
On Thu, Feb 21, 2019 at 08:09:26PM -0800, Florian Fainelli wrote:
> 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>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index f018b0607dac..5f6962da8877 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -2129,7 +2129,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;
 	}
@@ -2140,7 +2140,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;
 	}