[PATCH 1/2] miiphyutil: Fix inconsistent miiphy_write() error return value

Daniel Klauer
2022-02-09T15:41:30Z

miiphy_write() should not directly return the error return value from
bus->write(), because that is typically a -errno value, while generally
miiphy_write() and other miiphy_*() functions return 1 on error.
Some miiphy_write() callers only check for > 0 to detect errors.

Fix it to match miiphy_read(), which also converts bus->read() failure
to "return 1".

Signed-off-by: Daniel Klauer <daniel.klauer@gin.de>
---
common/miiphyutil.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/common/miiphyutil.c b/common/miiphyutil.c
index 7d4d15ed91..86a27665e3 100644
--- a/common/miiphyutil.c
+++ b/common/miiphyutil.c
@@ -236,7 +236,7 @@ static struct mii_dev *miiphy_get_active_dev(const char *devname)
* This API is deprecated. Use phy_read on a phy_device found via phy_connect
*
* Returns:
- * 0 on success
+ * 0 on success, 1 on error
*/
int miiphy_read(const char *devname, unsigned char addr, unsigned char reg,
unsigned short *value)
@@ -264,18 +264,23 @@ int miiphy_read(const char *devname, unsigned char addr, unsigned char reg,
* This API is deprecated. Use phy_write on a phy_device found by phy_connect
*
* Returns:
- * 0 on success
+ * 0 on success, 1 on error
*/
int miiphy_write(const char *devname, unsigned char addr, unsigned char reg,
unsigned short value)
{
struct mii_dev *bus;
+ int ret;

bus = miiphy_get_active_dev(devname);
- if (bus)
- return bus->write(bus, addr, MDIO_DEVAD_NONE, reg, value);
+ if (!bus)
+ return 1;

- return 1;
+ ret = bus->write(bus, addr, MDIO_DEVAD_NONE, reg, value);
+ if (ret < 0)
+ return 1;
+
+ return 0;
}

/*****************************************************************************
--
2.32.0