๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25173

Re: [PATCH net-next v3 1/2] net: phy: motorcomm: add led_brightness_set for YT8521

#25173
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 10:58
166 lines
13438 bytes
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.

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
Technical Details
Message-ID: <179612268917.3146.3443593330313080426@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374951-linux-kernel-netdev=dewy.ru
References: <20261130100001.3346131-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!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374951-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v3 1/2] net: phy: motorcomm: add
 led_brightness_set for YT8521
Date: Tue, 01 Dec 2026 10:58:09 +0000
Organization: Usenet Network
Message-ID: <179612268917.3146.3443593330313080426@kernel.org>
References: <20261130100001.3346131-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="1690699"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:sqVT6Q2j7XQM/emP30tcxb4a+Tk= sha256:5nh3UEhuOCAzlyA5tU+vmJLGEkyYVsPEgLXvd+KSuLY=
	sha1:PRf7QerC52r3OqOg1Hh4BIhfQh0= sha256:TS4pRAXgmmqOPC5PXR/2/rNO2Mj4AhFeKKXWjoo2HV0=
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 8DF72117338; Tue,  1 Dec 2026 13:58:32 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31
	tests=[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]
	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 o1CqsCystV2J;
	Tue,  1 Dec 2026 13:58:28 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-374951-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 454FF1172E0; Tue,  1 Dec 2026 13:58:19 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 6A7296020E6; Tue,  1 Dec 2026 10:58:18 +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=1796122696;
	b=lmEiKraZlae3UD6DEpt8wyNiCtrwAffWhrYsGVdc7NjfvjClroMrqivUoPQ16atwTKgQ
	 qs2wJW0QcuJlKEkSmf85d26wWQ2hlKvCj8pPiH8fCzTk+pqfA0Ju10lDIfQV0fqUm5NJq
	 KfK6mSwQi2hNp+7FwpaHIhlepVdeG/kQUmxDMbl2Lcac6Gg6zuHoOO8VWLgZOj7qh+wDv
	 YbIJZjxxMtmI62oxopxu5or3tKBFikB4ts5dVNcsZcUgDU9dcInYf/1iXwkmwvneGimt2
	 kssNaoElvESE+w2NWc86CZUuBxn/t598l7nkowXLXa6qpdSjDvQrO0KSXpl2subx7Ow==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796122696;
	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=bSmfPF7oW7fA1FVgfIxizgN6vFA9Xh37YnDfJqXCdbI=;
	b=o/20SDw1FGpEhRCexk9Mwi/WnuwJPMK+hImyOYShhbv3L9MWCrWh7/rin0Dwk787TOWy
	 Pe16miDaUBpuxZxSrdizLc7fLfMXUEbdDJfF17Rc3pSiL21dfzG9ukrm7raG5blzM53Yk
	 9LLUAPNWbeycGw35dSMnKcnoym/UVqkTHiNOJAd0NgijecdzpeoUrngFWPWzVw7pWFXUf
	 /mGU+qNXVShheWzgj/0H7LbROfI4KXYECFuG1q8PacocPf90laB2SJUYRm/rpVIyAxSTh
	 BQmkGxysdkpGWhjVzzjsNfy+y1LzJEY2nMlHmtx1Yfas+VqcGrBaAz/ZJwSrWfyBdhA==
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=Vkz8CPfJ;
	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 609F5606A331;
	Tue,  1 Dec 2026 10:58:16 +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=Vkz8CPfJ
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=1796122690;
	b=I87xb+vjabaPPlVbLmbX51Atn/XLBDWPhAZFaswRPwsh9UvkESd/eXOYpcrNzxi6bKgq
	 Y9dotiTVraH//Az2TPwcEXRrooGtf0Q+EONss2hE9Gbr06AePCx4gb0Z+MFb5liZQWHwb
	 QWpJheN4awj4D9JK1tVQ6JPEx+lLb01Wpp09i8bCAzKNVU6pvXBidHfvgrHT/+VRPjc78
	 u/HcwRJB9yWG06OsEzZzkwY43o6ef9e99bgRSYIYOpDJt6AqCq7YtjsLKZ+wxWOwnUwxC
	 5T+KOBTvCBtXpV2QmBFwmj6wCm9BlN4cwwQUck4vP9u8iNcaH/ZqamknoAYoDQVyhhw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796122690;
	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=bSmfPF7oW7fA1FVgfIxizgN6vFA9Xh37YnDfJqXCdbI=;
	b=Ass+aa3tikHlixfuy8JaAmekqBTOSbAUs3z2Ob3xGDuqiEhhhKloTwt82kn00CzhylSU
	 PxrqzCqxmn5Zd3MD8UP3rSInjK7RdBx5cMgcLk7H2zWUB0PT61i9pBCQ7cV29QAOnZJyZ
	 +opeV9iyXJqMmM4IoG/L5snOpv3pHGh/Lrx9BbcMzH6wNA0N+AZx9yIKOjGjuh3nxbTIK
	 9RQcdpdFMA36n3BB9lFrXeEzEP55ka6Awg8Ghb3Fnvyn/hvr2eA/nX/lS9JpkspdYxm95
	 eecx0cbLlrhTIM2Ceg6ypys6iykqKBrMDuiz8wZGDpeMTS2pRpO7f77HmMqdnSSR8ag==
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=Vkz8CPfJ;
	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 7CEEA606A320;
	Tue,  1 Dec 2026 10:58:10 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8A2D1F00893;
	Tue,  1 Dec 2026 10:58:09 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796122690;
	bh=bSmfPF7oW7fA1FVgfIxizgN6vFA9Xh37YnDfJqXCdbI=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=Vkz8CPfJSPbPzf3uk69DYIFPMg7HS9Vi6gyD402zxKdq4H2WyXtDyQyK+K6DSM3VX
	 CAoH0Ob74Yd7towF1qlWtQ9Y28vaICRi/5K74ucOgh8q4eVU2trUHf4gVQRzLQSWtq
	 UMByW4wzhlXyrED/XpxeBkjBgYBmqWJn7+RAmvgXXDDps5P1r406R1tCKFQWJgFhqA
	 oIzCMEhhpF4PjqnbxmTLMHMLzh26FqXTd7/X1+poEz9bjgE8IyaJxvgE24c2a5VdS/
	 VJNoLZX9d2d4lYqbnyUHn232JM07G6vc6FD9Pu6lXZe4A2lrCPQYv/ily6c4BTb2Qy
	 Y5PVcQh4iHjSA==
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: <20261130100001.3346131-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