netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] mlxsw: Fix -Wformat-truncation warnings
@ 2023-10-06 14:43 Petr Machata
  2023-10-06 14:43 ` [PATCH net-next 1/2] mlxsw: core_thermal: Fix -Wformat-truncation warning Petr Machata
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Petr Machata @ 2023-10-06 14:43 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	netdev
  Cc: Ido Schimmel, Petr Machata, mlxsw

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(-)

-- 
2.41.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net-next 1/2] mlxsw: core_thermal: Fix -Wformat-truncation warning
  2023-10-06 14:43 [PATCH net-next 0/2] mlxsw: Fix -Wformat-truncation warnings Petr Machata
@ 2023-10-06 14:43 ` Petr Machata
  2023-10-06 14:43 ` [PATCH net-next 2/2] mlxsw: spectrum_ethtool: " Petr Machata
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Petr Machata @ 2023-10-06 14:43 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	netdev
  Cc: Ido Schimmel, Petr Machata, mlxsw

From: Ido Schimmel <idosch@nvidia.com>

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);
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
index f709e44c76a8..f1b48d6615f6 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
@@ -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)
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net-next 2/2] mlxsw: spectrum_ethtool: Fix -Wformat-truncation warning
  2023-10-06 14:43 [PATCH net-next 0/2] mlxsw: Fix -Wformat-truncation warnings Petr Machata
  2023-10-06 14:43 ` [PATCH net-next 1/2] mlxsw: core_thermal: Fix -Wformat-truncation warning Petr Machata
@ 2023-10-06 14:43 ` Petr Machata
  2023-10-08 13:59 ` [PATCH net-next 0/2] mlxsw: Fix -Wformat-truncation warnings Simon Horman
  2023-10-10 10:20 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Petr Machata @ 2023-10-06 14:43 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	netdev
  Cc: Ido Schimmel, Petr Machata, mlxsw

From: Ido Schimmel <idosch@nvidia.com>

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);
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c
index 472830d07ac1..0f29e9c19411 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c
@@ -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;
 	}
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next 0/2] mlxsw: Fix -Wformat-truncation warnings
  2023-10-06 14:43 [PATCH net-next 0/2] mlxsw: Fix -Wformat-truncation warnings Petr Machata
  2023-10-06 14:43 ` [PATCH net-next 1/2] mlxsw: core_thermal: Fix -Wformat-truncation warning Petr Machata
  2023-10-06 14:43 ` [PATCH net-next 2/2] mlxsw: spectrum_ethtool: " Petr Machata
@ 2023-10-08 13:59 ` Simon Horman
  2023-10-10 10:20 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Simon Horman @ 2023-10-08 13:59 UTC (permalink / raw)
  To: Petr Machata
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	netdev, Ido Schimmel, mlxsw

On Fri, Oct 06, 2023 at 04:43:15PM +0200, Petr Machata 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.
> 
> Ido Schimmel (2):
>   mlxsw: core_thermal: Fix -Wformat-truncation warning
>   mlxsw: spectrum_ethtool: Fix -Wformat-truncation warning

For series,

Reviewed-by: Simon Horman <horms@kernel.org>
Tested-by: Simon Horman <horms@kernel.org> # build-tested


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next 0/2] mlxsw: Fix -Wformat-truncation warnings
  2023-10-06 14:43 [PATCH net-next 0/2] mlxsw: Fix -Wformat-truncation warnings Petr Machata
                   ` (2 preceding siblings ...)
  2023-10-08 13:59 ` [PATCH net-next 0/2] mlxsw: Fix -Wformat-truncation warnings Simon Horman
@ 2023-10-10 10:20 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-10-10 10:20 UTC (permalink / raw)
  To: Petr Machata; +Cc: davem, edumazet, kuba, pabeni, netdev, idosch, mlxsw

Hello:

This series was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-10-10 10:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-06 14:43 [PATCH net-next 0/2] mlxsw: Fix -Wformat-truncation warnings Petr Machata
2023-10-06 14:43 ` [PATCH net-next 1/2] mlxsw: core_thermal: Fix -Wformat-truncation warning Petr Machata
2023-10-06 14:43 ` [PATCH net-next 2/2] mlxsw: spectrum_ethtool: " Petr Machata
2023-10-08 13:59 ` [PATCH net-next 0/2] mlxsw: Fix -Wformat-truncation warnings Simon Horman
2023-10-10 10:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).