Article View: linux.kernel.netdev
Article #17195Re: [PATCH net] net: ibm: emac: attach the fixed-link PHY with of_phy_connect()
From: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 13:51
Date: Mon, 16 Nov 2026 13:51
213 lines
16068 bytes
16068 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 2 · 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 patch attaches the fixed-link PHY with of_phy_connect() in
emac_init_phy() (drivers/net/ethernet/ibm/emac/core.c:2680) but never…
- [Medium] In emac_init_phy()
(drivers/net/ethernet/ibm/emac/core.c:2684), the fixed-link path calls…
- [Medium] net: ibm: emac: fixed-link PHY leak in emac_init_phy() on
connect error
--
net: ibm: emac: attach the fixed-link PHY with of_phy_connect()
This commit changes the fixed-link branch of emac_init_phy(). Instead of
setting ndev->phydev by hand, it now calls of_phy_connect(), so the fixed
PHY is properly attached and enters the netdev's phy_link_topology. This
avoids a NULL link_topo dereference in phy_prepare_data() for
ETHTOOL_MSG_PHY_GET.
> diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
> index 640618c0a09e9..6e8b71138bb9a 100644
> --- a/drivers/net/ethernet/ibm/emac/core.c
> +++ b/drivers/net/ethernet/ibm/emac/core.c
> @@ -2674,11 +2674,14 @@ static int emac_init_phy(struct emac_instance *dev)
> return res;
>
> res = of_phy_register_fixed_link(np);
> - ndev->phydev = of_phy_find_device(np);
> - if (res || !ndev->phydev)
> - return res ? res : -EINVAL;
> - emac_adjust_link(dev->ndev);
> - put_device(&ndev->phydev->mdio.dev);
> + if (res)
> + return res;
> +
> + if (!of_phy_connect(ndev, np, &emac_adjust_link, 0,
> + dev->phy_mode))
> + return -EINVAL;
[Severity: Medium]
When of_phy_connect() fails here, the fixed PHY that
of_phy_register_fixed_link(np) registered a few lines above is never
cleaned up. emac_init_phy() returns -EINVAL immediately. Neither this
function nor the emac_probe() error path calls
of_phy_deregister_fixed_link(np).
of_phy_register_fixed_link() goes through fixed_phy_register(), which
does three things:
- takes one of the NUM_FP slots in the fixed PHY table;
- takes a reference on np with of_node_get();
- registers a phy_device on the global fixed MDIO bus.
All of this survives the failed probe.
of_phy_connect() can return NULL here in several ways:
- of_phy_find_device() does not find the device;
- phy_attach_direct() fails in try_module_get(),
phy_link_topo_add_phy() or phy_init_hw();
- phy_attach_direct() hits the -EBUSY "PHY already attached" case.
The last case ties in with the missing phy_disconnect() in
emac_remove(). On a rebind the first fixed PHY is still attached. Every
later probe attempt then registers another fixed PHY for the same
of_node, fails to connect, and leaks it. The fixed PHY table has only
NUM_FP slots and is shared by the whole system. Wouldn't a few
unbind/bind cycles exhaust it, so that fixed-link users of other
drivers fail too?
The old code had a similar leak when of_phy_find_device() returned
NULL. This patch rewrites this error handling anyway. Could the failure
branch call of_phy_deregister_fixed_link(np) before returning? The
drivers named in the commit message deregister the fixed link on their
probe error paths. The same unwinding would also be needed when probe
fails after emac_init_phy() has succeeded.
[Severity: High]
This path now really attaches the PHY. Does anything ever detach it? I
couldn't find phy_disconnect(), phy_detach() or
of_phy_deregister_fixed_link() anywhere under
drivers/net/ethernet/ibm/emac/.
Two paths leave the attach in place. In emac_probe(), a register_netdev()
failure jumps straight to err_detach_tah:
err = register_netdev(ndev);
if (err) {
...
goto err_detach_tah;
}
and emac_remove() only does:
unregister_netdev(dev->ndev);
...
mal_unregister_commac(dev->mal, &dev->commac);
emac_put_deps(dev);
The ndev comes from devm_alloc_etherdev(), so devres frees it on unbind or
on a failed probe. The fixed PHY stays registered on the global fixed MDIO
bus. Its attached_dev, adjust_link and phy_link_change fields still point
at the freed netdev. Before this patch, attached_dev stayed NULL on this
path.
Can this lead to a use-after-free on system suspend? The path would be:
mdio_bus_phy_suspend()
mdio_bus_phy_may_suspend()
if (netdev->ethtool->wol_enabled)
return false;
where netdev is the stale attached_dev. phy_suspend() also reads
netdev->ethtool->wol_enabled.
Does rebinding break too? On unbind/bind, a module reload, or a retry
after a failed register_netdev(), of_phy_register_fixed_link(np) registers
a second fixed PHY with the same of_node. But of_phy_find_device(np)
inside of_phy_connect() returns the first one, which is still attached.
phy_attach_direct() then fails here:
if (phydev->phy_link_change) {
phydev_err(phydev, "PHY already attached\n");
err = -EBUSY;
so emac_init_phy() returns -EINVAL on every later probe. The old code
rebound without an error, which doesn't seem to match this part of the
commit message:
so nothing else changes.
Each bind also seems to leak a few things:
- the device reference;
- the try_module_get() on the fixed_phy module, which then can't be
unloaded;
- the module reference on the genphy driver;
- the phy_device_node allocated by phy_link_topo_add_phy(), because
netdev_free_phy_link_topology() only calls xa_destroy() on topo->phys.
The of_phy_connect() kernel-doc says:
The refcount must be dropped by calling phy_disconnect() or phy_detach().
The drivers named in the commit message (gianfar, fec, davinci_emac,
nixge) pair of_phy_connect() with phy_disconnect() and
of_phy_deregister_fixed_link(), both on teardown and on the error paths.
The commit message leaves phy_disconnect() to a separate change. But this
patch is what creates the attach state on the fixed-link path. Should
phy_disconnect() and of_phy_deregister_fixed_link() be added here, both to
the emac_probe() error path after emac_init_phy() and to emac_remove()?
> +
> + emac_adjust_link(ndev);
[Severity: Medium]
Does phydev hold valid speed, duplex and pause values at this point?
fixed_phy_register() only stores the status in fmb_fixed_phys[] for
register emulation:
fmb_fixed_phys[phy_addr].status = *status;
fmb_fixed_phys[phy_addr].status.link = true;
and phy_device_create() starts with:
dev->speed = SPEED_UNKNOWN;
dev->duplex = DUPLEX_UNKNOWN;
dev->pause = false;
None of phy_attach_direct(), phy_probe(), phy_init_hw() or phy_resume()
reads link status, and the state machine is not started.
So emac_adjust_link() copies SPEED_UNKNOWN, DUPLEX_UNKNOWN and pause = 0
into dev->phy. That overwrites the dev->phy.pause = 1 set earlier in this
branch, and the SPEED_100/DUPLEX_FULL defaults from emac_probe().
emac_open() then calls emac_configure(). Because duplex is not
DUPLEX_FULL, it leaves out EMAC_MR1_FDE / EMAC_MR1_MWSW_001 and the flow
control bits. It takes the default case in the dev->phy.speed switch, and
it passes SPEED_UNKNOWN to rgmii_set_speed() / zmii_set_speed().
Wouldn't that leave the MAC at 10 Mb/s half duplex whatever the
fixed-link node says, for example 1000/full to an RTL8363SB switch?
The old hand-assignment code behaved the same way, but the commit message
relies on this call to configure the link:
emac_adjust_link() is still called once by hand
afterwards and the PHY state machine is still not started, because a
fixed link does not change.
Now that the PHY is attached, could phy_read_status(ndev->phydev) be
called under phydev->lock before emac_adjust_link()? Or could phylib drive
the handler instead?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112075321.3903875-1-xiaolinkui%40126.com
Technical Details
Message-ID:
<179483706662.3136.12689489417547730312@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364365-linux-kernel-netdev=dewy.ruReferences:
<20261112075321.3903875-1-xiaolinkui@126.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364365-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] net: ibm: emac: attach the fixed-link PHY with of_phy_connect() Date: Mon, 16 Nov 2026 13:51:06 +0000 Organization: Usenet Network Message-ID: <179483706662.3136.12689489417547730312@kernel.org> References: <20261112075321.3903875-1-xiaolinkui@126.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2077118"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:+Il86hlOZgVJkRjAgrzQAx5AYTw= sha256:Ntj1IhnF9bgKH5hnjC0DK+/n85tUmQrv1lpaBaFev8E= sha1:vcn8Z/cPzXcZwNWlyAIia9Bg3hA= sha256:efkamWd9LtHYB+reuFeBNm+JQFW0KtsINKKNM32ucsM= 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 7038B114C3C; Mon, 16 Nov 2026 16:53:07 +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 7XZcG47JqmXV; Mon, 16 Nov 2026 16:53:03 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-364365-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 53BBD114C37; Mon, 16 Nov 2026 16:52:49 +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 970973A05B; Mon, 16 Nov 2026 13:51:51 +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=1794837069; b=je12IEYKSu0t9BbTORpQW51r0zVzKzsSbRiC7od5CKD77pMMvGorRli/J9D0G6eL+Eo9 Rw8nrTCNZdaNQ6duP7C50YfIzDFjPRU6eRCdLIKapWeC/PpfPK6ttylqBAdRNysFlwlLF CeD5fsCRJMHYUpZMhHwPOUBrykbO/slJ7UwuETdeTd+1lzYGycOuIrV0sxz+aH+mq3kcD YE4UzeMT3dLxvRjltXjI6ze7nvgFZKskV6rS+U/aQTm+4mCdB0f+eD9tFVim8jKTDUA1M GG8ablP8jsPLeIvhxG/4hvdzmAoNFOtF0mVJa9ntQkfuIGHdvhuK++2oFydkWcLJKew== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794837069; 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=4ZuD8B6hoNm8RHjKxcqJEK2enGEm+a0togdRV6PHQdQ=; b=XXBke572oJhz5kgWxrX5NTMu/tSvCWOqr6XOxf7ZEt+K6ZqtjOhv6Df8s+OdOFdCnrzB FFabz7MoH7cklL4/VG7cNOExEZwWgedEEEhVZAs6t0GuAxzcGDzuaeKxxZ1TqZmtGJHzk 2fl8Eft1KrzUQTHM+1G+BJSjtCNxUl8oMyiIPMcTVRjKPiWWwN5o+jHcQwsoWXGg2z1j5 /htGceR70H7lROJroS850H+YuSrrB3S4or58wUw7fGziXtAeU3LCyXrUdRvSiTImaSnDT Pvzeaqk+k5usM9kKXM4I+WxYb5479jjhe7TGRTemFWBGP2IGQADk9QBTcs3eP+//MUw== 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=M2u72R0l; 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 3F64C60A5BD7; Mon, 16 Nov 2026 13:51:09 +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=M2u72R0l 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=1794837068; b=3WY1dhbCfbROofHzKlODwbxLVHCe2dxPQ08rK++W9D9QDronjlKP1Pazxrxj3KGoyXBg +iqoFCe/30lmmlYXiPTgvfTzmIL7ClTFgNi08aApzOiUj0NiW7m4v7OhA9DoLzat/UhNC DNnBxPtk11VsRmnOPghj/wjSOYWjH326J2FLVBxq/OocjlR1WFxEBBkPjuX2QC6jI7jj8 iif+6BsrmS6sQQFXHfX7+cy9hQwNpKNsZ4rMNTpMtbhIY+XLoLosdZ/ZtXCVMfmYFcGKP 4/kNUK0pPlB0rq6/nfSZovG4nhZ6K91TxqNzBxzEOIkSDLHg7KEcK1IHnYkXy/g362A== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794837068; 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=4ZuD8B6hoNm8RHjKxcqJEK2enGEm+a0togdRV6PHQdQ=; b=oWTZJ4lXorsjZ/IJHVIGoqOzm2wsIUg0Mzg15lV6xlswEMAszAIfA4ijwLsOwRVXOVk/ iC4PMjGHTQGeKfPwXHKPbJt/0X1Nn23EJy6fqatMQz1/GuloPYg7W5WwI7+UM2SJJtpOU 3ykxlKDSoOaY/JmknqkgeRwQdzlXJDv1r7b3AqmH4UtRMDZXDIVyir18xuVTxsmXxPgoj dKhA6jk+fuqjmW2pvX4c2J+0NrtWJEb3H8USLaHb+Pefq8ODHsZhoYvdczeN0/DkeZbc0 LCK9IyimQYMM5RI0sClLyMo4+G5t1+avAvXhZ3EmqL6VxsJAERBEK12YhFADbmOGpAg== 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=M2u72R0l; 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 579D1606A896; Mon, 16 Nov 2026 13:51:08 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A0A01F000C4; Mon, 16 Nov 2026 13:51:07 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794837067; bh=4ZuD8B6hoNm8RHjKxcqJEK2enGEm+a0togdRV6PHQdQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=M2u72R0lKsdFXpPt2rj1f0V6NREVyNtpflspHFPxqWpwLgSIg99ycLNte0cDSixiu xGgBVLgbYANmznimAEGQ/gQ4dX7Naw8gNit823UXp6kYow2oO2nic6Qr/fxuqJD/oQ OYYnRvZKAf5igr7CFJx5QBkMNeFNUQpig8DLf/WVsQ76JvPjjhoggy9coRb+0Y8hPc ynj2WI7y7UwitpR9XS9i0Jq4FDOP+rj4Haj38dMbu7VKNTVbBJ/0L8LYQ+aTTPqNV6 zQ+6JhJrhQqcQ92Ayh0LLtkRln4dbrqGWkSouDe+n+v0D+AuEezxR24eDKIC5QOfs1 PbliYSXwliKDg== X-Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, rosenp@gmail.com, jacob.e.keller@intel.com, daniel.machon@microchip.com, chunkeey@gmail.com, kees+treewide@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, xiaolinkui@kylinos.cn X-In-Reply-To: <20261112075321.3903875-1-xiaolinkui@126.com> 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