Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider. Critical: 0 · High: 1 (1) · Medium: 0 · Low: 0 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [High] The new LED brightness path reaches the PHY's extended registers without holding the MDIO bus lock. Pre-existing issues: - [High] This problem wasn't introduced by this patch, but the existing LED hw_control callbacks have the same missing MDIO bus lock. -- net: phy: motorcomm: add led_brightness_set for YT8521 This commit adds a led_brightness_set callback for the YT8521 and YT8531 PHYs. The callback uses the force mode bits in the LED general config register (0xA00B). It also makes led_hw_control_set() clear force mode when switching to the netdev trigger.
> diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c > index a87e83fdf590c..e0c6477a53e44 100644 > --- a/drivers/net/phy/motorcomm.c > +++ b/drivers/net/phy/motorcomm.c
[ ... ]
> @@ -1775,6 +1779,44 @@ static int yt8531s_config_init(struct phy_device *phydev) > return phy_restore_page(phydev, old_page, ret); > } > > +static int yt8521_hw_led_on_set(struct phy_device *phydev, u8 index, > + bool value) > +{ > + int reg, val; > + u16 mask; > + > + val = ytphy_read_ext(phydev, YTPHY_LED_GENERAL_CFG_REG); > + if (val < 0) > + return val; > + > + mask = YTPHY_LED_FORCE_EN(index) | YTPHY_LED_FORCE_MODE(index); > + /* 0: force OFF, 1: force ON, same as the value */ > + reg = (val & ~mask) | (value << (index * 3)); > + if (value) > + reg |= YTPHY_LED_FORCE_EN(index); > + > + if (reg == val) > + return 0; > + > + return ytphy_write_ext(phydev, YTPHY_LED_GENERAL_CFG_REG, reg); > +} > + > +static int yt8521_led_brightness_set(struct phy_device *phydev, u8 index, > + enum led_brightness value) > +{ > + int ret; > + > + if (index >= YT8521_MAX_LEDS) > + return -EINVAL; > + > + /* clear HW LED setup */ > + ret = ytphy_write_ext(phydev, YT8521_LED0_CFG_REG + index, 0); > + if (ret < 0) > + return ret; > + > + return yt8521_hw_led_on_set(phydev, index, (value != LED_OFF)); > +}
[Severity: High] Is the MDIO bus lock held on this path? ytphy_read_ext() and ytphy_write_ext() are both documented with: * NOTE:The caller must have taken the MDIO bus lock. However, phy_led_set_brightness() in drivers/net/phy/phy_device.c only takes phydev->lock before it calls the driver: mutex_lock(&phydev->lock); err = phydev->drv->led_brightness_set(phydev, phyled->index, value); The call chain looks like this: phy_led_set_brightness() yt8521_led_brightness_set() ytphy_write_ext(phydev, YT8521_LED0_CFG_REG + index, 0) yt8521_hw_led_on_set() ytphy_read_ext(phydev, YTPHY_LED_GENERAL_CFG_REG) ytphy_write_ext(phydev, YTPHY_LED_GENERAL_CFG_REG, reg) __phy_read() / __phy_write() __mdiobus_read() / __mdiobus_write() lockdep_assert_held_once(&bus->mdio_lock); With CONFIG_LOCKDEP, wouldn't the first brightness change hit this assertion? That change can come from sysfs or from a software trigger such as heartbeat. Without the bus lock, the 0x1E page select and 0x1F data pairs here are not serialized against code that holds only the bus lock. That includes phy_mii_ioctl(), other devices on the same MDIO bus, and the ytphy_*_ext_with_lock() callers in suspend/resume. Could the page select change between the select and the data access? The write would then land in a different extended register, for example 0xA000 or the WoL config. A concurrent locked modify of 0xA00B could also be lost between the read and the write in yt8521_hw_led_on_set(). The new yt8521_hw_led_on_set() call in yt8521_led_hw_control_set() has the same problem, because phy_led_hw_control_set() also holds only phydev->lock. Would it work to take phy_lock_mdio_bus() once around the LEDx_CFG clear and the GENERAL_CFG read-modify-write? The later commit "net: phy: motorcomm: add missing trigger link for YT8521" only changes yt8521_led_hw_control_get(), so it does not fix this.
> @@ -1801,10 +1843,15 @@ static int yt8521_led_hw_control_set(struct phy_device *phydev, u8 index, > unsigned long rules) > { > u16 val = 0; > + int ret; > > if (index >= YT8521_MAX_LEDS) > return -EINVAL; > > + ret = yt8521_hw_led_on_set(phydev, index, false); > + if (ret < 0) > + return ret; > +
[Severity: High] This is a pre-existing issue and was not introduced by this patch. The existing LED hw_control callbacks also access the extended registers without the MDIO bus lock. The end of yt8521_led_hw_control_set() does: return ytphy_write_ext(phydev, YT8521_LED0_CFG_REG + index, val); and yt8521_led_hw_control_get() does: val = ytphy_read_ext(phydev, YT8521_LED0_CFG_REG + index); Both run with only phydev->lock held, taken by phy_led_hw_control_set() and phy_led_hw_control_get(). The netdev trigger path therefore has the same lockdep assertion and the same page select/data race. This patch copies that unlocked pattern into the new brightness path. If the locking gets fixed here, should the bus lock cover all of yt8521_led_hw_control_set(), including this final write, and also yt8521_led_hw_control_get()? [ ... ]
-- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/2026…%40jmu.edu.cn