Skip to content

Commit 1b2bd0c

Browse files
Binary-Eaterkuba-moo
authored andcommitted
net/mlx5e: Check return value of snprintf writing to fw_version buffer for representors
Treat the operation as an error case when the return value is equivalent to the size of the name buffer. Failed to write null terminator to the name buffer, making the string malformed and should not be used. Provide a string with only the firmware version when forming the string with the board id fails. This logic for representors is identical to normal flow with ethtool. Without check, will trigger -Wformat-truncation with W=1. drivers/net/ethernet/mellanox/mlx5/core/en_rep.c: In function 'mlx5e_rep_get_drvinfo': drivers/net/ethernet/mellanox/mlx5/core/en_rep.c:78:31: warning: '%.16s' directive output may be truncated writing up to 16 bytes into a region of size between 13 and 22 [-Wformat-truncation=] 78 | "%d.%d.%04d (%.16s)", | ^~~~~ drivers/net/ethernet/mellanox/mlx5/core/en_rep.c:77:9: note: 'snprintf' output between 12 and 37 bytes into a destination of size 32 77 | snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 78 | "%d.%d.%04d (%.16s)", | ~~~~~~~~~~~~~~~~~~~~~ 79 | fw_rev_maj(mdev), fw_rev_min(mdev), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 80 | fw_rev_sub(mdev), mdev->board_id); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Fixes: cf83c8f ("net/mlx5e: Add missing ethtool driver info for representors") Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6d4ab2e97dcfbcd748ae71761a9d8e5e41cc732c Signed-off-by: Rahul Rameshbabu <[email protected]> Reviewed-by: Dragos Tatulea <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 41e63c2 commit 1b2bd0c

File tree

1 file changed

+8
-4
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+8
-4
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,17 @@ static void mlx5e_rep_get_drvinfo(struct net_device *dev,
7171
{
7272
struct mlx5e_priv *priv = netdev_priv(dev);
7373
struct mlx5_core_dev *mdev = priv->mdev;
74+
int count;
7475

7576
strscpy(drvinfo->driver, mlx5e_rep_driver_name,
7677
sizeof(drvinfo->driver));
77-
snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
78-
"%d.%d.%04d (%.16s)",
79-
fw_rev_maj(mdev), fw_rev_min(mdev),
80-
fw_rev_sub(mdev), mdev->board_id);
78+
count = snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
79+
"%d.%d.%04d (%.16s)", fw_rev_maj(mdev),
80+
fw_rev_min(mdev), fw_rev_sub(mdev), mdev->board_id);
81+
if (count == sizeof(drvinfo->fw_version))
82+
snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
83+
"%d.%d.%04d", fw_rev_maj(mdev),
84+
fw_rev_min(mdev), fw_rev_sub(mdev));
8185
}
8286

8387
static const struct counter_desc sw_rep_stats_desc[] = {

0 commit comments

Comments
 (0)