Re: [PATCH net-next v6 2/4] r8169: hold MDIO bus lock while loading firmware

From: netdev-bot+sashiko

Date: Fri Dec 04 2026 - 21:59:29 EST


Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The patch "r8169: hold MDIO bus lock while loading firmware"
fixes a race that is already in mainline, but the commit message…

--

r8169: hold MDIO bus lock while loading firmware

This patch takes the MDIO bus lock around rtl_fw_write_firmware() in
r8169_apply_firmware(). The firmware loader accesses PHY registers
directly and bypasses phylib. The lock is skipped on PHY-less parts where
tp->phydev is NULL.

> diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
> index f151ab6813932..b9068957ffa4f 100644
> --- a/drivers/net/ethernet/realtek/r8169_main.c
> +++ b/drivers/net/ethernet/realtek/r8169_main.c
> @@ -2686,9 +2686,14 @@ void r8169_apply_firmware(struct rtl8169_private *tp)
>
> /* TODO: release firmware if rtl_fw_write_firmware signals failure. */
> if (tp->rtl_fw) {
> + /* Keep phylib users (hwmon) off the bus meanwhile. */
> + if (tp->phydev)
> + phy_lock_mdio_bus(tp->phydev);
> rtl_fw_write_firmware(tp, tp->rtl_fw);

[Severity: Low]
Can this race already be hit in mainline? If so, should the commit carry
a Fixes: tag?

The "Realtek Internal NBASE-T PHY" entry uses rtl822x_probe(). When
CONFIG_REALTEK_PHY_HWMON is enabled, that function registers a hwmon
device for the internal PHY:

drivers/net/phy/realtek/realtek_main.c:rtl822x_probe() {
...
if (IS_ENABLED(CONFIG_REALTEK_PHY_HWMON) &&
phydev->phy_id != RTL_GENERIC_PHYID)
return rtl822x_hwmon_init(phydev);
...
}

That code came in with:

33700ca45b7d ("net: phy: realtek: add hwmon support for temp sensor on RTL822x")

A hwmon sysfs read takes only the MDIO bus lock, not RTNL:

rtl822x_hwmon_read()
phy_read_mmd(phydev, MDIO_MMD_VEND2, ...)
r8169_mdio_read_reg_c45()
r8168_phy_ocp_read()

r8168_phy_ocp_read() writes the address to GPHY_OCP and then reads the
data back from the same register.

Before this patch, rtl_fw_write_firmware() drove GPHY_OCP through
r8168g_mdio_read() and r8168g_mdio_write() without holding that lock. It
runs during ifup, reset work and resume.

If a sensor read overlaps the firmware load, could the PHY_READ,
PHY_DATA_OR/AND and PHY_WRITE_PREVIOUS sequences read from or write to the
wrong PHY register? Could hwmon also report a wrong temperature?

The new comment names hwmon as the competing user. The commit message
does not say that the race exists today or what users see when it hits.
The later patches in the series do not add a Fixes: tag either, so
kernels that already have the hwmon support (v6.14 and later) would not
pick this up. Would a tag like this be appropriate?

Fixes: 33700ca45b7d ("net: phy: realtek: add hwmon support for temp sensor on RTL822x")

Could this also go to net on its own, instead of as part of the RTL8127a
PTP series?

> /* At least one firmware doesn't reset tp->ocp_base. */
> tp->ocp_base = OCP_STD_PHY_BASE;
> + if (tp->phydev)
> + phy_unlock_mdio_bus(tp->phydev);

[ ... ]

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204021116.66-1-javen_xu%40realsil.com.cn