public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Daniel Klauer <daniel.klauer@gin.de>
To: <u-boot@lists.denx.de>
Subject: [PATCH 1/2] miiphyutil: Fix inconsistent miiphy_write() error return value
Date: Wed, 9 Feb 2022 16:32:56 +0100	[thread overview]
Message-ID: <20220209153257.284853-1-daniel.klauer@gin.de> (raw)

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


             reply	other threads:[~2022-02-09 15:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-09 15:32 Daniel Klauer [this message]
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

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=20220209153257.284853-1-daniel.klauer@gin.de \
    --to=daniel.klauer@gin.de \
    --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