Re: [PATCH net-next v5 3/4] net: mdio: reset PHY before attempting to access registers in fwnode_mdiobus_register_phy
From: Buday Csaba
Date: Wed Oct 29 2025 - 10:15:30 EST
On Wed, Oct 29, 2025 at 02:20:14PM +0100, Andrew Lunn wrote:
> > +/* Hard-reset a PHY before registration */
> > +static int fwnode_reset_phy(struct mii_bus *bus, u32 addr,
> > + struct fwnode_handle *phy_node)
> > +{
> > + struct mdio_device *tmpdev;
> > + int rc;
> > +
> > + tmpdev = mdio_device_create(bus, addr);
> > + if (IS_ERR(tmpdev))
> > + return PTR_ERR(tmpdev);
> > +
> > + fwnode_handle_get(phy_node);
>
> You add a _get() here. Where is the corresponding _put()?
When mdio_device_free() is called, it eventually invokes
mdio_device_release(). There is the corresponding _put(), that will
release the reference. I also verified this with a stack trace.
>
> Also, fwnode_handle_get() returns a handle. Why do you throw it away?
> What is the point of this get?
>
I copied this initialization stub from of_mdiobus_register_device()
in of_mdio.c. The same pattern is used there:
fwnode_handle_get(fwnode);
device_set_node(&mdiodev->dev, fwnode);
It is kind of awkward that we need to half-establish a device, just
to assert the reset, but I could not think of any better solution, that
does not lead to a large amount of code duplication.
> > + device_set_node(&tmpdev->dev, phy_node);
> > + rc = mdio_device_register_reset(tmpdev);
> > + if (rc) {
> > + mdio_device_free(tmpdev);
> > + return rc;
> > + }
> > +
> > + mdio_device_reset(tmpdev, 1);
> > + mdio_device_reset(tmpdev, 0);
> > +
> > + mdio_device_unregister_reset(tmpdev);
> > + mdio_device_free(tmpdev);
> > +
> > + return 0;
> > +}
> > +
>
> Andrew
>
Csaba