From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/3] net: dsa: ksz9477: return negative error codes on PHY access failures
Date: Thu, 2 May 2024 17:17:57 +0200 [thread overview]
Message-ID: <20240502151757.3964461-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240502151757.3964461-1-a.fatoum@pengutronix.de>
The ksz register accessors return a negative error code if the
underlying transport, e.g. i2c, fails. We need to propagate this error
code, instead of reporting incorrect data.
For the case a PHY doesn't exist, reads on a physical bus return 0xFFFF
due to the pull-ups on the MDIO line, so we leave that as is.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/net/ksz9477.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ksz9477.c b/drivers/net/ksz9477.c
index 5c5f4ec8d995..950eb89c09c2 100644
--- a/drivers/net/ksz9477.c
+++ b/drivers/net/ksz9477.c
@@ -29,12 +29,15 @@ static int ksz9477_phy_read16(struct dsa_switch *ds, int addr, int reg)
{
struct device *dev = ds->dev;
struct ksz_switch *priv = dev_get_priv(dev);
- u16 val = 0xffff;
+ int ret;
+ u16 val;
if (addr >= priv->phy_port_cnt)
- return val;
+ return 0xffff;
- ksz_pread16(priv, addr, 0x100 + (reg << 1), &val);
+ ret = ksz_pread16(priv, addr, 0x100 + (reg << 1), &val);
+ if (ret)
+ return ret;
return val;
}
@@ -52,9 +55,8 @@ static int ksz9477_phy_write16(struct dsa_switch *ds, int addr, int reg,
/* No gigabit support. Do not write to this register. */
if (!(priv->features & GBIT_SUPPORT) && reg == MII_CTRL1000)
return 0;
- ksz_pwrite16(priv, addr, 0x100 + (reg << 1), val);
- return 0;
+ return ksz_pwrite16(priv, addr, 0x100 + (reg << 1), val);
}
static int ksz9477_switch_detect(struct ksz_switch *priv)
--
2.39.2
next prev parent reply other threads:[~2024-05-02 15:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-02 15:17 [PATCH 1/3] net: dsa: ksz9477: always toggle reset gpio if available Ahmad Fatoum
2024-05-02 15:17 ` [PATCH 2/3] net: dsa: ksz9477: report 0 as value when returning error Ahmad Fatoum
2024-05-02 15:17 ` Ahmad Fatoum [this message]
2024-05-02 15:19 ` [PATCH 1/3] net: dsa: ksz9477: always toggle reset gpio if available Ahmad Fatoum
2024-05-03 6:50 ` Sascha Hauer
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=20240502151757.3964461-3-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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