From: netdev-bot+sashiko@kernel.org
To: 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 v2 1/2] net: phy: motorcomm: add led_brightness_set for YT8521
Date: Tue, 24 Nov 2026 10:39:15 +0000 [thread overview]
Message-ID: <179551675530.3135.11557257875706105488@kernel.org> (raw)
In-Reply-To: <20261120100001.1568757-1-amadeus@jmu.edu.cn>
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · Low: 2
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 callbacks in drivers/net/phy/motorcomm.c reach
extended registers through the unlocked helpers…
- [Medium] yt8521_hw_led_on_set() may program only part of what looks
like a 2-bit per-LED force-mode field in YTPHY_LED_GENERAL_CFG_REG…
- [Low] The patch adds a force state in YTPHY_LED_GENERAL_CFG_REG, but
yt8521_led_hw_control_get() still reads only YT8521_LEDx_CFG_REG (line…
- [Low] The commit message body says only 'Add support for manual
brightness setting on YT8521/YT8531 PHY.' It does not mention that the…
--
net: phy: motorcomm: add led_brightness_set for YT8521
This adds a led_brightness_set callback for the YT8521 and YT8531 PHYs.
The callback clears the per-LED hardware control config. It then turns the
LED on or off with the force bits in the LED general config register
(0xA00B). It also makes yt8521_led_hw_control_set() clear those force bits
before it programs the trigger rules.
> net: phy: motorcomm: add led_brightness_set for YT8521
>
> Add support for manual brightness setting on YT8521/YT8531 PHY.
> Testing with on/off and heartbeat on the Radxa E20C (YT8531).
[Severity: Low]
This isn't a bug, but the subject only names YT8521. The callback is added
to both the YT8521 and YT8531 entries in motorcomm_phy_drvs.
The body also doesn't mention that yt8521_led_hw_control_set() now clears
the force-enable and force-mode bits in YTPHY_LED_GENERAL_CFG_REG. Before
this patch the hw-control path never touched 0xA00B, so any force state
left by firmware or a bootloader stayed in place.
The only mention is the v2 changelog line "Clear force led status in
led_hw_control_set()". That line is below the --- separator, so it will be
dropped when the patch is applied.
Could the body describe this change as well?
> diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
> index a87e83fdf590c..5a0cd4d7d6336 100644
> --- a/drivers/net/phy/motorcomm.c
> +++ b/drivers/net/phy/motorcomm.c
> @@ -271,6 +271,10 @@
> */
> #define YTPHY_WCR_TYPE_PULSE BIT(0)
>
> +#define YTPHY_LED_GENERAL_CFG_REG 0xA00B
> +#define YTPHY_LED_FORCE_MODE(x) BIT((x) * 3)
> +#define YTPHY_LED_FORCE_EN(x) BIT((x) * 3 + 2)
[Severity: Medium]
Is the force mode field really one bit wide? Each LED gets a 3-bit slot
here, but bit x*3+1 (bits 1, 4 and 7) is never defined or touched. That
layout looks like a 2-bit force_mode field at [x*3+1:x*3] next to a 1-bit
force_en.
If so, yt8521_hw_led_on_set() only ORs in BIT(x*3) | BIT(x*3+2):
mask = YTPHY_LED_FORCE_EN(index) | YTPHY_LED_FORCE_MODE(index);
if (value)
reg = val | mask;
The resulting forced mode would then depend on whatever bit x*3+1 already
held. If firmware or a bootloader left that bit set, would brightness on
program mode 0b11 instead of solid on? The LED would then show a different
pattern from what sysfs reports.
I couldn't confirm the field layout from in-tree documentation. Should the
whole mode field be masked and set explicitly?
[ ... ]
> @@ -1775,6 +1779,43 @@ 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 mask, reg, val;
> +
> + 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);
> + if (value)
> + reg = val | mask;
> + else
> + reg = val & ~mask;
> +
> + 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 for these extended register accesses? The
kernel-doc for both helpers says:
drivers/net/phy/motorcomm.c:ytphy_read_ext() / ytphy_write_ext()
* NOTE:The caller must have taken the MDIO bus lock.
But the PHY LED core only holds phydev->lock when it calls the callback:
drivers/net/phy/phy_device.c:phy_led_set_brightness() {
...
mutex_lock(&phydev->lock);
err = phydev->drv->led_brightness_set(phydev, phyled->index, value);
mutex_unlock(&phydev->lock);
...
}
So the call chain is:
led_set_brightness()
phy_led_set_brightness() <- phydev->lock only
yt8521_led_brightness_set()
ytphy_write_ext(LEDx_CFG)
__phy_write()
yt8521_hw_led_on_set()
ytphy_read_ext(0xA00B)
ytphy_write_ext(0xA00B)
Won't __mdiobus_read() and __mdiobus_write() hit
lockdep_assert_held_once(&bus->mdio_lock) the first time the brightness
changes?
Without the bus lock, the 0x1E page select and 0x1F data accesses can also
interleave with other users of the same bus. Examples are other PHYs being
polled by the state machine, phy_mii_ioctl(), and phy_select_page() or the
_with_lock helpers. Could a write then land in the wrong extended register,
or a read return another register's value? Software blink triggers like
heartbeat call this path repeatedly, so the window keeps reopening.
The read-modify-write of 0xA00B in yt8521_hw_led_on_set() is not atomic
either. Can a concurrent update of the force bits for another LED index be
lost?
The existing hw_control_set/get callbacks already used the unlocked
helpers. This patch adds a new unlocked callback, and also a new unlocked
read-modify-write in yt8521_led_hw_control_set(). The follow-up commit "net:
phy: motorcomm: add missing trigger link for YT8521" doesn't address this,
since it only changes yt8521_led_hw_control_get().
Would it work to take phy_lock_mdio_bus() and phy_unlock_mdio_bus() around
the whole LED operation (both the 0xA00B update and the LEDx_CFG write),
rather than locking each access separately?
> static const unsigned long supported_trgs = (BIT(TRIGGER_NETDEV_FULL_DUPLEX) |
> BIT(TRIGGER_NETDEV_HALF_DUPLEX) |
> BIT(TRIGGER_NETDEV_LINK) |
> @@ -1801,10 +1842,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: Low]
This clears the force bits when hw_control_set() runs. Does it run when the
netdev trigger is activated over an LED that was forced on?
Take this sequence. With trigger "none", brightness is set to 1.
yt8521_led_brightness_set() writes LEDx_CFG = 0 and sets FORCE_EN and
FORCE_MODE in 0xA00B.
Then "netdev" is written to the trigger. __led_trigger_set() only turns
the LED off when an old trigger is being removed:
drivers/leds/led-triggers.c:__led_trigger_set() {
...
if (trig || !hw_triggered)
led_set_brightness(led_cdev, LED_OFF);
}
...
}
That code sits inside the if (led_cdev->trigger) block, so it doesn't run
when going from "none" to "netdev".
netdev_trig_activate() then sets trigger_data->hw_control = true and calls
set_device_name(), which skips the baseline state during activation:
drivers/leds/trigger/ledtrig-netdev.c:set_device_name() {
...
if (!trigger_data->hw_control || led_get_trigger_data(trigger_data->led_cdev))
set_baseline_state(trigger_data);
...
}
So yt8521_led_hw_control_set() is never called, and the force bits stay
set. yt8521_led_hw_control_get() only reads YT8521_LED0_CFG_REG + index,
which is 0, so it reports no rules.
The trigger then believes the LED is offloaded with no rules, while the
hardware keeps it forced on. This lasts until a NETDEV_UP or NETDEV_CHANGE
event, or a mode attribute change.
Other PHY drivers such as marvell end up in a similar hw_control state
here. This driver only reaches it because the patch adds the force mode.
Should yt8521_led_hw_control_get() take the 0xA00B force bits into account?
> if (test_bit(TRIGGER_NETDEV_LINK, &rules)) {
> val |= YT8521_LED_10_ON_EN;
> val |= YT8521_LED_100_ON_EN;
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120100001.1568757-1-amadeus%40jmu.edu.cn
prev parent reply other threads:[~2026-11-24 10:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 10:00 [PATCH v2 1/2] net: phy: motorcomm: add led_brightness_set for YT8521 Chukun Pan
2026-11-20 10:00 ` [PATCH v2 2/2] net: phy: motorcomm: add missing trigger link " Chukun Pan
2026-11-24 10:39 ` netdev-bot+sashiko
2026-11-21 16:57 ` [PATCH v2 1/2] net: phy: motorcomm: add led_brightness_set " Andrew Lunn
2026-11-24 6:50 ` Chukun Pan
2026-11-24 10:39 ` netdev-bot+sashiko [this message]
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=179551675530.3135.11557257875706105488@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--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@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