mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH] net: phy: Fix get_phy_device return value
Date: Fri, 22 Nov 2013 15:55:15 +0100	[thread overview]
Message-ID: <1385132115-24179-1-git-send-email-s.hauer@pengutronix.de> (raw)

A function should either return an ERR_PTR or NULL on failure, but not both.
Let get_phy_device() return an ERR_PTR and fix the return checks in mdiobus_scan
and phy_device_connect.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/phy/mdio_bus.c | 2 +-
 drivers/net/phy/phy.c      | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 6163a50..87072be 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -82,7 +82,7 @@ struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)
 		return bus->phy_map[addr];
 
 	phydev = get_phy_device(bus, addr);
-	if (IS_ERR(phydev) || phydev == NULL)
+	if (IS_ERR(phydev))
 		return phydev;
 
 	bus->phy_map[addr] = phydev;
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index db00e38..2a33054 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -217,7 +217,7 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr)
 
 	/* If the phy_id is mostly Fs, there is no device there */
 	if ((phy_id & 0x1fffffff) == 0x1fffffff)
-		return NULL;
+		return ERR_PTR(-ENODEV);
 
 	dev = phy_device_create(bus, addr, phy_id);
 
@@ -254,7 +254,7 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
 	if (!edev->phydev) {
 		if (addr >= 0) {
 			dev = mdiobus_scan(bus, addr);
-			if (!dev) {
+			if (IS_ERR(dev)) {
 				ret = -EIO;
 				goto fail;
 			}
@@ -273,7 +273,7 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
 					continue;
 
 				dev = mdiobus_scan(bus, i);
-				if (!dev || dev->attached_dev)
+				if (IS_ERR(dev) || dev->attached_dev)
 					continue;
 
 				dev->attached_dev = edev;
@@ -304,7 +304,7 @@ int phy_device_connect(struct eth_device *edev, struct mii_bus *bus, int addr,
 	return 0;
 
 fail:
-	if (dev)
+	if (!IS_ERR(dev))
 		dev->attached_dev = NULL;
 	puts("Unable to find a PHY (unknown ID?)\n");
 	return ret;
-- 
1.8.4.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

                 reply	other threads:[~2013-11-22 14:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1385132115-24179-1-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@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