diff mbox series

[v1,3/3] net: mdio-mux: Handle -EPROBE_DEFER correctly

Message ID 20210804214333.927985-4-saravanak@google.com
State Superseded
Headers show
Series Clean up and fix error handling in mdio_mux_init() | expand

Commit Message

Saravana Kannan Aug. 4, 2021, 9:43 p.m. UTC
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.

Link: https://lore.kernel.org/lkml/CAGETcx95kHrv8wA-O+-JtfH7H9biJEGJtijuPVN0V5dUKUAB3A@mail.gmail.com/#t
Signed-off-by: Saravana Kannan <saravanak@google.com>
---
 drivers/net/mdio/mdio-mux.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Andrew Lunn Aug. 7, 2021, 3:49 p.m. UTC | #1
On Wed, Aug 04, 2021 at 02:43:32PM -0700, Saravana Kannan wrote:
> 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.

> 

> Link: https://lore.kernel.org/lkml/CAGETcx95kHrv8wA-O+-JtfH7H9biJEGJtijuPVN0V5dUKUAB3A@mail.gmail.com/#t

> Signed-off-by: Saravana Kannan <saravanak@google.com>


Reviewed-by: Andrew Lunn <andrew@lunn.ch>


    Andrew
diff mbox series

Patch

diff --git a/drivers/net/mdio/mdio-mux.c b/drivers/net/mdio/mdio-mux.c
index 13035e2685c4..ebd001f0eece 100644
--- a/drivers/net/mdio/mdio-mux.c
+++ 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;