]> git.baikalelectronics.ru Git - kernel.git/commitdiff
r8169: fix PHY driver check on platforms w/o module softdeps
authorHeiner Kallweit <hkallweit1@gmail.com>
Fri, 27 Mar 2020 16:33:32 +0000 (17:33 +0100)
committerDavid S. Miller <davem@davemloft.net>
Fri, 27 Mar 2020 22:56:34 +0000 (15:56 -0700)
On Android/x86 the module loading infrastructure can't deal with
softdeps. Therefore the check for presence of the Realtek PHY driver
module fails. mdiobus_register() will try to load the PHY driver
module, therefore move the check to after this call and explicitly
check that a dedicated PHY driver is bound to the PHY device.

Fixes: e4387abf08c6 ("r8169: check that Realtek PHY driver module is loaded")
Reported-by: Chih-Wei Huang <cwhuang@android-x86.org>
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/realtek/r8169_main.c

index a9bdafd15a35a03695930ec2902ac8296b8e332f..791d99b9e1cf44f658924db44c6fa67b55a5cf79 100644 (file)
@@ -5285,6 +5285,13 @@ static int r8169_mdio_register(struct rtl8169_private *tp)
        if (!tp->phydev) {
                mdiobus_unregister(new_bus);
                return -ENODEV;
+       } else if (!tp->phydev->drv) {
+               /* Most chip versions fail with the genphy driver.
+                * Therefore ensure that the dedicated PHY driver is loaded.
+                */
+               dev_err(&pdev->dev, "realtek.ko not loaded, maybe it needs to be added to initramfs?\n");
+               mdiobus_unregister(new_bus);
+               return -EUNATCH;
        }
 
        /* PHY will be woken up in rtl_open() */
@@ -5446,15 +5453,6 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        int chipset, region;
        int jumbo_max, rc;
 
-       /* Some tools for creating an initramfs don't consider softdeps, then
-        * r8169.ko may be in initramfs, but realtek.ko not. Then the generic
-        * PHY driver is used that doesn't work with most chip versions.
-        */
-       if (!driver_find("RTL8201CP Ethernet", &mdio_bus_type)) {
-               dev_err(&pdev->dev, "realtek.ko not loaded, maybe it needs to be added to initramfs?\n");
-               return -ENOENT;
-       }
-
        dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp));
        if (!dev)
                return -ENOMEM;