lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <57df2161-a4f8-c57a-d5d0-e360f06aa9a2@gmail.com>
Date:   Wed, 19 Feb 2020 23:51:47 +0100
From:   Heiner Kallweit <hkallweit1@...il.com>
To:     Andrew Lunn <andrew@...n.ch>
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 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@...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?
> 
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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ