From: netdev-bot+sashiko@kernel.org
To: xiaolinkui@126.com
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
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 [thread overview]
Message-ID: <179551284032.3135.4209335363407893906@kernel.org> (raw)
In-Reply-To: <20261123093201.770552-2-xiaolinkui@126.com>
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
next prev parent reply other threads:[~2026-11-24 9:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 9:31 [PATCH net v2 0/2] net: ibm: emac: fix the fixed-link PHY setup Linkui Xiao
2026-11-23 9:32 ` [PATCH net v2 1/2] net: ibm: emac: attach the fixed-link PHY with of_phy_connect() Linkui Xiao
2026-11-24 9:34 ` netdev-bot+sashiko [this message]
2026-11-23 9:32 ` [PATCH net v2 2/2] net: ibm: emac: read the fixed-link status before adjusting the link Linkui Xiao
2026-11-23 14:55 ` Andrew Lunn
2026-11-24 8:39 ` Linkui Xiao
2026-11-24 9:34 ` netdev-bot+sashiko
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=179551284032.3135.4209335363407893906@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=andrew@lunn.ch \
--cc=chunkeey@gmail.com \
--cc=daniel.machon@microchip.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=jacob.e.keller@intel.com \
--cc=kees+treewide@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rosenp@gmail.com \
--cc=xiaolinkui@126.com \
--cc=xiaolinkui@kylinos.cn \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®