Re: [PATCH] fix: net: cadence: macb_mii_init: fix double of_node_put on mdio_np after macb_mdiobus_register

From: Andrew Lunn

Date: Fri Jun 26 2026 - 12:07:05 EST


On Fri, Jun 26, 2026 at 11:14:49PM +0800, WenTao Liang wrote:
> After macb_mdiobus_register succeeds, the mdio_np reference ownership is
> transferred to the mii_bus device (stored in mii_bus->dev.of_node). When
> the subsequent macb_mii_probe fails, the error path jumps to
> err_out_unregister_bus which calls mdiobus_free (releasing the node via
> fwnode_handle_put) and then falls through to err_out which calls
> of_node_put(mdio_np) again, causing a double put.
>
> Move the of_node_put to only execute on paths where the reference was not
> transferred (i.e., before successful macb_mdiobus_register).
>
> Cc: stable@xxxxxxxxxxxxxxx
> Fixes: ef8a2e27289e ("net: macb: fix probing of PHY not described in the dt")
> Signed-off-by: WenTao Liang <vulab@xxxxxxxxxxx>
> ---
> drivers/net/ethernet/cadence/macb_main.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index a12aa21244e8..c58e089e5888 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -1170,6 +1170,9 @@ static int macb_mii_init(struct macb *bp)
> mdiobus_unregister(bp->mii_bus);
> err_out_free_mdiobus:
> mdiobus_free(bp->mii_bus);
> + of_node_put(mdio_np);
> + return err;
> +
> err_out:
> of_node_put(mdio_np);

This does not look correct.

You say if mdiobus_register() is successful, mdiobus_free() will
release the reference.

If macb_mii_probe() fails, we have successfully done
mdiobus_register(). It does a goto err_out_unregister_bus, which calls
mdiobus_unregister(), mdiobus_free() releasing the reference, and then
with your patch of_node_put(). This looks like a double put to me.

I think i already said this once, consider the risk of your patches,
particularly if you cannot test them.

Andrew