Re: [PATCH net] net: emac: release DT PHY resources on teardown
From: Rosen Penev
Date: Tue Oct 20 2026 - 23:11:11 EST
On Tue Oct 20, 2026 at 6:05 PM PDT, Andrew Lunn wrote:
> On Tue, Oct 20, 2026 at 03:30:02PM -0700, Rosen Penev wrote:
>> Disconnect PHYLIB PHYs and deregister fixed PHYs during both probe
>> unwind and driver removal. Without this cleanup, unbinding a DT-based
>> EMAC can leave its PHY attached to the freed netdev, while fixed-link
>> instances retain their registered fixed PHY.
>
> This driver is quite convoluted with its PHY handling.
I agree. I got this LLM to convert the whole thing to phylink. It tested
a bunch of stuff over serial and ethernet, which works. That's net-next
material though. It'll probably get rejected.
>
> Please split this into two, phy_disconnect() and
> of_phy_deregister_fixed_link() and add better commit messages.
>
> if ((dev->phy_address == 0xffffffff && dev->phy_map == 0xffffffff) ||
> of_phy_is_fixed_link(np)) {
>
> /* PHY-less configuration. */
> dev->phy.address = -1;
> ...
> if (of_phy_is_fixed_link(np)) {
> int res = emac_dt_mdio_probe(dev);
>
> if (res)
> return res;
>
> res = of_phy_register_fixed_link(np);
>
> The logic here is more complex than
>
>> + if (of_phy_is_fixed_link(np))
>> + of_phy_deregister_fixed_link(np);
>
> So you need to explain in the commit message why it is correct.
>
>> +static void emac_cleanup_phy(struct emac_instance *dev)
>> +{
>> + struct device_node *np = dev->ofdev->dev.of_node;
>> +
>> + if (dev->ndev->phydev && dev->phy.address >= 0)
>> + phy_disconnect(dev->ndev->phydev);
>
> It is also not clear this is correct, since a fixed-link should be
> connected to, yet a fixed link has dev->phy.address == -1?
>
> Andrew