mlxsw: Fix -Wformat-truncation warnings
Subsystems (3)
Petr Machata
maintainercover mlxsw: Fix -Wformat-truncation warnings
Ido Schimmel writes:
Commit 6d4ab2e97dcf ("extrawarn: enable format and stringop overflow warnings in W=1") enabled format warnings as part of W=1 builds, resulting in two new warnings in mlxsw. Fix both and target at net-next as the warnings are not indicative of actual bugs.
Ido Schimmel (2):
mlxsw: core_thermal: Fix -Wformat-truncation warning
mlxsw: spectrum_ethtool: Fix -Wformat-truncation warning
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 2 +- drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.41.0
Petr Machata
maintainerPATCH 1/2 mlxsw: core_thermal: Fix -Wformat-truncation warning
From: Ido Schimmel <[email protected]>
The name of a thermal zone device cannot be longer than 19 characters ('THERMAL_NAME_LENGTH - 1'). The format string 'mlxsw-lc%d-gearbox%d' can exceed this limitation if the maximum number of line cards and the maximum number of gearboxes on each line card cannot be represented using a single digit.
This is not the case with current systems nor future ones. Therefore, increase the size of the result buffer beyond 'THERMAL_NAME_LENGTH' and suppress the following build warning [1].
If this limitation is ever exceeded, we will know about it since the thermal core validates the thermal device's name during registration.
[1]drivers/net/ethernet/mellanox/mlxsw/core_thermal.c: In function ‘mlxsw_thermal_gearboxes_init.constprop’:drivers/net/ethernet/mellanox/mlxsw/core_thermal.c:543:71: error: ‘%d’ directive output may be truncated writing between 1 and 3 bytes into a region of size between 1 and 3 [-Werror=format-truncation=]
543 | snprintf(tz_name, sizeof(tz_name), "mlxsw-lc%d-gearbox%d",
| ^~
In function ‘mlxsw_thermal_gearbox_tz_init’,
inlined from ‘mlxsw_thermal_gearboxes_init.constprop’ at drivers/net/ethernet/mellanox/mlxsw/core_thermal.c:611:9:drivers/net/ethernet/mellanox/mlxsw/core_thermal.c:543:52: note: directive argument in the range [1, 255]
543 | snprintf(tz_name, sizeof(tz_name), "mlxsw-lc%d-gearbox%d",
| ^~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c:543:17: note: ‘snprintf’ output between 19 and 23 bytes into a destination of size 20
543 | snprintf(tz_name, sizeof(tz_name), "mlxsw-lc%d-gearbox%d",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
544 | gearbox_tz->slot_index, gearbox_tz->module + 1);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--- drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +1 -1
@@ -536,7 +536,7 @@ mlxsw_thermal_modules_fini(struct mlxsw_thermal *thermal,static int mlxsw_thermal_gearbox_tz_init (struct mlxsw_thermal_module *gearbox_tz) { -char tz_name[THERMAL_NAME_LENGTH ]; +char tz_name[40 ];int ret;if (gearbox_tz->slot_index)
Signature · 1 line
2.41.0
Petr Machata
maintainerPATCH 2/2 mlxsw: spectrum_ethtool: Fix -Wformat-truncation warning
In reply to Petr MachataFrom: Ido Schimmel <[email protected]>
Ethtool stats strings cannot be longer than 32 characters ('ETH_GSTRING_LEN'), including the terminating null byte. The format string '%.29s_%.1d' can exceed this limitation if the per-TC counter name exceeds 28 characters. Together with the underscore, the two digits of the TC (bounded at 16) and the terminating null byte, more than 32 characters will be used.
Fix this by bounding the counter name at 28 characters which suppresses the following build warning [1]. This does not affect ethtool output since the longest counter name does not exceed this limitation.
[1]drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c: In function ‘mlxsw_sp_port_get_strings’:drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c:622:58: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
622 | snprintf(*p, ETH_GSTRING_LEN, "%.29s_%.1d",
| ^
In function ‘mlxsw_sp_port_get_tc_strings’,
inlined from ‘mlxsw_sp_port_get_strings’ at drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c:677:4:drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c:622:17: note: ‘snprintf’ output between 3 and 33 bytes into a destination of size 32
622 | snprintf(*p, ETH_GSTRING_LEN, "%.29s_%.1d",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
623 | mlxsw_sp_port_hw_tc_stats[i].str, tc);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c: In function ‘mlxsw_sp_port_get_strings’:drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c:622:58: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
622 | snprintf(*p, ETH_GSTRING_LEN, "%.29s_%.1d",
| ^
In function ‘mlxsw_sp_port_get_tc_strings’,
inlined from ‘mlxsw_sp_port_get_strings’ at drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c:677:4:drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c:622:17: note: ‘snprintf’ output between 3 and 33 bytes into a destination of size 32
622 | snprintf(*p, ETH_GSTRING_LEN, "%.29s_%.1d",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
623 | mlxsw_sp_port_hw_tc_stats[i].str, tc);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--- drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c +1 -1
@@ -619,7 +619,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 ,"%.29s_%.1d" , +snprintf (*p,ETH_GSTRING_LEN ,"%.28s_%d" , mlxsw_sp_port_hw_tc_stats[i].str, tc); *p +=ETH_GSTRING_LEN ; }
Signature · 1 line
2.41.0
Quoted 10 lines · Petr Machata
Ido Schimmel writes:
Commit
6d4ab2e97dcf("extrawarn: enable format and stringop overflow warnings in W=1") enabled format warnings as part of W=1 builds, resulting in two new warnings in mlxsw. Fix both and target at net-next as the warnings are not indicative of actual bugs.Ido Schimmel (2):
mlxsw:core_thermal: Fix -Wformat-truncation warning
mlxsw:spectrum_ethtool: Fix -Wformat-truncation warning
For series,
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 8 lines · On Fri, 6 Oct 2023 16:43:15 +0200 you wrote:
Ido Schimmel writes:
Commit
6d4ab2e97dcf("extrawarn: enable format and stringop overflow warnings in W=1") enabled format warnings as part of W=1 builds, resulting in two new warnings in mlxsw. Fix both and target at net-next as the warnings are not indicative of actual bugs.[...]
Here is the summary with links:
- [net-next,1/2] mlxsw: core_thermal: Fix -Wformat-truncation warning
https://git.kernel.org/netdev/net-next/c/83b2d81b691c - [net-next,2/2] mlxsw: spectrum_ethtool: Fix -Wformat-truncation warning https://git.kernel.org/netdev/net-next/c/392ce2abb0ce
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html