diff mbox series

[U-Boot] net: designware: remove mdio bus on probe failure

Message ID 20190712190703.32519-1-simon.k.r.goldschmidt@gmail.com
State Accepted
Commit 4ee587e2cf8a3f31c2810c35771cb90d2e3b37f8
Delegated to: Joe Hershberger
Headers show
Series [U-Boot] net: designware: remove mdio bus on probe failure | expand

Commit Message

Simon Goldschmidt July 12, 2019, 7:07 p.m. UTC
The designware eth driver registers an mdio bus during probe, but if no
PHY is found, this bus is never removed although probe failes and the
driver is shown as not probed in the dm tree.

This later leads to errors when e.g. the mii or mdio commands try to
use available mdio buses because the mdio bus is still registered but
all corresponding data structures are invalid because probe failed.

Fix this by unregistering the mdio bus on probe failure (just as it is
unregistered in the .remove callback, too).

Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
---

 drivers/net/designware.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

Comments

Joe Hershberger July 13, 2019, 12:07 a.m. UTC | #1
On Fri, Jul 12, 2019 at 2:07 PM Simon Goldschmidt
<simon.k.r.goldschmidt@gmail.com> wrote:
>
> The designware eth driver registers an mdio bus during probe, but if no
> PHY is found, this bus is never removed although probe failes and the
> driver is shown as not probed in the dm tree.
>
> This later leads to errors when e.g. the mii or mdio commands try to
> use available mdio buses because the mdio bus is still registered but
> all corresponding data structures are invalid because probe failed.
>
> Fix this by unregistering the mdio bus on probe failure (just as it is
> unregistered in the .remove callback, too).
>
> Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Joe Hershberger July 18, 2019, 9:40 p.m. UTC | #2
Hi Simon,

https://patchwork.ozlabs.org/patch/1131509/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git

Thanks!
-Joe
diff mbox series

Patch

diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index 2c5d9560c5..3b6cf5ddb5 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -677,10 +677,10 @@  int designware_eth_probe(struct udevice *dev)
 	struct dw_eth_dev *priv = dev_get_priv(dev);
 	u32 iobase = pdata->iobase;
 	ulong ioaddr;
-	int ret;
+	int ret, err;
 	struct reset_ctl_bulk reset_bulk;
 #ifdef CONFIG_CLK
-	int i, err, clock_nb;
+	int i, clock_nb;
 
 	priv->clock_count = 0;
 	clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells");
@@ -753,13 +753,23 @@  int designware_eth_probe(struct udevice *dev)
 	priv->interface = pdata->phy_interface;
 	priv->max_speed = pdata->max_speed;
 
-	dw_mdio_init(dev->name, dev);
+	ret = dw_mdio_init(dev->name, dev);
+	if (ret) {
+		err = ret;
+		goto mdio_err;
+	}
 	priv->bus = miiphy_get_dev_by_name(dev->name);
 
 	ret = dw_phy_init(priv, dev);
 	debug("%s, ret=%d\n", __func__, ret);
+	if (!ret)
+		return 0;
 
-	return ret;
+	/* continue here for cleanup if no PHY found */
+	err = ret;
+	mdio_unregister(priv->bus);
+	mdio_free(priv->bus);
+mdio_err:
 
 #ifdef CONFIG_CLK
 clk_err:
@@ -767,8 +777,8 @@  clk_err:
 	if (ret)
 		pr_err("failed to disable all clocks\n");
 
-	return err;
 #endif
+	return err;
 }
 
 static int designware_eth_remove(struct udevice *dev)