]> git.itanic.dy.fi Git - linux-stable/commitdiff
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)
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

index f709e44c76a80b589a9d19745e15a2563b010f3b..f1b48d6615f6a8b0b04089cbe3a7c3f168385939 100644 (file)
@@ -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)