🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27072

[PATCH net] net: phy: motorcomm: Take the MDIO bus lock in the YT8521 LED callbacks

#27072
From: Praneeth Balasubramanian
Date: Fri, 04 Dec 2026 18:49
72 lines
14001 bytes
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
Technical Details
Message-ID: <20261204184945.1687040-1-praneethb2002@gmail.com>
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.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-377555-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.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-377555-linux-kernel-netdev=dewy.ru
From: praneethb2002@gmail.com (Praneeth Balasubramanian)
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <20261204184945.1687040-1-praneethb2002@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2835054"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Hp1vniq4//qXOURRVyJ1j4ePLzI= sha256:qTAwLd87xXLS19p/PhtpUeelqvlCih7qTGSRuZIOQCU=
	sha1:weDn+IjckROWvuHCymKcOFPiow0= sha256:dqVzIp8rjI5SxsOgUaLDELWitD8ZDy8qcZn8oSG5RWo=
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 C7625117C9C; Fri,  4 Dec 2026 21:50:05 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.397
X-Spam-Status: No, score=-3.397 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
	HEADER_FROM_DIFFERENT_DOMAINS=0.001, 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=gmail.com
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 u0J66AbF7TSY;
	Fri,  4 Dec 2026 21:50:03 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-377555-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 3D2A5117C99; Fri,  4 Dec 2026 21:49:55 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 5399B27128; Fri,  4 Dec 2026 18:49:53 +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=1796410192;
	b=BC4LQh44F/hLbbVb0/FMKy/jpWaWPhSuiiGK2NOL3sBMNcygN8bUl0xgN6ytolQl2Sty
	 QWJpoSpme31cqElYZCWlLZaykuOnvt2twO1iVQ1K3OjqzEJuf0eZ3/V7276fZpn+v0Ku+
	 ILc5KiYL7Fk2l+F1Mjwa8wdbdA2vmYF1avtAcips4lmgxWmPNgJXGZ4ooC3q2WkBHr2j+
	 HtSpTb8SN3DlHoy5vC9ekMOQW0l2i5HXMoRx4Liq8UwqRRdekZWYsq3lZFP8iUDOukV0Q
	 oJ8U68EsRLUS2/HppVfvembKUEy8QBLyy/evi/q+8SV/TNC3jwO5HcDCd1qPb4xiLdA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796410192;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
	 X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:Date:Message-Id:
	 X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=jbpkT2DME7pJRvLdnsaQg9oX/+NyPZ+MCkYdeUxNjW4=;
	b=02T7qDeb/hzD1ARP4rP5ksFpBkDIBbMsuYySNm9uqUvLX29QmiP4otmBttatYS9rwbMe
	 VhE6yzFJrhqNYXCmerbcli7xXxaumWir8qtb4Oa2NY7h+SecGIuyLjgRWJatREyC7hDpB
	 ZQEtTyukrxixRKYTwurelDDYdEk8oQFKkcQa+kqdi6OUWyat65hVQS+U/sKYnyGRmkZgL
	 BsfVw0LzQUghQ65PQ3k8ndtVqOKzIZiZOZpFGCkA+0mgFIN0GyS6jx4YG/fM+58+YrrQQ
	 Mn71wELBdg4OWtl7vIxRqxW+G7dSnSKYSsoD61A909el0v0JjC6YRDsLUROZDPZzIbQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=0JLquSWn;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	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 71DE7606A33B;
	Fri,  4 Dec 2026 18:49:52 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=0JLquSWn
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.170
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796410191;
	b=rYzJrCB9qyKmlzUTB/vJ0RK1jGldLT3prG9Nh9lSHtgn6bQmhtu6GMjLlTuxns/Lf0AP
	 ALd1k532xVrtKbf5B6DAbN83OCF5an6xwt3OS9fejEQXKvpuQ4WZwm14UGXlbh9oe1+PN
	 FZod1EL0bJv4m1aeh8SrtIajeBB46FzYWLZk2jn87z0Eli12OFjqT5ry2bG8woWzeODl6
	 SCfnWqOJKoYXkzKhYXmpzk/8NrstWG+TWQVbT7uL81a9M3Xr/UUa7tsywjPxtKTsfYmol
	 HIfHfAN+GaOTi8QPl96WxAK0fh2RCtc05TO7pi1zzzi0o8nh1hr2YusF4YXT7i0vr/A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796410191;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
	 From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version:
	 Content-Transfer-Encoding;
	bh=jbpkT2DME7pJRvLdnsaQg9oX/+NyPZ+MCkYdeUxNjW4=;
	b=kfzCkDgSlAY+MVmbf1Y6rpyevgUV9sJB8yNq30HBWSLaUFBEgqWrgwqb6Wjek7AbUpzm
	 YR+hopYAhkGn/zTtBIOhokar9ryyU88xm6/Az3eDbNlV2r0GHnJNQlF+uCy0VaxORVbjZ
	 GkBQJu0ahRN62oASjxengRaJ+GgjKu6qkvSK0DIIM4Nfemd2J/01IxZp09EZz5v7ebF1d
	 3ixjY5KpfRsdxQFBR81+mN6vKDbS2U7DeVGRuMz9MLW95trNbHihfnw0ID8KTRknfMqgc
	 gaMTERE1n9s0DHz+0ugKBd6Ft5h5w7XjVJYoF9PSBwGlJPJMSud+kBsf5XR+V+eKi0Q==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=0JLquSWn;
	arc=none smtp.remote-ip=74.125.82.170
X-Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BEF0606A322
	for <netdev@vger.kernel.org>; Fri,  4 Dec 2026 18:49:51 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3BEF0606A322
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-386ab9ab619so2070245eec.1
        for <netdev@vger.kernel.org>; Fri, 04 Dec 2026 10:49:51 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1796410190; x=1797014990; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
        bh=jbpkT2DME7pJRvLdnsaQg9oX/+NyPZ+MCkYdeUxNjW4=;
        b=0JLquSWnZADYjNaFH/IttNSFB6Hm9jXMtSbUPK9BjyqKMVWyUKwzkLogKMEWuXrrWH
         81VQWfgZOXFPrGTs6Ej4jEzArL6CymTqPdo9zD1kvs6uJaXfjkomImmeZ5IoN5Rs7bpZ
         R/Jl8TvAG1BhEuqvkt2qfsiIYPrkEfEXweUffFc1gs+53pAtdojnR4SWgu0Ha31Ph9v0
         PmD0wcZA1QYbHFIQW2NOuyLAPHtVwgJd3m02ZQYcIjlabZcyy2qYHGtzyIlX+ev/608o
         SWmfrlICGYVUGBsFdeShtSwK4ECz9vyO/ZCqUUVE5KVpOgvKp1qkZsC8sZmvp6XLYkIU
         t9yw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1796410190; x=1797014990;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=jbpkT2DME7pJRvLdnsaQg9oX/+NyPZ+MCkYdeUxNjW4=;
        b=fruXoEQ0crrqOt7onMLl57L4ymMsu4EKQhyPpo02q9N3/884vojBK8eB8Oky952yHN
         pFXvZufc1J4gvCNe7LpIcf/DqgpqTEdV/OsNswHhfkrbBBVfoExvNmGD2SQuGMdPJHYz
         2+Gq8jCsVMINLPNw3MVufAW6KdAFYJLGm3uwomE8hlhsGWctHSzjUuOrPo9BSQPlu1T2
         k7TG0+Ii2wgtNFxsKaw17tB9nReWSlSuoEY+0sHCVUNO7ejLRgy4vXGHLvaJDaCNhyRY
         Ye0X5r69vHdQtDDYkdQmguMNe7alFw6kj/CwwA2dVc4eOOwR9EnCmTfJtPVfWbKKsao+
         ITDA==
X-Forwarded-Encrypted: i=1; AL+hErFqZaPh61OGVYL0XtMSHotGgFVDq5rCRxgRTG4vEHSeiLFH3uhdi0/ERdKRhZnJPVI2lxWyDZ4=@vger.kernel.org
X-Gm-Message-State: AB4q+uHo7LOwMnP1b3HwZ3Tu44bm7RRGTSArDLSlnwE/BtYFzO+jC7oS
	IcQfJ/8Jc9fZVkqUVp/UuZUwqvinck3midhVXaWrqL37YEmkEB+/XR4q
X-Gm-Gg: AZFdTZfe3kSlIwp8v4fw0syafjNN/JCA8T5cao+2sX964vkAeVXU2JnVviDHEIda6Ne
	yJBPC1SynrMPWZ4gOaAjEBIQjgO5sUNOr5G1F185kic+z9FnnSwuKJ1qAVGKX7G1lcJH7FTH5T+
	fhL4bYS+GZHz/mQKXTVF5h35kK6LThrYfg7pysZloFQMWPl69X6ok48/Ac8Jqk+UuXVwOlT9Wgf
	IHsvf4SMCUZGjhwIkJ/4Aew3hpJJCmOnLQophRgYFbwKjWQY4Kkv+bZN2BzQ9n149GFTyGtzM8Q
	YnDAFHOPQtiiIsMXlvDzG90oCZcp0QVDCglddxV82svAxgf7rj9w55Zv3DY8Ttwq3I2+jfrodWe
	biwB6fVq34FaRVmOCvu3/KRQpIkFxTTYk5MbN0GLaPX/8lLQk1qkLJmdXdgs6gEhlwVX+oR8ibG
	N1Zcxup+t/yAsNkXo9cXwVHrvkjwoZkkVJr+nzUvY3fZLDBknfeNXsqP+wP8P7E1Z5F7Rw1/oiP
	q6hmYH60HtTM7RV9itSlX3zcMLgzesP4HJmwIfDBbCGibZHvnJXLcv2u6Jli+NxLFFykbUSx8wv
	EAqqbBtzBgaTw2ZlRzpcQmfcYNqiuiiRvO3PegtcohVVekx1+BGs+63u6Mt8pJ+xvth47hf+vMe
	JikPZkw2PaVhu
X-Received: by 2002:a05:7300:cf0f:b0:387:4e5c:397d with SMTP id 5a478bee46e88-387520afa0emr2718310eec.11.1796410190387;
        Fri, 04 Dec 2026 10:49:50 -0800 (PST)
X-Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37])
        by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3875218c6a6sm10321963eec.5.2026.12.04.10.49.49
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Fri, 04 Dec 2026 10:49:50 -0800 (PST)
X-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
X-Mailer: git-send-email 2.25.1
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