Re: [PATCH net-next v4 3/3] net: phy: dap8211r: add PHY LED control support
From: netdev-bot+sashiko
Date: Mon Nov 23 2026 - 08:19:51 EST
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
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).
- [Medium] In drivers/net/phy/dap8211r.c, dap8211r_led_hw_control_get()
(lines 312-351) does not undo what dap8211r_led_hw_control_set()…
- [Low] dap8211r_led_hw_control_set() in drivers/net/phy/dap8211r.c first
clears FORCE_EN(index) in LED_COMCON (0xA00B) with…
--
net: phy: dap8211r: add PHY LED control support
This adds PHY LED support for the three LEDs on the DAP8211R. It adds a
dap8211r_write_ext() helper for indirect extended register writes. It also
implements the led_brightness_set, led_hw_is_supported, led_hw_control_set
and led_hw_control_get callbacks, using force mode for brightness and the
LED_x_CON registers for hardware triggers.
> diff --git a/drivers/net/phy/dap8211r.c b/drivers/net/phy/dap8211r.c
> index 1fe20efd394d7..b0fb3cf89b55a 100644
> --- a/drivers/net/phy/dap8211r.c
> +++ b/drivers/net/phy/dap8211r.c
[ ... ]
> +static int dap8211r_led_hw_control_set(struct phy_device *phydev, u8 index, unsigned long rules)
> +{
> + u16 led_mode = 0, led_reg;
> + int ret;
> +
> + switch (index) {
> + case DAP8211R_LED_ID_0 ... DAP8211R_LED_ID_2:
> + led_reg = DAP8211R_LED_0_CON + index;
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + ret = dap8211r_modify_ext(phydev, DAP8211R_LED_COMCON, DAP8211R_LED_FORCE_EN(index), 0);
> + if (ret)
> + return ret;
[Severity: Low]
Force mode is cleared in LED_COMCON here, but the new rules are only
written to LED_x_CON later by a separate dap8211r_write_ext() call. Each
helper takes and drops the MDIO bus lock on its own. In between, won't the
LED follow whatever LED_x_CON held before (power-on, bootloader, or
previous trigger rules)?
If the final dap8211r_write_ext() fails, the function returns an error but
leaves force mode off and the stale rules active. set_baseline_state() in
drivers/leds/trigger/ledtrig-netdev.c ignores the return value:
led_cdev->hw_control_set(led_cdev, trigger_data->mode);
so the trigger would assume the new mode is in effect.
Would it work to write LED_x_CON first and clear FORCE_EN afterwards? The
rule register has no visible effect while force mode is on.
> +
> + if (test_bit(TRIGGER_NETDEV_LINK, &rules))
> + led_mode |= DAP8211R_LED_LINK;
> +
[ ... ]
> + if (test_bit(TRIGGER_NETDEV_RX, &rules))
> + led_mode |= DAP8211R_LED_RX | DAP8211R_LED_ACT_BLINK;
> +
> + if (test_bit(TRIGGER_NETDEV_TX, &rules))
> + led_mode |= DAP8211R_LED_TX | DAP8211R_LED_ACT_BLINK;
> +
[ ... ]
> + return dap8211r_write_ext(phydev, led_reg, led_mode);
> +}
[ ... ]
> +static int dap8211r_led_hw_control_get(struct phy_device *phydev, u8 index, unsigned long *rules)
> +{
[ ... ]
> + led_mode = dap8211r_read_ext(phydev, led_reg);
> + if (led_mode < 0)
> + return led_mode;
> +
> + if (led_mode & DAP8211R_LED_LINK_10)
> + __set_bit(TRIGGER_NETDEV_LINK_10, rules);
> +
> + if (led_mode & DAP8211R_LED_LINK_100)
> + __set_bit(TRIGGER_NETDEV_LINK_100, rules);
> +
> + if (led_mode & DAP8211R_LED_LINK_1000)
> + __set_bit(TRIGGER_NETDEV_LINK_1000, rules);
> +
> + if (led_mode & DAP8211R_LED_RX)
> + __set_bit(TRIGGER_NETDEV_RX, rules);
> +
> + if (led_mode & DAP8211R_LED_TX)
> + __set_bit(TRIGGER_NETDEV_TX, rules);
> +
> + if (led_mode & DAP8211R_LED_HALF_DUPLEX)
> + __set_bit(TRIGGER_NETDEV_HALF_DUPLEX, rules);
> +
> + if (led_mode & DAP8211R_LED_FULL_DUPLEX)
> + __set_bit(TRIGGER_NETDEV_FULL_DUPLEX, rules);
> +
> + return 0;
> +}
[Severity: Medium]
Does dap8211r_led_hw_control_get() return the same rules that
dap8211r_led_hw_control_set() writes? I see three mismatches.
First, hw_control_set() turns TRIGGER_NETDEV_LINK into LINK_10 | LINK_100 |
LINK_1000. This function only reports the three speed bits and never
reports TRIGGER_NETDEV_LINK.
Second, hw_control_set() always sets DAP8211R_LED_ACT_BLINK along with
TX/RX, but bit 13 is never checked here. The kernel-doc on hw_control_set()
says the LED does not blink on traffic without ACT_BLINK unless another
rule is active. A register with TX/RX set, ACT_BLINK clear and no
link/duplex bit would still be reported as tx/rx offload.
Third, any other LED_x_CON bits are silently ignored, and 0 is returned
anyway.
The led_hw_control_get kernel-doc in include/linux/phy.h says:
Set *@rules to how the HW is currently blinking. Returns 0
on success, or a error code if the current blinking cannot
be represented in rules, or some other error happens.
Should this return an error when the register holds bits that cannot be
expressed as rules?
This matters because the netdev trigger reads the rules and then writes
them back:
netdev_trig_activate()
led_cdev->hw_control_get(led_cdev, &mode)
trigger_data->mode = mode
register_netdevice_notifier()
netdev_trig_notify(NETDEV_REGISTER)
set_baseline_state()
led_cdev->hw_control_set(led_cdev, trigger_data->mode)
hw_control_set() rebuilds led_mode from 0 and writes the whole register
with dap8211r_write_ext(), not a masked modify. Any hardware setting that
hw_control_get() could not express would then be lost just by activating
the trigger, for example via linux,default-trigger = "netdev".
In the ACT_BLINK case, the LED could start blinking on traffic when it did
not before. Whether this happens in practice depends on the power-on or
strap values of LED_x_CON.
In the LINK case, after the trigger is re-activated, sysfs would show
link=0 and link_10=link_100=link_1000=1. Writing link=1 is then rejected
with -EINVAL by this check in netdev_led_attr_store():
if (test_bit(TRIGGER_NETDEV_LINK, &mode) &&
(test_bit(TRIGGER_NETDEV_LINK_10, &mode) ||
test_bit(TRIGGER_NETDEV_LINK_100, &mode) ||
test_bit(TRIGGER_NETDEV_LINK_1000, &mode) ||
until the speed bits are cleared by hand.
rtl8211f_led_hw_control_get() in the realtek driver reports
TRIGGER_NETDEV_LINK when all three speed bits are set. Could the same
approach be used here?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122131900.2951586-1-a.shimko.dev%40gmail.com