netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>,
	David Miller <davem@davemloft.net>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: [PATCH net-next v2 2/4] net: phy: warn if phy_start is called from invalid state
Date: Sun, 20 Jan 2019 10:02:13 +0100	[thread overview]
Message-ID: <cc566aa7-27cd-67fb-ea4b-00ee84d3dd7b@gmail.com> (raw)
In-Reply-To: <36a3f6a9-7f4c-7d51-05aa-71e847132102@gmail.com>

phy_start() should be called from states PHY_READY or PHY_HALTED only.
Check for this to detect misbehaving drivers. Also the state machine
should be started only when being called from one of the valid states.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/phy/phy.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 3df6aadc5..fd928979b 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -861,9 +861,16 @@ void phy_start(struct phy_device *phydev)
 
 	mutex_lock(&phydev->lock);
 
+	if (phydev->state != PHY_READY && phydev->state != PHY_HALTED) {
+		WARN(1, "called from state %s\n",
+		     phy_state_to_str(phydev->state));
+		goto out;
+	}
+
 	switch (phydev->state) {
 	case PHY_READY:
 		phydev->state = PHY_UP;
+		phy_start_machine(phydev);
 		break;
 	case PHY_HALTED:
 		/* if phy was suspended, bring the physical link up again */
@@ -877,13 +884,13 @@ void phy_start(struct phy_device *phydev)
 		}
 
 		phydev->state = PHY_RESUMING;
+		phy_start_machine(phydev);
 		break;
 	default:
 		break;
 	}
+out:
 	mutex_unlock(&phydev->lock);
-
-	phy_start_machine(phydev);
 }
 EXPORT_SYMBOL(phy_start);
 
-- 
2.20.1



  parent reply	other threads:[~2019-01-20  9:05 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-20  8:59 [PATCH net-next v2 0/4] net: phy: improve starting PHY Heiner Kallweit
2019-01-20  9:01 ` [PATCH net-next v2 1/4] net: phy: start state machine in phy_start only Heiner Kallweit
2019-01-21 16:35   ` Andrew Lunn
2019-01-21 18:36     ` Heiner Kallweit
2019-01-21 18:42       ` Andrew Lunn
2019-01-21 21:52         ` Heiner Kallweit
2019-01-21 23:55           ` Andrew Lunn
2019-01-22 14:46       ` Lendacky, Thomas
2019-01-22 19:09         ` Heiner Kallweit
2019-01-23  2:50           ` S-k, Shyam-sundar
2019-01-20  9:02 ` Heiner Kallweit [this message]
2019-01-21 16:40   ` [PATCH net-next v2 2/4] net: phy: warn if phy_start is called from invalid state Andrew Lunn
2019-01-21 18:25     ` Heiner Kallweit
2019-01-21 18:29       ` Andrew Lunn
2019-01-21 18:30         ` Heiner Kallweit
2019-01-20  9:03 ` [PATCH net-next v2 3/4] net: phy: start interrupts in phy_start Heiner Kallweit
2019-01-20  9:05 ` [PATCH net-next v2 4/4] net: phy: change phy_start_interrupts to phy_request_interrupt Heiner Kallweit
2019-01-22 22:50 ` [PATCH net-next v2 0/4] net: phy: improve starting PHY David Miller

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=cc566aa7-27cd-67fb-ea4b-00ee84d3dd7b@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=netdev@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).