public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH 1/2] miiphyutil: Fix inconsistent miiphy_write() error return value
@ 2022-02-09 15:32 Daniel Klauer
  2022-02-09 15:32 ` [PATCH 2/2] net: phy: mv88e6352: Fix miiphy_read/miiphy_write return value checks Daniel Klauer
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Klauer @ 2022-02-09 15:32 UTC (permalink / raw)
  To: u-boot

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-02-16 10:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-09 15:32 [PATCH 1/2] miiphyutil: Fix inconsistent miiphy_write() error return value Daniel Klauer
2022-02-09 15:32 ` [PATCH 2/2] net: phy: mv88e6352: Fix miiphy_read/miiphy_write return value checks Daniel Klauer
2022-02-12 11:50   ` Ramon Fried
2022-02-14 10:33     ` Daniel Klauer
2022-02-15  7:08       ` Ramon Fried
2022-02-16 10:52         ` Daniel Klauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox