[PATCH master] mdio_bus: return 0xFFFF when read fails with error code

Ahmad Fatoum a.fatoum at pengutronix.de
Thu May 2 08:17:23 PDT 2024


phy_read may return an error code if the underlying transport
misbehaves, e.g. a busy and non-recoverable I2C bus.

Instead of packing the error code value into the buffer, let's just
report 0xFFFF, which is the natural value used for unresponsive PHYs,
due to the pull-ups.

We could instead also return an error code, but this brings us quite a
bit of complexity, because we would need to decide:

  - Either use an intermediary buffer and report an error code
    immediately

  - Return an incomplete count and assume that the error condition persists
    to the follow-up read, so it can return the error code

Take the easy way out and just report 0xFFFF, which is generally
understood to mean unresponsive PHY.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/net/phy/mdio_bus.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index eed7c779e753..30d5aeacff0d 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -472,12 +472,13 @@ int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val)
 
 static ssize_t phydev_read(struct cdev *cdev, void *_buf, size_t count, loff_t offset, ulong flags)
 {
-	int i = count;
+	int ret, i = count;
 	uint16_t *buf = _buf;
 	struct phy_device *phydev = cdev->priv;
 
 	while (i > 0) {
-		*buf = phy_read(phydev, offset / 2);
+		ret = phy_read(phydev, offset / 2);
+		*buf = ret >= 0 ? ret : 0xffff;
 		buf++;
 		i -= 2;
 		offset += 2;
-- 
2.39.2




More information about the barebox mailing list