๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #8428

Re: [PATCH v3 1/7] net: dsa: mt7530: get ctrl phy addr using a function

#8428
From: netdev-bot+sashiko
Date: Thu, 29 Oct 2026 02:02
95 lines
11569 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The new helper mt753x_ctrl_phy_addr()
  (drivers/net/dsa/mt7530.c:49-57) handles a NULL priv->mdiodev byโ€ฆ
- [Low] The commit message says the control PHY is found by taking the
  switch's MDIO address, adding 1, and taking it "modulo 31".

--

net: dsa: mt7530: get ctrl phy addr using a function

This commit replaces the MT753X_CTRL_PHY_ADDR() macro with a
mt753x_ctrl_phy_addr() helper. The helper warns and returns 0 when
priv->mdiodev is NULL. It is also meant to give MMIO implementations a
place to supply their own control PHY address.

> The switch is typically on
> MDIO address 31 and the PHYs are 0, 1, 2, 3, and 4 with 0 being the
> special one. So taking the address of mdiodev (the switch) add 1 and
> modulo 31 finds the first PHY.

[Severity: Low]
Is "modulo 31" right here? The code computes:

    (priv->mdiodev->addr + 1) & (PHY_MAX_ADDR - 1)

PHY_MAX_ADDR is 32, so this masks with 31, which is modulo 32. For a
switch at address 31, (31 + 1) % 31 would give 1. The code gives 0,
which is the PHY the message calls the special one.

Should this say modulo 32, or say that it wraps around the 32-address
MDIO space?

> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
> index 7781a63b4e6fd..d10194488bdee 100644
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c
> @@ -46,6 +46,16 @@ static const struct mt7530_mib_desc mt7530_mib[] = {
>  	MIB_DESC(1, MT7530_PORT_MIB_RX_ARL_DROP, "RxArlDrop"),
>  };
>  
> +static int
> +mt753x_ctrl_phy_addr(struct mt7530_priv *priv)
> +{
> +	if (WARN_ON_ONCE(!priv->mdiodev))
> +		return 0;

[Severity: Low]
When priv->mdiodev is NULL, this returns 0. That is also a valid PHY
address, so callers can't tell the fallback from a real result.

At this commit, core_write() and core_rmw() then use priv->bus without
checking it:

    struct mii_bus *bus = priv->bus;
    ...
    ret = bus->write(bus, ctl_phy, MII_MMD_CTRL, MDIO_MMD_VEND2);

On MMIO devices, mt7988_probe() sets priv->bus = NULL and never sets
mdiodev. If the fallback were hit there, could the WARN be followed by a
NULL bus dereference in core_write() or core_rmw()?

In mt7531_setup(), the same fallback would send the CORE_PLL_GROUP4
write and the EEE advertisement writes to PHYs 0 to 4.

This doesn't look reachable at this commit. Every caller runs only for
MT7530/MT7621/MT7531, which are probed through mt7530-mdio.c and always
have both priv->bus and priv->mdiodev set.

Two later patches in the series also cover this:

  - "net: dsa: mediatek: support PLL setup on MMIO MT7530" adds a
    child_bus fallback and a WARN_ON_ONCE(!bus) check to core_write()
    and core_rmw().
  - "net: dsa: mediatek: support EN751221 switch" adds the EN751221
    special case to this helper.

That leaves a design question. Should the helper return an error for a
missing mdiodev, so callers can bail out instead of using address 0?

> +
> +	/* Default is 1st PHY */
> +	return (priv->mdiodev->addr + 1) & (PHY_MAX_ADDR - 1);
> +}
> +

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261028011317.1557238-1-cjd%40cjdns.fr
Technical Details
Message-ID: <179323935516.3134.4150149245635529305@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-353122-linux-kernel-netdev=dewy.ru
References: <20261028011317.1557238-2-cjd@cjdns.fr>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-353122-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v3 1/7] net: dsa: mt7530: get ctrl phy addr using a function
Date: Thu, 29 Oct 2026 02:02:35 +0000
Organization: Usenet Network
Message-ID: <179323935516.3134.4150149245635529305@kernel.org>
References: <20261028011317.1557238-2-cjd@cjdns.fr>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1915220"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:g76xzu7dTvfLCvPLxZGyaa7Skoo= sha256:dfJWZaRECvdnmKZDH21Vls1JXFb+l7HMRLqcxZw8eMc=
	sha1:pgFNHxHx6Yuz3cSgjrNzWmqGqTE= sha256:sWuoq5LyRfuIWDBEdx213517CmF/H+M3rqGBuWku/ks=
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 E572D125C4E; Thu, 29 Oct 2026 05:03:24 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 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] 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 eN7bI261HDlZ;
	Thu, 29 Oct 2026 05:03:21 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-353122-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 6FFDC125C44; Thu, 29 Oct 2026 05:03:11 +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 77BCA28D65; Thu, 29 Oct 2026 02:02:39 +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=1793239358;
	b=zN+i85o+9420OZk/tjkXCA4UrVSLm03wH3qmJZ9YxtC3Akx+xdUVufd3HBXZMypA8u1w
	 Z/ago+7nVii10WNjru+QkR0RkMzt4vgEOXsLW2qExqMTwbqocEvDtCh4ZjW5Y/5SLrLrQ
	 krFRTlM403eiB6vfqwoOobKsAzLJzQyThLeH4Q+RJB6aCs/2rvIL82moeuamLUg3gt6WM
	 2VpC5/4d+wCSess1FWExeVKUkBTp8CTJ5LgrTo0XVYr5GNTizMZiYY2BsaZXfln5L/mLE
	 KWKcvH5QBYkOsQOJagjfI5Z2wlhRpAnpNPbsFJUQu58KFLVNW4UJKlKzTltrbEs7nvQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793239358;
	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=ig9ryT9lQ5WH61asJrWLJKKAff4oOz6FkZcoxGtITzU=;
	b=0AXMiJUZYKQI1HuAdVEAVjCvyOodbX1rKAFoMSfaxgR0DB61fRcoUjptkFv1q2yl9K4Q
	 MeXogagiYfK1SlxfVaIQiNdWf10qV5Pq+PYe8zT9mlPmE5PFoWsYxIPGcU8qf9MtGkT5F
	 nPL3+v97W3T9xZtu5P2oylxoJEE5Ri5xJREfLJqjF3LOiSK35sckIIi7Uiaqv4gIA/8B6
	 MEdlGqnng8bJ5ZpXfFoiOEs4kgu8uXNVVrPV/WdqAUpTiFKkrk67occMdsk7jtJUI4U7+
	 MkNXe039aO3bcZfO3sD4fOpb7Dv30xRobNT6VpIQ4IB14gRimNVtI9TUHYJPFcCo0VA==
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=ZnxXNoL4;
	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 A8693606A331;
	Thu, 29 Oct 2026 02:02:38 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ZnxXNoL4
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=1793239357;
	b=06fN3//CcRgpZJ7x6QbFDm9ybGqKoHhkMtnS0AvudU6PPKz3F9giw9xrqUiPek9UlRqR
	 miuSE3t9i82eqgvoAlCnIPGnfnOYSJAvKULTKz39qNtxQvSJds6cRy8ckBxgQuTCq8ReR
	 lPgW0p9uSKrMTVzgkbKaMc10qJzVZBgGcTN51yxTnyKMuuNFjDxSkaSnYGhoIf5J7qKy/
	 5T8H0zpVSF0lVAkwpRSokovthT9ZSBrUSqVTkZAE+lCCIe5uKk7CS0FYrEQWRZcierknL
	 RRiHSlzx/mNQpPnkbngmOt2KLLHV7kfxy29c988rsditM+IeBv0oJSxclPUe4/zzT0Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793239357;
	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=ig9ryT9lQ5WH61asJrWLJKKAff4oOz6FkZcoxGtITzU=;
	b=PZ+MXqNfzj4l0Ecsi1manAjUE4zxa0h6gMDBi9UVqsWEnkMr3N2zxZXz56JmtOBMi6x8
	 7XUfwsxovi++kxbHBfCtVOpvBS90+QnASN7z1fuvrkOK8cq9cu4nuCB9KGkTxbpYOu1Ab
	 EBN7jz9Tyz+l7earnVj6vxoJYXxalmkqK0cvEMrGRvVcT2iPVfR/RU3gSjt8zIBv1UUxq
	 k6SUN9Vt+ictfK6uxn6etxHiojRxQ8ALZI7wI85kdVHQLb1kFCdgZ6rrtWPfyrmE957Jw
	 li7YdZNC7/QBYqNmIjy5WVtZYsVIC6+TXrBcFFQU8cUlXBDwOmO4ZS/MwmMvHxpJqzg==
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=ZnxXNoL4;
	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 86815606A320;
	Thu, 29 Oct 2026 02:02:37 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5ACB1F031E2;
	Thu, 29 Oct 2026 02:02:35 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793239357;
	bh=ig9ryT9lQ5WH61asJrWLJKKAff4oOz6FkZcoxGtITzU=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=ZnxXNoL4Q40oWbzyvpUY0pLFjvFN9FK/DXVtODmCrRREcQk6rgGKqY0vLZVrupTcn
	 kqh7lvT35zYATayZeC0ejUHkuQdv2ZSgJmuIaRab3Pc0l/KSN8qSk23jsWXdJeaOaQ
	 sGQZhBXkf8KdYVHpLtlQaIC2gSBtuY4oaMD44xeXNOnVgiVvQh7nsSjOq89cDQACEI
	 ALKTSCmEwHySp6di+9UQlBJOMzGZBCokVke1li215uVNRoTfBPqScGn5CfdUDUQmZf
	 VUbR2NhuIUm3I1FRtMaKPz50O45m8TzLhZe15/JveDUGw818MUP2rTq6fxHkmLOM7L
	 fjDEok5axoDNA==
X-Cc: netdev@vger.kernel.org, andrew@lunn.ch, olteanv@gmail.com,
 davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
 robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
 matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com,
 chester.a.unal@arinc9.com, daniel@makrotopia.org, linux@armlinux.org.uk,
 arinc.unal@arinc9.com, Landen.Chao@mediatek.com, dqfext@gmail.com,
 sean.wang@mediatek.com, devicetree@vger.kernel.org,
 linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
 linux-mediatek@lists.infradead.org, naseefkm@gmail.com, b.larsson@gmx.com
X-In-Reply-To: <20261028011317.1557238-2-cjd@cjdns.fr>
X-sashiko-severity: Low
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