Hi1 > When registering mdiobus children, if we get an -EPROBE_DEFER, we shouldn't > ignore it and continue registering the rest of the mdiobus children. This > would permanently prevent the deferring child mdiobus from working instead > of reattempting it in the future. So, if a child mdiobus needs to be > reattempted in the future, defer the entire mdio-mux initialization. > > This fixes the issue where PHYs sitting under the mdio-mux aren't > initialized correctly if the PHY's interrupt controller is not yet ready > when the mdio-mux is being probed. Additional context in the link > below. I don't believe this is quite right. AFAICT it leaks memory in the EPROBE_DEFER case. Could someone double-check? Suggested fix is below. > +++ b/drivers/net/mdio/mdio-mux.c > @@ -175,11 +175,15 @@ int mdio_mux_init(struct device *dev, > cb->mii_bus->write = mdio_mux_write; > r = of_mdiobus_register(cb->mii_bus, child_bus_node); > if (r) { > + mdiobus_free(cb->mii_bus); > + if (r == -EPROBE_DEFER) { > + ret_val = r; > + goto err_loop; > + } > + devm_kfree(dev, cb); > dev_err(dev, > "Error: Failed to register MDIO bus for child %pOF\n", > child_bus_node); > - mdiobus_free(cb->mii_bus); > - devm_kfree(dev, cb); > } else { > cb->next = pb->children; > pb->children = cb; Signed-off-by: Pavel Machek (CIP) diff --git a/drivers/net/mdio/mdio-mux.c b/drivers/net/mdio/mdio-mux.c index ccb3ee704eb1..6d0e505343c5 100644 --- a/drivers/net/mdio/mdio-mux.c +++ b/drivers/net/mdio/mdio-mux.c @@ -163,6 +163,7 @@ int mdio_mux_init(struct device *dev, cb->mii_bus = mdiobus_alloc(); if (!cb->mii_bus) { ret_val = -ENOMEM; + devm_kfree(dev, cb); goto err_loop; } cb->mii_bus->priv = cb; @@ -176,11 +177,11 @@ int mdio_mux_init(struct device *dev, r = of_mdiobus_register(cb->mii_bus, child_bus_node); if (r) { mdiobus_free(cb->mii_bus); + devm_kfree(dev, cb); if (r == -EPROBE_DEFER) { ret_val = r; goto err_loop; } - devm_kfree(dev, cb); dev_err(dev, "Error: Failed to register MDIO bus for child %pOF\n", child_bus_node); -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany