an8811hb_check_crc() ignores the return value of its PBUS reads. When the status read fails, the loop tests a stale or uninitialized pbus_value and can stop waiting before the check has finished. When the result read fails, the PASS or FAIL message tests the status value. en8811h_print_fw_version() also ignores a failed read, which leaves priv->firmware_version at 0 on the first firmware load, or when the bootloader's running firmware is kept. en8811h_read_status() then handles it as firmware older than 24011202 and guesses the link partner's 2.5GBASE-T ability from the link speed. Return the error from each of these reads. A failed version read now fails the firmware load or the probe, as the other PBUS errors there do. Found by an AI code review agent; not triggered. Compile-tested with W=1. Signed-off-by: Zhao Li --- v3: - move the comment above the phydev_dbg() it describes, as agreed on the v2 thread v2: https://lore.kernel.org/netdev/20261120062001.38233-1-enderaoelyther@gmail.com/ - retarget to net-next, drop the Fixes: and Cc: stable tags (Andrew Lunn) - also check the version read in en8811h_use_running_fw(), added in net-next by 89f0fb60afdb v1: https://lore.kernel.org/netdev/20261118182436.32455-1-enderaoelyther@gmail.com/ No new W=1, sparse or smatch warnings. drivers/net/phy/air_en8811h.c | 45 +++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/drivers/net/phy/air_en8811h.c b/drivers/net/phy/air_en8811h.c index ef20b41ed5cb..01a8ce85acb9 100644 --- a/drivers/net/phy/air_en8811h.c +++ b/drivers/net/phy/air_en8811h.c @@ -378,18 +378,26 @@ static int an8811hb_check_crc(struct phy_device *phydev, u32 set1, AN8811HB_CRC_RD_EN); if (ret < 0) return ret; - air_phy_buckpbus_reg_read(phydev, set1, &pbus_value); + ret = air_phy_buckpbus_reg_read(phydev, set1, &pbus_value); + if (ret < 0) + return ret; do { msleep(300); - air_phy_buckpbus_reg_read(phydev, mon2, &pbus_value); + ret = air_phy_buckpbus_reg_read(phydev, mon2, &pbus_value); + if (ret < 0) + return ret; - /* We do not know what errors this check is supposed - * catch or what to do about a failure. So print the - * result and continue like the vendor driver does. - */ if (pbus_value & AN8811HB_CRC_ST) { - air_phy_buckpbus_reg_read(phydev, mon3, &pbus_value); + ret = air_phy_buckpbus_reg_read(phydev, mon3, + &pbus_value); + if (ret < 0) + return ret; + + /* We do not know what errors this check is supposed + * catch or what to do about a failure. So print the + * result and continue like the vendor driver does. + */ phydev_dbg(phydev, "CRC Check %s!\n", pbus_value & AN8811HB_CRC_CHECK_PASS ? "PASS" : "FAIL"); @@ -403,14 +411,20 @@ static int an8811hb_check_crc(struct phy_device *phydev, u32 set1, return -ENODEV; } -static void en8811h_print_fw_version(struct phy_device *phydev) +static int en8811h_print_fw_version(struct phy_device *phydev) { struct en8811h_priv *priv = phydev->priv; + int ret; + + ret = air_phy_buckpbus_reg_read(phydev, EN8811H_FW_VERSION, + &priv->firmware_version); + if (ret < 0) + return ret; - air_phy_buckpbus_reg_read(phydev, EN8811H_FW_VERSION, - &priv->firmware_version); phydev_info(phydev, "MD32 firmware version: %08x\n", priv->firmware_version); + + return 0; } static int an8811hb_load_file(struct phy_device *phydev, const char *name, @@ -527,7 +541,10 @@ static int en8811h_use_running_fw(struct phy_device *phydev, int err) if (status != EN8811H_PHY_READY) return err; - en8811h_print_fw_version(phydev); + status = en8811h_print_fw_version(phydev); + if (status < 0) + return status; + return 1; } @@ -575,7 +592,7 @@ static int en8811h_load_firmware(struct phy_device *phydev) if (ret < 0) goto en8811h_load_firmware_out; - en8811h_print_fw_version(phydev); + ret = en8811h_print_fw_version(phydev); en8811h_load_firmware_out: release_firmware(fw2); @@ -1179,7 +1196,9 @@ static int an8811hb_probe(struct phy_device *phydev) goto err_dev_create; } - en8811h_print_fw_version(phydev); + ret = en8811h_print_fw_version(phydev); + if (ret < 0) + goto err_dev_create; /* mcu has just restarted after firmware load */ priv->mcu_needs_restart = false; base-commit: eb6d6c80d35449c27471b1874f13066c09a8964d -- 2.56.1