net/mlx5e: Fix return value in case of module EEPROM read error
Subsystems (5)
Tariq Toukan
maintainerPATCH 1/1 net/mlx5e: Fix return value in case of module EEPROM read error
From: Gal Pressman <[email protected]>
mlx5e_get_module_eeprom_by_page() has weird error handling.
First, it is treating -EINVAL as a special case, but it is unclear why.
Second, it tries to fail "gracefully" by returning the number of bytes read even in case of an error. This results in wrongly returning success (0 return value) if the error occurs before any bytes were read.
Simplify the error handling by returning an error when such occurs. This also aligns with the error handling we have in mlx5e_get_module_eeprom() for the old API.
This fixes the following case where the query fails, but userspace ethtool wrongly treats it as success and dumps an output:
# ethtool -m eth2 netlink warning: mlx5_core: Query module eeprom by page failed, read 0 bytes, err -5 netlink warning: mlx5_core: Query module eeprom by page failed, read 0 bytes, err -5 Offset Values ------ ------ 0x0000: 00 00 00 00 05 00 04 00 00 00 00 00 05 00 05 00 0x0010: 00 00 00 00 05 00 06 00 50 00 00 00 67 65 20 66 0x0020: 61 69 6c 65 64 2c 20 72 65 61 64 20 30 20 62 79 0x0030: 74 65 73 2c 20 65 72 72 20 2d 35 00 14 00 03 00 0x0040: 08 00 01 00 03 00 00 00 08 00 02 00 1a 00 00 00 0x0050: 14 00 04 00 08 00 01 00 04 00 00 00 08 00 02 00 0x0060: 0e 00 00 00 14 00 05 00 08 00 01 00 05 00 00 00 0x0070: 08 00 02 00 1a 00 00 00 14 00 06 00 08 00 01 00
--- drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +1 -3
@@ -2125,14 +2125,12 @@ static int mlx5e_get_module_eeprom_by_page(struct net_device *netdev,if (!size_read)return i; -if (size_read == -EINVAL ) -return -EINVAL ;if (size_read <0 ) {NL_SET_ERR_MSG_FMT_MOD ( extack,"Query module eeprom by page failed, read %u bytes, err %d" , i, size_read); -return i; +return size_read; } i += size_read;
base-commit: e120f46768d98151ece8756ebd688b0e43dc8b29
Signature · 1 line
2.31.1
Quoted 32 lines · Tariq Toukan
From: Gal Pressman <[email protected]>
mlx5e_get_module_eeprom_by_page()has weird error handling.First, it is treating
-EINVALas a special case, but it is unclear why.Second, it tries to fail "gracefully" by returning the number of bytes read even in case of an error. This results in wrongly returning success (0 return value) if the error occurs before any bytes were read.
Simplify the error handling by returning an error when such occurs. This also aligns with the error handling we have in
mlx5e_get_module_eeprom()for the old API.This fixes the following case where the query fails, but userspace ethtool wrongly treats it as success and dumps an output:
# ethtool -m eth2 netlink warning: mlx5_core: Query module eeprom by page failed, read 0 bytes, err -5 netlink warning: mlx5_core: Query module eeprom by page failed, read 0 bytes, err -5 Offset Values ------ ------ 0x0000: 00 00 00 00 05 00 04 00 00 00 00 00 05 00 05 00 0x0010: 00 00 00 00 05 00 06 00 50 00 00 00 67 65 20 66 0x0020: 61 69 6c 65 64 2c 20 72 65 61 64 20 30 20 62 79 0x0030: 74 65 73 2c 20 65 72 72 20 2d 35 00 14 00 03 00 0x0040: 08 00 01 00 03 00 00 00 08 00 02 00 1a 00 00 00 0x0050: 14 00 04 00 08 00 01 00 04 00 00 00 08 00 02 00 0x0060: 0e 00 00 00 14 00 05 00 08 00 01 00 05 00 00 00 0x0070: 08 00 02 00 1a 00 00 00 14 00 06 00 08 00 01 00
Quoted 4 lines
Fixes e109d2b204da ("net/mlx5: Implement get_module_eeprom_by_page()")Signed-off-by Gal Pressman <[email protected]>Reviewed-by Alex Lazar <[email protected]>Signed-off-by Tariq Toukan <[email protected]>
Thanks for the detailed description.
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 4 lines · On Tue, 4 Nov 2025 16:15:36 +0200 you wrote:
From: Gal Pressman <[email protected]>
mlx5e_get_module_eeprom_by_page()has weird error handling.
Quoted 8 lines
First, it is treating
-EINVALas a special case, but it is unclear why.Second, it tries to fail "gracefully" by returning the number of bytes read even in case of an error. This results in wrongly returning success (0 return value) if the error occurs before any bytes were read.
[...]
Here is the summary with links:
- [net] net/mlx5e: Fix return value in case of module EEPROM read error
https://git.kernel.org/netdev/net/c/d1c94bc5b90c
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html