Skip to contentSkip to conversation

nfp: flower: add check for flower VF netdevs for get/set_eeprom

PATCH Applied Simon Horman 3 participants 3 messages Feb 6, 2023 – Feb 8, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfp: flower: add check for flower VF netdevs for get/set_eeprom

From: James Hershaw <[email protected]>

Move the nfp_net_get_port_mac_by_hwinfo() check to ahead in the get/set_eeprom() functions to in order to check for a VF netdev, which this function does not support.

It is debatable if this is a fix or an enhancement, and we have chosen
to go for the latter. It does address a problem introduced by
commit 74b4f1739d4e ("nfp: flower: change get/set_eeprom logic and enable for flower reps"). However, the ethtool->len == 0 check avoids the problem manifesting as a run-time bug (NULL pointer dereference of app).

---
 drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c +6 -6
index e9d228d7a95d..807b86667bca 100644
@@ -1908,12 +1908,12 @@ nfp_net_get_eeprom(struct net_device *netdev,
 	struct nfp_app *app = nfp_app_from_netdev(netdev);
 	u8 buf[NFP_EEPROM_LEN] = {};
 
-	if (eeprom->len == 0)
-		return -EINVAL;
-
 	if (nfp_net_get_port_mac_by_hwinfo(netdev, buf))
 		return -EOPNOTSUPP;
 
+	if (eeprom->len == 0)
+		return -EINVAL;
+
 	eeprom->magic = app->pdev->vendor | (app->pdev->device << 16);
 	memcpy(bytes, buf + eeprom->offset, eeprom->len);
 
@@ -1927,15 +1927,15 @@ nfp_net_set_eeprom(struct net_device *netdev,
 	struct nfp_app *app = nfp_app_from_netdev(netdev);
 	u8 buf[NFP_EEPROM_LEN] = {};
 
+	if (nfp_net_get_port_mac_by_hwinfo(netdev, buf))
+		return -EOPNOTSUPP;
+
 	if (eeprom->len == 0)
 		return -EINVAL;
 
 	if (eeprom->magic != (app->pdev->vendor | app->pdev->device << 16))
 		return -EINVAL;
 
-	if (nfp_net_get_port_mac_by_hwinfo(netdev, buf))
-		return -EOPNOTSUPP;
-
 	memcpy(buf + eeprom->offset, bytes, eeprom->len);
 	if (nfp_net_set_port_mac_by_hwinfo(netdev, buf))
 		return -EOPNOTSUPP;
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Simon Horman

From: James Hershaw <[email protected]>

Move the nfp_net_get_port_mac_by_hwinfo() check to ahead in the get/set_eeprom() functions to in order to check for a VF netdev, which this function does not support.

It is debatable if this is a fix or an enhancement, and we have chosen
to go for the latter. It does address a problem introduced by
commit 74b4f1739d4e ("nfp: flower: change get/set_eeprom logic and enable for flower reps"). However, the ethtool->len == 0 check avoids the problem manifesting as a run-time bug (NULL pointer dereference of app).

Quoted 7 lines
---
 drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Thanks,

#2 lore raw
In reply to Simon Horman
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Quoted 6 lines · On Mon, 6 Feb 2023 16:48:36 +0100 you wrote:

From: James Hershaw <[email protected]>

Move the nfp_net_get_port_mac_by_hwinfo() check to ahead in the get/set_eeprom() functions to in order to check for a VF netdev, which this function does not support.

Quoted 7 lines

It is debatable if this is a fix or an enhancement, and we have chosen
to go for the latter. It does address a problem introduced by
commit 74b4f1739d4e ("nfp: flower: change get/set_eeprom logic and enable for flower reps"). However, the ethtool->len == 0 check avoids the problem manifesting as a run-time bug (NULL pointer dereference of app).

[...]

Here is the summary with links:
- [net-next] nfp: flower: add check for flower VF netdevs for get/set_eeprom

    https://git.kernel.org/netdev/net-next/c/f817554786dd

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html