Skip to content

Commit 13d0ab6

Browse files
hkallweitdavem330
authored andcommitted
net: phy: check return code when requesting PHY driver module
When requesting the PHY driver module fails we'll bind the genphy driver later. This isn't obvious to the user and may cause, depending on the PHY, different types of issues. Therefore check the return code of request_module(). Note that we only check for failures in loading the module, not whether a module exists for the respective PHY ID. v2: - add comment explaining what is checked and what is not - return error from phy_device_create() if loading module fails Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 01cb8a1 commit 13d0ab6

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

drivers/net/phy/phy_device.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,12 +546,31 @@ static const struct device_type mdio_bus_phy_type = {
546546
.pm = MDIO_BUS_PHY_PM_OPS,
547547
};
548548

549+
static int phy_request_driver_module(struct phy_device *dev, int phy_id)
550+
{
551+
int ret;
552+
553+
ret = request_module(MDIO_MODULE_PREFIX MDIO_ID_FMT,
554+
MDIO_ID_ARGS(phy_id));
555+
/* we only check for failures in executing the usermode binary,
556+
* not whether a PHY driver module exists for the PHY ID
557+
*/
558+
if (IS_ENABLED(CONFIG_MODULES) && ret < 0) {
559+
phydev_err(dev, "error %d loading PHY driver module for ID 0x%08x\n",
560+
ret, phy_id);
561+
return ret;
562+
}
563+
564+
return 0;
565+
}
566+
549567
struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
550568
bool is_c45,
551569
struct phy_c45_device_ids *c45_ids)
552570
{
553571
struct phy_device *dev;
554572
struct mdio_device *mdiodev;
573+
int ret = 0;
555574

556575
/* We allocate the device, and initialize the default values */
557576
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
@@ -608,15 +627,21 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
608627
if (!(c45_ids->devices_in_package & (1 << i)))
609628
continue;
610629

611-
request_module(MDIO_MODULE_PREFIX MDIO_ID_FMT,
612-
MDIO_ID_ARGS(c45_ids->device_ids[i]));
630+
ret = phy_request_driver_module(dev,
631+
c45_ids->device_ids[i]);
632+
if (ret)
633+
break;
613634
}
614635
} else {
615-
request_module(MDIO_MODULE_PREFIX MDIO_ID_FMT,
616-
MDIO_ID_ARGS(phy_id));
636+
ret = phy_request_driver_module(dev, phy_id);
617637
}
618638

619-
device_initialize(&mdiodev->dev);
639+
if (!ret) {
640+
device_initialize(&mdiodev->dev);
641+
} else {
642+
kfree(dev);
643+
dev = ERR_PTR(ret);
644+
}
620645

621646
return dev;
622647
}

0 commit comments

Comments
 (0)