From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Luiz Angelo Daros de Luca <luizluca@gmail.com>, kuba@kernel.org
Cc: netdev@vger.kernel.org, andrew@lunn.ch, hkallweit1@gmail.com,
davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next] net: mdio: get/put device node during (un)registration
Date: Wed, 3 Jan 2024 12:01:12 +0000 [thread overview]
Message-ID: <ZZVMiPCoDyv/NZXN@shell.armlinux.org.uk> (raw)
In-Reply-To: <ZZU1SJlKpeU38c9I@shell.armlinux.org.uk>
On Wed, Jan 03, 2024 at 10:22:00AM +0000, Russell King (Oracle) wrote:
> I agree with that approach, but as you rightly point out, we need MDIO
> to behave correctly, and I don't think that patching just one bit of
> MDIO to fix this mess is the right approach.
This is probably a safer approach to ensuring that the firmware data
reference count isn't dropped while the bus exists byensuring that we
always take a reference at register time. It also likely fixes similar
issues with ACPI and swnode based users as well.
It doesn't deal with the excess-refcount problem, as with this approach
the two issues are entirely independent of each other.
Please test to check that this addresses your issue. Thanks.
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 6cf73c15635b..afbad1ad8683 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -193,6 +193,10 @@ static void mdiobus_release(struct device *d)
bus->state != MDIOBUS_ALLOCATED,
"%s: not in RELEASED or ALLOCATED state\n",
bus->id);
+
+ if (bus->state == MDIOBUS_RELEASED)
+ fwnode_handle_put(dev_fwnode(d));
+
kfree(bus);
}
@@ -684,6 +688,15 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)
bus->dev.groups = NULL;
dev_set_name(&bus->dev, "%s", bus->id);
+ /* If the bus state is allocated, we're registering a fresh bus
+ * that may have a fwnode associated with it. Grab a reference
+ * to the fwnode. This will be dropped when the bus is released.
+ * If the bus was set to unregistered, it means that the bus was
+ * previously registered, and we've already grabbed a reference.
+ */
+ if (bus->state == MDIOBUS_ALLOCATED)
+ fwnode_handle_get(dev_fwnode(&bus->dev));
+
/* We need to set state to MDIOBUS_UNREGISTERED to correctly release
* the device in mdiobus_free()
*
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
next prev parent reply other threads:[~2024-01-03 12:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-20 4:52 [PATCH net-next] net: mdio: get/put device node during (un)registration Luiz Angelo Daros de Luca
2024-01-01 13:10 ` patchwork-bot+netdevbpf
2024-01-02 11:02 ` Russell King (Oracle)
2024-01-02 21:57 ` Luiz Angelo Daros de Luca
2024-01-03 0:31 ` Jakub Kicinski
2024-01-03 10:22 ` Russell King (Oracle)
2024-01-03 12:01 ` Russell King (Oracle) [this message]
2024-01-03 21:50 ` Luiz Angelo Daros de Luca
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=ZZVMiPCoDyv/NZXN@shell.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luizluca@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.