[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200219222103.GZ31084@lunn.ch>
Date: Wed, 19 Feb 2020 23:21:03 +0100
From: Andrew Lunn <andrew@...n.ch>
To: Heiner Kallweit <hkallweit1@...il.com>
Cc: Florian Fainelli <f.fainelli@...il.com>,
Russell King - ARM Linux <linux@...linux.org.uk>,
David Miller <davem@...emloft.net>,
Realtek linux nic maintainers <nic_swsd@...ltek.com>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>
Subject: Re: [PATCH net-next 1/2] net: phy: unregister MDIO bus in
_devm_mdiobus_free if needed
On Mon, Feb 17, 2020 at 09:34:57PM +0100, Heiner Kallweit wrote:
> If using managed MDIO bus handling (devm_mdiobus_alloc et al) we still
> have to manually unregister the MDIO bus. For drivers that don't depend
> on unregistering the MDIO bus at a specific, earlier point in time we
> can make driver author's life easier by automagically unregistering
> the MDIO bus. This extension is transparent to existing drivers.
>
> Signed-off-by: Heiner Kallweit <hkallweit1@...il.com>
> ---
> drivers/net/phy/mdio_bus.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> index 9bb9f37f2..6af51cbdb 100644
> --- a/drivers/net/phy/mdio_bus.c
> +++ b/drivers/net/phy/mdio_bus.c
> @@ -170,7 +170,12 @@ EXPORT_SYMBOL(mdiobus_alloc_size);
>
> static void _devm_mdiobus_free(struct device *dev, void *res)
> {
> - mdiobus_free(*(struct mii_bus **)res);
> + struct mii_bus *bus = *(struct mii_bus **)res;
> +
> + if (bus->state == MDIOBUS_REGISTERED)
> + mdiobus_unregister(bus);
> +
> + mdiobus_free(bus);
> }
Hi Heiner
The API is rather asymmetric. The alloc is not just setting up a free,
but also an unregister. Are there other examples of this in the
kernel?
Maybe a devm_of_mdiobus_register() would be better? It is then clear
that the unregister happens because of this call, and the free because
of the devm_mdiobus_alloc().
Andrew
Powered by blists - more mailing lists