]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
net: phy: Check against net_device being NULL
authorIoana Ciornei <ioana.ciornei@nxp.com>
Tue, 28 May 2019 17:38:09 +0000 (20:38 +0300)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
BugLink: https://bugs.launchpad.net/bugs/1839036
[ Upstream commit 82c76aca81187b3d28a6fb3062f6916450ce955e ]

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>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/net/phy/phy_device.c

index 9186fba35d148d4b037ab31c983ad1d8984095f3..9a72ec7be8efedce43651f2af5ad4ca8d6de9e05 100644 (file)
@@ -729,6 +729,9 @@ int phy_connect_direct(struct net_device *dev, struct phy_device *phydev,
 {
        int rc;
 
+       if (!dev)
+               return -EINVAL;
+
        rc = phy_attach_direct(dev, phydev, phydev->dev_flags, interface);
        if (rc)
                return rc;
@@ -1067,6 +1070,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
         */