mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Wolfram Sang <w.sang@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 1/3] net: miidev: check for errors when accessing bus in restart_aneg
Date: Wed, 21 Mar 2012 12:18:43 +0100	[thread overview]
Message-ID: <1332328725-29753-2-git-send-email-w.sang@pengutronix.de> (raw)
In-Reply-To: <1332328725-29753-1-git-send-email-w.sang@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
---
 drivers/net/miidev.c |   29 +++++++++++++++++++++++------
 1 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/drivers/net/miidev.c b/drivers/net/miidev.c
index d721aac..83b6fe9 100644
--- a/drivers/net/miidev.c
+++ b/drivers/net/miidev.c
@@ -30,13 +30,14 @@
 
 int miidev_restart_aneg(struct mii_device *mdev)
 {
-	uint16_t status;
-	int timeout;
+	int status, timeout;
 
 	/*
 	 * Reset PHY, then delay 300ns
 	 */
-	mii_write(mdev, mdev->address, MII_BMCR, BMCR_RESET);
+	status = mii_write(mdev, mdev->address, MII_BMCR, BMCR_RESET);
+	if (status)
+		return status;
 
 	if (mdev->flags & MIIDEV_FORCE_LINK)
 		return 0;
@@ -45,8 +46,14 @@ int miidev_restart_aneg(struct mii_device *mdev)
 
 	if (mdev->flags & MIIDEV_FORCE_10) {
 		printf("Forcing 10 Mbps ethernet link... ");
+
 		status = mii_read(mdev, mdev->address, MII_BMSR);
-		mii_write(mdev, mdev->address, MII_BMCR, BMCR_FULLDPLX | BMCR_CTST);
+		if (status < 0)
+			return status;
+
+		status = mii_write(mdev, mdev->address, MII_BMCR, BMCR_FULLDPLX | BMCR_CTST);
+		if (status)
+			return status;
 
 		timeout = 20;
 		do {	/* wait for link status to go down */
@@ -56,6 +63,8 @@ int miidev_restart_aneg(struct mii_device *mdev)
 				break;
 			}
 			status = mii_read(mdev, mdev->address, MII_BMSR);
+			if (status < 0)
+				return status;
 		} while (status & BMSR_LSTATUS);
 
 	} else {	/* MII100 */
@@ -63,10 +72,18 @@ int miidev_restart_aneg(struct mii_device *mdev)
 		 * Set the auto-negotiation advertisement register bits
 		 */
 		status = mii_read(mdev, mdev->address, MII_ADVERTISE);
+		if (status < 0)
+			return status;
+
 		status |= ADVERTISE_ALL;
-		mii_write(mdev, mdev->address, MII_ADVERTISE, status);
 
-		mii_write(mdev, mdev->address, MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART);
+		status = mii_write(mdev, mdev->address, MII_ADVERTISE, status);
+		if (status)
+			return status;
+
+		status = mii_write(mdev, mdev->address, MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART);
+		if (status)
+			return status;
 	}
 
 	return 0;
-- 
1.7.9.1


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

  reply	other threads:[~2012-03-21 11:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-21 11:18 [PATCH 0/3] miidev: improve phy initialization Wolfram Sang
2012-03-21 11:18 ` Wolfram Sang [this message]
2012-03-21 11:18 ` [PATCH 2/3] net: miidev: Refactor timeout for aneg Wolfram Sang
2012-03-21 11:18 ` [PATCH 3/3] net: miidev: properly check for MII reset Wolfram Sang
2012-03-23  7:23 ` [PATCH 0/3] miidev: improve phy initialization Sascha Hauer

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=1332328725-29753-2-git-send-email-w.sang@pengutronix.de \
    --to=w.sang@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