All of lore.kernel.org
 help / color / mirror / Atom feed
From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Frank <Frank.Sae@motor-comm.com>,
	Jijie Shao <shaojijie@huawei.com>,
	Chukun Pan <amadeus@jmu.edu.cn>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Praneeth Balasubramanian <praneethb2002@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH net] net: phy: motorcomm: Take the MDIO bus lock in the YT8521 LED callbacks
Date: Fri,  4 Dec 2026 10:49:45 -0800	[thread overview]
Message-ID: <20261204184945.1687040-1-praneethb2002@gmail.com> (raw)

ytphy_read_ext() and ytphy_write_ext() access an extended register by
writing its number to YTPHY_PAGE_SELECT and then reading or writing
YTPHY_PAGE_DATA. Their comments say that the caller must hold the MDIO
bus lock, so that no other access to the PHY lands between the two
steps. yt8521_led_hw_control_set() and yt8521_led_hw_control_get() call
them without it: phy_led_hw_control_set() and phy_led_hw_control_get()
only hold phydev->lock.

Another user of the bus, for example a WoL query through
ytphy_read_ext_with_lock() or a register access from the MAC driver, can
then change the selected extended register in between. The LED
configuration is then written to a different register, or read from
one.

Use ytphy_read_ext_with_lock() and ytphy_write_ext_with_lock(), as the
rest of the driver does outside locked sections.

This was discovered by a static analysis tool: Clang context analysis
checking the locking rule in the comments of ytphy_read_ext() and
ytphy_write_ext() (an LLM was used to turn the comments into rules). The
netdev AI review later pointed out the same problem as pre-existing on
the YT8521 led_brightness_set series. The issue was not triggered, and
the fix was only build-tested.

Fixes: 355b82c54c12 ("net: phy: motorcomm: Add support for PHY LEDs on YT8521")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---

Notes:
    This was found by a compiler-based check, part of research at UCSB SecLab.
    The locking rule stated in the kernel-doc comment of the called function
    was turned into a Clang context-analysis requirement (__must_hold) on that
    function, and Clang 23 with CONFIG_WARN_CONTEXT_ANALYSIS then checked every
    caller. An LLM was used only to turn the comment into a machine-readable
    rule; the report itself comes from the compiler. The patch and changelog
    were drafted with Claude Opus 5.5. I reviewed the patch and take
    responsibility for it.
    
    Testing: builds without new warnings with W=1 (x86_64, clang 23,
    allmodconfig). Not runtime-tested; I do not have this hardware, and I
    have not observed the race myself.

 drivers/net/phy/motorcomm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
index a87e83fdf590..b109b160d681 100644
--- a/drivers/net/phy/motorcomm.c
+++ b/drivers/net/phy/motorcomm.c
@@ -1836,7 +1836,8 @@ static int yt8521_led_hw_control_set(struct phy_device *phydev, u8 index,
 	if (test_bit(TRIGGER_NETDEV_RX, &rules))
 		val |= YT8521_LED_RXACT_BLK_EN;
 
-	return ytphy_write_ext(phydev, YT8521_LED0_CFG_REG + index, val);
+	return ytphy_write_ext_with_lock(phydev, YT8521_LED0_CFG_REG + index,
+					 val);
 }
 
 static int yt8521_led_hw_control_get(struct phy_device *phydev, u8 index,
@@ -1847,7 +1848,7 @@ static int yt8521_led_hw_control_get(struct phy_device *phydev, u8 index,
 	if (index >= YT8521_MAX_LEDS)
 		return -EINVAL;
 
-	val = ytphy_read_ext(phydev, YT8521_LED0_CFG_REG + index);
+	val = ytphy_read_ext_with_lock(phydev, YT8521_LED0_CFG_REG + index);
 	if (val < 0)
 		return val;
 
-- 
2.25.1


                 reply	other threads:[~2026-12-04 18:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261204184945.1687040-1-praneethb2002@gmail.com \
    --to=praneethb2002@gmail.com \
    --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=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shaojijie@huawei.com \
    --cc=stable@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.