mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: willemb@google.com
To: netdev-bot+sashiko@kernel.org, amadeus@jmu.edu.cn
Cc: Frank.Sae@motor-comm.com, andrew@lunn.ch, pabeni@redhat.com,
	 kuba@kernel.org, edumazet@kernel.org, davem@davemloft.net,
	 hkallweit1@gmail.com, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org
Subject: Re: [PATCH net-next v3 1/2] net: phy: motorcomm: add led_brightness_set for YT8521
Date: Thu, 03 Dec 2026 23:43:46 -0500	[thread overview]
Message-ID: <willemb.1cf443602c3cb@google.com> (raw)
In-Reply-To: <179612268917.3146.3443593330313080426@kernel.org>

netdev-bot+sashiko@ wrote:
> 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.

Please respond to this sashiko finding


> 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/20261130100001.3346131-1-amadeus%40jmu.edu.cn



  reply	other threads:[~2026-12-04  4:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 10:00 Chukun Pan
2026-11-30 10:00 ` [PATCH net-next v3 2/2] net: phy: motorcomm: add missing trigger link " Chukun Pan
2026-12-01 10:58   ` netdev-bot+sashiko
2026-11-30 13:17 ` [PATCH net-next v3 1/2] net: phy: motorcomm: add led_brightness_set " Andrew Lunn
2026-12-01 10:58 ` netdev-bot+sashiko
2026-12-04  4:43   ` willemb [this message]
2026-12-04  6:50   ` Chukun Pan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=willemb.1cf443602c3cb@google.com \
    --to=willemb@google.com \
    --cc=Frank.Sae@motor-comm.com \
    --cc=amadeus@jmu.edu.cn \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®