• Ido Schimmel's avatar
    mlxsw: spectrum_ethtool: Fix -Wformat-truncation warning · 392ce2ab
    Ido Schimmel authored
    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: default avatarIdo Schimmel <idosch@nvidia.com>
    Reviewed-by: default avatarPetr Machata <petrm@nvidia.com>
    Signed-off-by: default avatarPetr Machata <petrm@nvidia.com>
    Reviewed-by: default avatarSimon Horman <horms@kernel.org>
    Tested-by: Simon Horman <horms@kernel.org> # build-tested
    Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
    392ce2ab
spectrum_ethtool.c 59.8 KB