]> git.itanic.dy.fi Git - linux-stable/commit
mlxsw: core_thermal: Fix -Wformat-truncation warning
authorIdo Schimmel <idosch@nvidia.com>
Fri, 6 Oct 2023 14:43:16 +0000 (16:43 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 10 Oct 2023 10:15:50 +0000 (12:15 +0200)
commit83b2d81b691ce0efdd4087c510d33087c2474da1
tree4f13813f45c5a2a5e4df8d1d92acce48fcfa18a8
parent59fe651753fb897ebe0ac91c19cf503e7a551632
mlxsw: core_thermal: Fix -Wformat-truncation warning

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>
Reviewed-by: Simon Horman <horms@kernel.org>
Tested-by: Simon Horman <horms@kernel.org> # build-tested
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c