diff mbox series

[03/11] net: phy: Check against net_device being NULL

Message ID 1558992127-26008-4-git-send-email-ioana.ciornei@nxp.com
State Changes Requested
Delegated to: David Miller
Headers show
Series Decoupling PHYLINK from struct net_device | expand

Commit Message

Ioana Ciornei May 27, 2019, 9:21 p.m. UTC
In general, we don't want MAC drivers calling phy_attach_direct with the
net_device being NULL. Add checks against this in all the functions
calling it: phy_attach() and phy_connect_direct().

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/net/phy/phy_device.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Andrew Lunn May 28, 2019, 3:50 p.m. UTC | #1
On Tue, May 28, 2019 at 12:21:59AM +0300, Ioana Ciornei wrote:
> In general, we don't want MAC drivers calling phy_attach_direct with the
> net_device being NULL. Add checks against this in all the functions
> calling it: phy_attach() and phy_connect_direct().
> 
> Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
> Suggested-by: Andrew Lunn <andrew@lunn.ch>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
Andrew Lunn May 28, 2019, 3:51 p.m. UTC | #2
On Tue, May 28, 2019 at 12:21:59AM +0300, Ioana Ciornei wrote:
> In general, we don't want MAC drivers calling phy_attach_direct with the
> net_device being NULL. Add checks against this in all the functions
> calling it: phy_attach() and phy_connect_direct().
> 
> Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
> Suggested-by: Andrew Lunn <andrew@lunn.ch>

I should actually say, once you fix the sparse warnings, you can add:

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
diff mbox series

Patch

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index da3bf3f70d63..0b7730fd41ba 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -948,6 +948,9 @@  int phy_connect_direct(struct net_device *dev, struct phy_device *phydev,
 {
 	int rc;
 
+	if (!dev)
+		return ERR_PTR(-EINVAL);
+
 	rc = phy_attach_direct(dev, phydev, phydev->dev_flags, interface);
 	if (rc)
 		return rc;
@@ -1307,6 +1310,9 @@  struct phy_device *phy_attach(struct net_device *dev, const char *bus_id,
 	struct device *d;
 	int rc;
 
+	if (!dev)
+		return ERR_PTR(-EINVAL);
+
 	/* Search the list of PHY devices on the mdio bus for the
 	 * PHY with the requested name
 	 */