net: phy: Fix not to call phy_resume() if PHY is not attached
authorYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Wed, 28 Nov 2018 09:02:41 +0000 (09:02 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Jan 2020 09:24:04 +0000 (10:24 +0100)
[ Upstream commit ef1b5bf506b1f0ee3edc98533e1f3ecb105eb46a ]

This patch fixes an issue that mdio_bus_phy_resume() doesn't call
phy_resume() if the PHY is not attached.

Fixes: 803dd9c77ac3 ("net: phy: avoid suspending twice a PHY")
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/phy/phy_device.c

index 3289fd910c4a6604c8704b55a3c1b22fbe361806..487d0372a44411cc43c21f9c62e37f8b85f94261 100644 (file)
@@ -80,7 +80,7 @@ static LIST_HEAD(phy_fixup_list);
 static DEFINE_MUTEX(phy_fixup_lock);
 
 #ifdef CONFIG_PM
-static bool mdio_bus_phy_may_suspend(struct phy_device *phydev)
+static bool mdio_bus_phy_may_suspend(struct phy_device *phydev, bool suspend)
 {
        struct device_driver *drv = phydev->mdio.dev.driver;
        struct phy_driver *phydrv = to_phy_driver(drv);
@@ -92,10 +92,11 @@ static bool mdio_bus_phy_may_suspend(struct phy_device *phydev)
        /* PHY not attached? May suspend if the PHY has not already been
         * suspended as part of a prior call to phy_disconnect() ->
         * phy_detach() -> phy_suspend() because the parent netdev might be the
-        * MDIO bus driver and clock gated at this point.
+        * MDIO bus driver and clock gated at this point. Also may resume if
+        * PHY is not attached.
         */
        if (!netdev)
-               return !phydev->suspended;
+               return suspend ? !phydev->suspended : phydev->suspended;
 
        /* Don't suspend PHY if the attached netdev parent may wakeup.
         * The parent may point to a PCI device, as in tg3 driver.
@@ -125,7 +126,7 @@ static int mdio_bus_phy_suspend(struct device *dev)
        if (phydev->attached_dev && phydev->adjust_link)
                phy_stop_machine(phydev);
 
-       if (!mdio_bus_phy_may_suspend(phydev))
+       if (!mdio_bus_phy_may_suspend(phydev, true))
                return 0;
 
        return phy_suspend(phydev);
@@ -136,7 +137,7 @@ static int mdio_bus_phy_resume(struct device *dev)
        struct phy_device *phydev = to_phy_device(dev);
        int ret;
 
-       if (!mdio_bus_phy_may_suspend(phydev))
+       if (!mdio_bus_phy_may_suspend(phydev, false))
                goto no_resume;
 
        ret = phy_resume(phydev);