Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Johan Hovold
Mon, 16 Nov 2026 09:11
[PATCH net-next v2 0/2] net: tn40xx: avoid early firmware node release
Author: Johan Hovold
Date: Mon, 16 Nov 2026 09:11
Date: Mon, 16 Nov 2026 09:11
33 lines
8481 bytes
8481 bytes
The tn40xx driver works around a swnode implementation detail and drops a firmware node reference it has not taken itself. The first patch avoids releasing the firmware node prematurely if mdio bus registration ever bails out before taking the reference, and the second patch cleans up the implementation by switching to using a primary software node. This was something I stumbled over when reviewing the software node implementation and the series has only been compile tested. Johan Changes in v2 - only drop the fwnode reference if it has been taken - amend commit message and explain why this does not lead to a UAF currently - switch to primary software node (2/2, new patch) v1: https://lore.kernel.org/all/20261110100051.2567443-1-johan@kernel.org/ Johan Hovold (2): net: tn40xx: avoid early firmware node release net: tn40xx: switch to primary software node drivers/net/ethernet/tehuti/tn40_mdio.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) -- 2.56.1
[PATCH net-next v2 2/2] net: tn40xx: switch to primary software node
Author: Johan Hovold
Date: Mon, 16 Nov 2026 09:11
Date: Mon, 16 Nov 2026 09:11
77 lines
10404 bytes
10404 bytes
Some cards use a secondary software node which is removed from the
device by device_remove_software_node() on probe failure and on driver
unbind.
Removing a secondary software node this way involves clearing the
mdiobus device firmware node pointer, which in turn means that the
driver must drop any reference taken by __mdiobus_register() during
registration instead of letting mdiobus_release() do it as it would for
a primary firmware node.
Fix the asymmetry and layering violation and clean up the software node
handling by making the software node a primary node which is released
when freeing the mdiobus.
Cc: Hans-Frieder Vogt <hfdevel@gmx.net>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/net/ethernet/tehuti/tn40_mdio.c | 23 ++++-------------------
1 file changed, 4 insertions(+), 19 deletions(-)
diff --git a/drivers/net/ethernet/tehuti/tn40_mdio.c b/drivers/net/ethernet/tehuti/tn40_mdio.c
index 438f0d86c2a1..4130d75fbcaf 100644
--- a/drivers/net/ethernet/tehuti/tn40_mdio.c
+++ b/drivers/net/ethernet/tehuti/tn40_mdio.c
@@ -156,21 +156,14 @@ static int tn40_swnodes_register(struct tn40_priv *priv)
void tn40_swnodes_cleanup(struct tn40_priv *priv)
{
/* cleanup of swnodes is only needed for AQR105-based cards */
- if (priv->pdev->device == PCI_DEVICE_ID_TEHUTI_TN9510) {
- /*
- * drop any reference taken by __mdiobus_register() before
- * device_remove_software_node() clears the fwnode pointer
- */
- if (priv->mdio->state != MDIOBUS_ALLOCATED)
- fwnode_handle_put(dev_fwnode(&priv->mdio->dev));
- device_remove_software_node(&priv->mdio->dev);
+ if (priv->pdev->device == PCI_DEVICE_ID_TEHUTI_TN9510)
software_node_unregister_node_group(priv->nodes.group);
- }
}
int tn40_mdiobus_init(struct tn40_priv *priv)
{
struct pci_dev *pdev = priv->pdev;
+ struct fwnode_handle *fwnode;
struct mii_bus *bus;
int ret;
@@ -196,13 +189,8 @@ int tn40_mdiobus_init(struct tn40_priv *priv)
return ret;
}
- ret = device_add_software_node(&bus->dev,
- priv->nodes.group[SWNODE_MDIO]);
- if (ret) {
- dev_err(&pdev->dev,
- "device_add_software_node failed: %d\n", ret);
- goto err_swnodes_unregister;
- }
+ fwnode = software_node_fwnode(priv->nodes.group[SWNODE_MDIO]);
+ bus->dev.fwnode = fwnode;
}
tn40_mdio_set_speed(priv, TN40_MDIO_SPEED_6MHZ);
@@ -214,9 +202,6 @@ int tn40_mdiobus_init(struct tn40_priv *priv)
}
return 0;
-err_swnodes_unregister:
- software_node_unregister_node_group(priv->nodes.group);
- return ret;
err_swnodes_cleanup:
tn40_swnodes_cleanup(priv);
return ret;
--
2.56.1
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads