mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: a.shimko.dev@gmail.com
Cc: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, robh@kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, maxime.chevallier@bootlin.com, pavel@ucw.cz,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-leds@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH net-next v4 3/3] net: phy: dap8211r: add PHY LED control support
Date: Mon, 23 Nov 2026 13:19:43 +0000	[thread overview]
Message-ID: <179543998366.3135.8537500779592480863@kernel.org> (raw)
In-Reply-To: <20261122131900.2951586-4-a.shimko.dev@gmail.com>

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

  parent reply	other threads:[~2026-11-23 13:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 13:18 [PATCH net-next v4 0/3] net: phy: dap8211r: add " Artem Shimko
2026-11-22 13:18 ` [PATCH net-next v4 1/3] net: phy: dap8211r: fix kernel-doc comments for extended register helpers Artem Shimko
2026-11-22 13:18 ` [PATCH net-next v4 2/3] dt-bindings: net: dptel,dap8211r: add LED nodes Artem Shimko
2026-11-23 13:19   ` netdev-bot+sashiko
2026-11-23 16:03     ` Artem Shimko
2026-11-22 13:18 ` [PATCH net-next v4 3/3] net: phy: dap8211r: add PHY LED control support Artem Shimko
2026-11-22 15:29   ` Andrew Lunn
2026-11-23 13:19   ` netdev-bot+sashiko [this message]
2026-11-23 16:24     ` Artem Shimko

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=179543998366.3135.8537500779592480863@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=a.shimko.dev@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=maxime.chevallier@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pavel@ucw.cz \
    --cc=robh@kernel.org \
    /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®