🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21708

Re: [PATCH v2 1/2] net: phy: motorcomm: add led_brightness_set for YT8521

#21708
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 10:39
249 lines
16965 bytes
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
Technical Details
Message-ID: <179551675530.3135.11557257875706105488@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!193.141.40.65.MISMATCH!npeer.as286.net!npeer-ng0.as286.net!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370238-linux-kernel-netdev=dewy.ru
References: <20261120100001.1568757-1-amadeus@jmu.edu.cn>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!193.141.40.65.MISMATCH!npeer.as286.net!npeer-ng0.as286.net!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370238-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v2 1/2] net: phy: motorcomm: add led_brightness_set for YT8521
Date: Tue, 24 Nov 2026 10:39:15 +0000
Organization: Usenet Network
Message-ID: <179551675530.3135.11557257875706105488@kernel.org>
References: <20261120100001.1568757-1-amadeus@jmu.edu.cn>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="4113788"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:W8AN81wuVLVK0vkVTW+CK0IyCBQ= sha256:b4Ncw0J+U/oqp2QLI03uOqQQ0nmlukCUCKdh5uITLWw=
	sha1:+NGFI9mmz8+jD7+VP0OI9gCQZ+w= sha256:EfxVjalttjvWgj/vr65yyGZKowi9/9ZW5ZluhKURznk=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id EA3BB125DF3; Tue, 24 Nov 2026 13:39:40 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id usyK9zxd4nDI;
	Tue, 24 Nov 2026 13:39:37 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-370238-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id BDF76125DF2; Tue, 24 Nov 2026 13:39:28 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 737C9389CC; Tue, 24 Nov 2026 10:39:24 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795516763;
	b=m0cHKRpXoIRbamkg7hY+4/n8mqVG8jZ5Ta7IHp2klbVkuNIsYwIkRHfoxjF111YuMJWW
	 ZbuYV4TLPW31MBx/zr9qdpV0FGb1Mg6/TIqT97FKXH/FWK2iBwPF8BdnL3NGuqNfYd3OH
	 4ZXoTPLltGstZx7a15G9qadFg7Dc6DcHA1QyoiiurCmVYTemeVDkBR+A1chFLw4MBfBAE
	 gxRcEugMAXmch1WmY9+OSXkDNuNnilHUE7lFkFK11F5/TFxoUGBF1L1mOXBkwA/S1E9FC
	 KcfgahB7e/5V6c9BbpmSniSCV1cQDkQEPmqvLycEqcD7xteHYjrB19ShPb4p0paIS4Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795516763;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=nI4e52Acf1U0twvafLH3l00NdIpteq82nRKqiYLBaok=;
	b=CZZ+JGXljkC3vLwc6/YywypaBO5dEOcnvamIiXk+rDaNGmMQVEGp707dgF41EH0eq950
	 GjfMYVXu310rNXzAdIbXqm4iSL57L94S4HuP5QljidNPOlmtaAv5Qh6G2oNxgzDKWcUR/
	 LeP3x5i9H8krb6l1DlbfawtCQqgdKy7YID7RkGg/LKk54rWZ1QEay7hLgmRfcJ0MMgt0a
	 EJCgJhOXVBdgmvB74hXy/s2ly6o0PFNtQVb2iojV27NxsRzPjlKiHVHtald3bPlxlX49r
	 cpgo84HA5YI6GTFvBvTfO7SXU1cPy9xJ893CgAR/a1+UXVz0w9w6MH9RymMmLr/BHkA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=iazj78Bl;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 59B12606A33E;
	Tue, 24 Nov 2026 10:39:23 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=iazj78Bl
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795516756;
	b=dS7CJnCgRz9rFKZIZqPMhbQaTyoMUaRNNyWblyz/U5K9XAIySv49vho2D5pQwCReY+i7
	 KD3PDz8zBJlVYQSvHj8LNXmvcIBEqz9WJjK4soE+Hy7b6lEsq2GX75nB0NhqrJ5nnnbMO
	 VIIMmgyBjO7kqWrye2Zu/z06TjZ9BL/z+v+bkci/xPSu9CFZfN5EwJyaX4J3QPECLMkYf
	 WrYIJCoB6yEsWTu12qvo9kTAM1DEIVL1BE8LXKqiWzkQHaSIq1naNl10ass0xMdXcFuSj
	 uMZnLZjyjuO30okqHGJktcWwJYtFXgmMuEqGj6hMSWA1KV1GlF8AgEAkQIIssjFQhAw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795516756;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=nI4e52Acf1U0twvafLH3l00NdIpteq82nRKqiYLBaok=;
	b=0jEsCcfd0ATcKZgjOtDiYwMdsl0K75OyDmb/yLT3fU1LFazd4WnK48WSGDPLHYRHv1zb
	 xMllLzDX7n5HUHsweCyXjmGCb5NcZeq9opp76qV/trbJC0ttdKRt9KkpBWQsUxY9ISAPi
	 JLVaih+Lf6oXMDEAhsZNQmqfJQ+PX2Aib+mjKq9LXZH/43yiZPXKgNhh3F+8kCeOzIYv7
	 oR2vicN1nUOvnFITrOzSxSopDLyvfeVO6M1FVcmIstF/Qu7sQZi3h+JVO6DmmlVT7jOVw
	 6CJVuOh9hQXR8kcK7+zWoxPcllesaHEzp3f6NCBGZ1Fn/0Dlvat8F3XTGQqSYnW4iZw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=iazj78Bl;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC6B4606A31E;
	Tue, 24 Nov 2026 10:39:16 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C09DE1F000C0;
	Tue, 24 Nov 2026 10:39:15 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795516756;
	bh=nI4e52Acf1U0twvafLH3l00NdIpteq82nRKqiYLBaok=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=iazj78BldilxlvS+8TC6x9EdeBTBGmshZKF3EPuo7949rvJOLL0rRH64akv2UvcNC
	 gIUOSiHxZVVniMtrHgvdGNAmDEuE2wqY6BTS19kc7oiXP1qpznm61q4/D26rzRXOMk
	 D6oZaXhM4NqI2GgnxLMssGjz83W7FDWVz3ycIX1rI+GTG0Es9mNiqdqPCBGSt/2+yp
	 I0WjWrUn0MjppAduTrhd//Q8zPGYOmROiGsmd7xIIwzYXiU6PAsAZyVYzgdllesGTq
	 FosVPdkq0hzJ8FFxUwMuPdWBY2hvRKK7p4KJvsepIonw4PNOaGKQ1b/CAIg1ayzBfp
	 H0sQUVpHXnSEQ==
X-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
X-In-Reply-To: <20261120100001.1568757-1-amadeus@jmu.edu.cn>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list