Re: [PATCH net-next] net: mdio: get/put device node during (un)registration

Russell King (Oracle)
2024-01-02T11:02:43Z

On Wed, Dec 20, 2023 at 01:52:29AM -0300, Luiz Angelo Daros de Luca wrote:
> The __of_mdiobus_register() function was storing the device node in
> dev.of_node without increasing its reference count. It implicitly relied
> on the caller to maintain the allocated node until the mdiobus was
> unregistered.
>
> Now, __of_mdiobus_register() will acquire the node before assigning it,
> and of_mdiobus_unregister_callback() will be called at the end of
> mdio_unregister().
>
> Drivers can now release the node immediately after MDIO registration.
> Some of them are already doing that even before this patch.
>
> Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>

I don't like this, certainly not the use of a method prefixed by a
double-underscore, and neither the conditional nature of "putting"
this. That alone seems to point to there being more issues.

I also notice that netdev have applied this without *any* review from
phylib maintainers. Grr.

Indeed there are more issues with the refcounting here. If one looks at
drivers/net/phy/mdio_bus.c::of_mdiobus_link_mdiodev(), we find this:

if (addr == mdiodev->addr) {
device_set_node(dev, of_fwnode_handle(child));
/* The refcount on "child" is passed to the mdio
* device. Do _not_ use of_node_put(child) here.
*/
return;

but there is nowhere that this refcount is dropped.

Really, the patch should be addressing the problem rather than putting
a sticky-plaster over just one instance of it.

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!