From: Heiner Kallweit <hkallweit1@gmail.com>
To: Andrew Lunn <andrew@lunn.ch>
Cc: Florian Fainelli <f.fainelli@gmail.com>,
Russell King - ARM Linux <linux@armlinux.org.uk>,
David Miller <davem@davemloft.net>,
Realtek linux nic maintainers <nic_swsd@realtek.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH net-next 1/2] net: phy: unregister MDIO bus in _devm_mdiobus_free if needed
Date: Wed, 19 Feb 2020 23:51:47 +0100 [thread overview]
Message-ID: <57df2161-a4f8-c57a-d5d0-e360f06aa9a2@gmail.com> (raw)
In-Reply-To: <20200219222103.GZ31084@lunn.ch>
On 19.02.2020 23:21, Andrew Lunn wrote:
> 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@gmail.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?
>
To a certain extent pcim_release() is similar. It silently reverses
previous calls to pci_enable_msi / pci_enable_msix (after calling
pcim_enable_device).
> 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().
>
I understand the concern regarding the asymmetry. For me the question
is whether the additional effort for avoiding it is worth it.
We'd have to create at least devm_register_mdiobus and
devm_of_mdiobus_register.
Also then we'd have to think about how to deal with the case that a
non-perfect driver author combines a non-managed mdiobus_alloc
with a later call to devm_register_mdiobus, because we'd like to
avoid the case that mdiobus_free is called before mdiobus_unregister.
Maybe we would need a mechanism similar to the one used in the
PCI core functions mentioned earlier.
devm_register_mdiobus would have to warn if the bus allocation was
non-managed.
> Andrew
>
Heiner
next prev parent reply other threads:[~2020-02-19 22:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-17 20:34 [PATCH net-next 0/2] net: phy: unregister MDIO bus in _devm_mdiobus_free if needed Heiner Kallweit
2020-02-17 20:34 ` [PATCH net-next 1/2] " Heiner Kallweit
2020-02-19 22:21 ` Andrew Lunn
2020-02-19 22:51 ` Heiner Kallweit [this message]
2020-02-17 20:35 ` [PATCH net-next 2/2] r8169: let managed MDIO bus handling unregister the MDIO bus Heiner Kallweit
2020-02-21 19:42 ` [PATCH net-next 0/2] net: phy: unregister MDIO bus in _devm_mdiobus_free if needed David Miller
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=57df2161-a4f8-c57a-d5d0-e360f06aa9a2@gmail.com \
--to=hkallweit1@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=nic_swsd@realtek.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;
as well as URLs for NNTP newsgroup(s).