From: Andy Chiu <andy.chiu@sifive.com>
To: monstr@monstr.eu
Cc: Andy Chiu <andy.chiu@sifive.com>,
Greentime Hu <greentime.hu@sifive.com>,
Joe Hershberger <joe.hershberger@ni.com>,
Ramon Fried <rfried.dev@gmail.com>,
u-boot@lists.denx.de
Subject: [PATCH 3/3] net: xilinx: Force a probe failure if it cannot setup phy
Date: Thu, 20 Jan 2022 15:34:20 +0800 [thread overview]
Message-ID: <20220120073420.1887809-3-andy.chiu@sifive.com> (raw)
In-Reply-To: <20220120073420.1887809-1-andy.chiu@sifive.com>
Or we may get load access faults afterward.
The `phydev` field on axi-ethernet’s private struct is not set on a
failed phy_connect():
axi_emac_probe()
=> axiemac_phy_init()
=> priv->phydev = phy_connect() <--- may fail
However, all of the following calls on `axi_emac_ops` assume a valid
`phydev` pointer. For example:
axiemac_start()
=> setup_phy()
=> phy_startup()
=> if (phydev->drv->startup) <--- deref of phydev
return phydev->drv->startup(phydev);
Thus, it would be better to fail at the driver probe and let u-boot
handle the rest (e.g. probe the driver again if needed), rather than
having access faults.
Signed-off-by: Andy Chiu <andy.chiu@sifive.com>
Reviewed-by: Greentime Hu <greentime.hu@sifive.com>
---
drivers/net/xilinx_axi_emac.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/net/xilinx_axi_emac.c b/drivers/net/xilinx_axi_emac.c
index dbda6c70d8..08322aff88 100644
--- a/drivers/net/xilinx_axi_emac.c
+++ b/drivers/net/xilinx_axi_emac.c
@@ -782,10 +782,16 @@ static int axiemac_setup_emac(struct udevice *dev)
ret = mdio_register_seq(priv->bus, dev_seq(dev));
if (ret)
- return ret;
+ goto fail;
- axiemac_phy_init(dev);
+ ret = axiemac_phy_init(dev);
+ if (ret)
+ goto fail_free_mdio;
+fail_free_mdio:
+ mdio_unregister(priv->bus);
+ mdio_free(priv->bus);
+fail:
return ret;
}
--
2.34.1
next prev parent reply other threads:[~2022-01-20 23:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-20 7:34 [PATCH 1/3] net: xilinx: fix load access fault Andy Chiu
2022-01-20 7:34 ` [PATCH 2/3] net: xilinx: Move setup of 1G MAC to a function Andy Chiu
2022-01-20 7:34 ` Andy Chiu [this message]
2022-02-09 13:33 ` [PATCH 3/3] net: xilinx: Force a probe failure if it cannot setup phy Andy Chiu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220120073420.1887809-3-andy.chiu@sifive.com \
--to=andy.chiu@sifive.com \
--cc=greentime.hu@sifive.com \
--cc=joe.hershberger@ni.com \
--cc=monstr@monstr.eu \
--cc=rfried.dev@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox