Article View: linux.kernel.netdev
Article #21639Re: [PATCH net v2 1/2] net: ibm: emac: attach the fixed-link PHY with of_phy_connect()
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 09:34
Date: Tue, 24 Nov 2026 09:34
112 lines
11742 bytes
11742 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 ยท High: 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] When the driver is unbound, emac_remove() calls phy_disconnect()
only after unregister_netdev() has finished.
--
net: ibm: emac: attach the fixed-link PHY with of_phy_connect()
For the fixed-link case, this patch stops setting ndev->phydev by hand
in emac_init_phy() and attaches the PHY with of_phy_connect() instead.
It also adds phy_disconnect() and of_phy_deregister_fixed_link() calls
to the emac_probe() error path and to emac_remove(), so the PHY is
detached on unbind.
> diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
> index 1b95b4d5deff5..ba02cf878a124 100644
> --- a/drivers/net/ethernet/ibm/emac/core.c
> +++ b/drivers/net/ethernet/ibm/emac/core.c
[ ... ]
> @@ -3223,6 +3232,11 @@ static void emac_remove(struct platform_device *ofdev)
>
> cancel_work_sync(&dev->reset_work);
>
> + if (dev->ndev->phydev)
> + phy_disconnect(dev->ndev->phydev);
[Severity: High]
Can this phy_disconnect() run against a netdev that is already
unregistered? Earlier in emac_remove() we have:
unregister_netdev(dev->ndev);
cancel_work_sync(&dev->reset_work);
On the phy-handle path, emac_mdio_init_phy() calls phy_start() at probe
time. emac_close() only calls netif_carrier_off() and never phy_stop().
So the phylib state machine keeps running while the interface is down,
and phy_link_change() can turn carrier back on.
Suppose carrier is on when the driver is unbound. That happens if the
interface was never opened, or if the link flapped after close. The
sequence is then:
emac_remove()
unregister_netdev()
netdev_run_todo() /* NETREG_UNREGISTERED, waits for refs */
phy_disconnect()
phy_stop()
_phy_state_machine() /* PHY_HALTED, phydev->link == 1 */
phy_link_down()
phy_link_change(false)
netif_carrier_off()
linkwatch_fire_event()
linkwatch_add_event()
netdev_hold()
netif_carrier_off() only skips NETREG_UNINITIALIZED:
if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
if (dev->reg_state == NETREG_UNINITIALIZED)
return;
atomic_inc(&dev->carrier_down_count);
linkwatch_fire_event(dev);
}
The unregistered netdev therefore lands on lweventlist, and it holds a
reference taken after netdev_run_todo() has already waited for all
references to drop.
When emac_remove() returns, devres frees the netdev that came from
devm_alloc_etherdev(). Later, __linkwatch_run_queue() still uses it:
dev = list_first_entry(&wrk, struct net_device, link_watch_list);
list_del_init(&dev->link_watch_list);
if (!netif_device_present(dev) ||
Wouldn't that be a use-after-free of the net_device? The same thing can
happen if the running state machine reports any link change between
unregister_netdev() and phy_disconnect().
The commit message says:
This fixes the phy-handle path as well, which calls phy_start() but
never phy_stop().
Could the PHY be stopped or disconnected before unregister_netdev()
instead? Another option would be to move phy_start() and phy_stop()
into ndo_open and ndo_stop.
> + if (of_phy_is_fixed_link(ofdev->dev.of_node))
> + of_phy_deregister_fixed_link(ofdev->dev.of_node);
> +
> if (emac_has_feature(dev, EMAC_FTR_HAS_TAH))
> tah_detach(dev->tah_dev, dev->tah_port);
[ ... ]
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123093201.770552-1-xiaolinkui%40126.com
Technical Details
Message-ID:
<179551284032.3135.4209335363407893906@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370159-linux-kernel-netdev=dewy.ruReferences:
<20261123093201.770552-2-xiaolinkui@126.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370159-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v2 1/2] net: ibm: emac: attach the fixed-link PHY with of_phy_connect() Date: Tue, 24 Nov 2026 09:34:00 +0000 Organization: Usenet Network Message-ID: <179551284032.3135.4209335363407893906@kernel.org> References: <20261123093201.770552-2-xiaolinkui@126.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="4101283"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:mgRPuD/1kCMsjaU8CbuFnr2+vHs= sha256:csQHpY0cdYT0ZnmMvM91k+ATuLgn6IwVsss/Hs+tfIg= sha1:KL+tSA5QgBvQqbNHr8ZU6rcLoQk= sha256:ENUxgSSwU616uLVuQDyN6OzydRgi4CsQxxjjqADoFw0= 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 74CA7125DEB; Tue, 24 Nov 2026 12:34:27 +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 YHdTE8a-HRbS; Tue, 24 Nov 2026 12:34:22 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-370159-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 49DF1125DE9; Tue, 24 Nov 2026 12:34:11 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 9D2182A056; Tue, 24 Nov 2026 09:34:07 +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=1795512843; b=K5jCop2mdcZhrNuIY1r0bDs9jMpE+aZ7dJp0cilGklapDbliYTsR58uEnaniHXFhe2Cc 3qT7Znpm8GEPeG1+cAyk10fHgXCvZcc8khqgCRD0M7Ck3Pb9Ot7qwuzK5OiCSjbhcNxhS vaPIwUYliDO0lYkr6xPcDHjJRWNK9H8OOJ83F/g++yIcRe/7cI44K9qTKsoo8M0Fu4FCf 80vr1AOGERqpnqqjTbDIw/H5qlL+KgaAmPWpcsjGQGbA51fHmgp0qUfcbTqKkQaahJw92 NiDCqD5mJFSxNpHoZRmbpn9iRdjvg9rVSvNX/kTVH35O932sZvdyC99mkNEXpWwltEA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795512843; 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=pEHllY3wB79e0b2IJ3VOYybEoWGDEgP+1ZO0Wb52Q2o=; b=u9nTGet/Nbq4vNxuw37bNkjHO5EEECV7PLo7sgUSqOd0Led9O2MG+c/4D30EMpwLGNeo eTU0cdVW2IbYVN5UqKJtN4Z2BjnUHFAVJVc7qAwnx9v9FnynxMY3Rq7cwlKZd47sSbq8s //SSb4wnEoNvVCSAqkw/HU6QmVXc58mQV9Q6CTpFtraKElk8qBicOwy06RDx9xS9Mriat w7MNNRubOq9VXEzo2lVZSLctklxu3wH7KBmtprrZM5hAYnWUcw+zyTzLtTnzwNQW4lp+Y OFTRMMQkx18nd27MmctOzyIPmoOUxbzHmArDpNaEqXHh2l0tMbwMMcRpMzpEsErx4Cw== 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=QF5ErUir; 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 34A63606A681; Tue, 24 Nov 2026 09:34:03 +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=QF5ErUir 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=1795512842; b=2k/d75dR4z7d4SNTr9mhVEKO57bzPcRz3Bp/E103knV+9w/OZrJ2iWxurh6qBsZexjkH UKR3NGUQRZhtw1LEdpVf41LLkFH+HEA5G2ExhrSJDMwqYS59ery/UU5OAv8ceDRCKwOPT 2p7uA70Rhl9IQCywUrDVS7iE8ArLK+37qTd490rZ1sqXgZq6EiesF2JNDJ28ZluLCAtvP 64YBg6L5S78NnMHeFidj5e84HY9NNAnL+XyXoUgeiqSFLeI3EkmjnGfULI1iIPtTY2SWx zfOwf6pyXLmf/VH8dEX5aTS5TdLKMTX0pinco82bK7FF4CgKt5MHo9SL+0R1tBBKvag== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795512842; 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=pEHllY3wB79e0b2IJ3VOYybEoWGDEgP+1ZO0Wb52Q2o=; b=iHXeOIMNn8THhW1Zm3Sg6oEc7SHHm/+BdTRTnPpdEnwX/Q5ekW7Q9+/TAcKAKOUSW6f1 QtMAf38VkFeiV2xr0iSAPXz2FovklNLC01A9kdm3dBuIgkdwu0zSaiHOlHWfkKvflK8SH ZXo434Mxo4Yz18GAASGtNCroKwzrfAyYnU1NT0rZyabCACo3oQw0ogAGLqEICF5lLuoNY 2dfCHVY3Ny+D9VK0LvGGh25tdQc6DWXxZPjpbd5zpGWXJrXXFXWcK5D0V4IXzgnt4GnC3 HsyIsxMUofDOUiM/h5RCmyLd7EgEyOHi+F9TiCZq2eV3W1bCFGxtbaAOKfmeD+vnGXQ== 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=QF5ErUir; 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 52286606A32D; Tue, 24 Nov 2026 09:34:02 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C45231F000D1; Tue, 24 Nov 2026 09:34:00 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795512841; bh=pEHllY3wB79e0b2IJ3VOYybEoWGDEgP+1ZO0Wb52Q2o=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=QF5ErUirrDLXM2ZECVOAMBE9ATMMmiu9gNxoAytjuDcBP608bAcq/RmXdcJmYavK/ 6Jagw8oIjvo0SMWC0G+czqI/s1ALsbaPJISGkwhGjCSdadBXawzgL+jUVTMQXThVVp 7r1iILhR0ZrUPD2obfZtiObFRKCXzE1te/1EduuTtr2e00s9zofalp2+fB860Kfl/y ulbCMkP3cCk2idEO2Mk2s6CrmomUDSDt4kaje7aktGNg3lpoBPMAWKroA9xqteCoB1 CeSeDrIOB0csr2AayYn72ZDnvzKpqo1E+kjXSk6+4zV2fCIxQFHFoKtlZD/zmx74cS ymBlMU6uTl90A== X-Cc: andrew@lunn.ch, 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: <20261123093201.770552-2-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