From: Johan Hovold <johan@kernel.org>
To: FUJITA Tomonori <fujita.tomonori@gmail.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org, Johan Hovold <johan@kernel.org>,
Hans-Frieder Vogt <hfdevel@gmx.net>
Subject: [PATCH net-next v2 1/2] net: tn40xx: avoid early firmware node release
Date: Mon, 16 Nov 2026 10:11:48 +0100 [thread overview]
Message-ID: <20261116091149.730586-2-johan@kernel.org> (raw)
In-Reply-To: <20261116091149.730586-1-johan@kernel.org>
The mdiobus allocated by tn40_mdiobus_init() has no primary firmware
node so its firmware node pointer points to the secondary software node
added by device_add_software_node() and whose reference is released by
device_remove_software_node().
As device_remove_software_node() clears the firmware node pointer, any
reference taken by __mdiobus_register() needs to dropped before removing
the software node.
Add a comment explaining why the driver drops a reference it never took
itself, and only drop the firmware node reference if it was actually
taken by __mdiobus_register() as indicated by the bus state.
Note that __mdiobus_register() will essentially only return early
without taking the reference during development when the bus structure
has not been properly initialised. And currently, not even that would
lead to a use-after-free as the child PHY node holds a reference to the
parent MDIO node, the child is deregistered before the parent, and
software_node_unregister() returns early if the parent node has already
been freed.
Cc: Hans-Frieder Vogt <hfdevel@gmx.net>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/net/ethernet/tehuti/tn40_mdio.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/tehuti/tn40_mdio.c b/drivers/net/ethernet/tehuti/tn40_mdio.c
index fb1a4a2e4dbc..438f0d86c2a1 100644
--- a/drivers/net/ethernet/tehuti/tn40_mdio.c
+++ b/drivers/net/ethernet/tehuti/tn40_mdio.c
@@ -157,7 +157,12 @@ 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) {
- fwnode_handle_put(dev_fwnode(&priv->mdio->dev));
+ /*
+ * 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);
software_node_unregister_node_group(priv->nodes.group);
}
--
2.56.1
next prev parent reply other threads:[~2026-11-16 9:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 9:11 [PATCH net-next v2 0/2] net: tn40xx: avoid early firmware node release Johan Hovold
2026-11-16 9:11 ` Johan Hovold [this message]
2026-11-16 9:11 ` [PATCH net-next v2 2/2] net: tn40xx: switch to primary software node Johan Hovold
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261116091149.730586-2-johan@kernel.org \
--to=johan@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=fujita.tomonori@gmail.com \
--cc=hfdevel@gmx.net \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox