From: sashiko-bot@kernel.org
To: "Markus Stockhausen" <markus.stockhausen@gmx.de>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next v5 3/8] net: phy: add (*notify_phy_attach/detach)() hooks to struct mii_bus
Date: Thu, 23 Jul 2026 06:24:44 +0000 [thread overview]
Message-ID: <20260723062445.698D91F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260722062356.12291-4-markus.stockhausen@gmx.de>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] Inverted resource teardown order in `phy_detach` causes LIFO violation.
Pre-existing issues:
- [High] `phy_attach_direct` destroys pre-existing attachments when returning -EBUSY.
--
--- Patch [3]: [PATCH net-next v5 3/8] net: phy: add (*notify_phy_attach/detach)() hooks to struct mii_bus ---
commit 2e5a68c82441635d018ad6986569eeead2f1a154
Author: Daniel Golle <daniel@makrotopia.org>
net: phy: add (*notify_phy_attach/detach)() hooks to struct mii_bus
Some MDIO buses require to program PHY polling registers depending on
the PHY type. This adds two simple hooks in struct mii_bus which are
called right after a PHY has been attached and just before it is
going to be detached.
Link: https://github.com/openwrt/openwrt/pull/21515#discussion_r2714069716
Link: https://lore.kernel.org/netdev/cover.1769053496.git.daniel@makrotopia.org/
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 94b2e85e00a37..a62c2ff6c2aab 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -1876,6 +1876,13 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
> if (err)
> goto error;
>
> + if (phydev->mdio.bus->notify_phy_attach) {
> + err = phydev->mdio.bus->notify_phy_attach(phydev);
> + if (err)
> + goto error;
[Severity: High]
This is a pre-existing issue, but does jumping to the error label in this
function cause problems for already attached PHYs?
Earlier in phy_attach_direct(), if a second device attempts to attach to a
PHY that is already attached, it detects this (phydev->attached_dev is set),
sets err = -EBUSY, and jumps to the error label.
The error block then calls phy_detach(phydev), which tears down the fully
established attachment. This forcefully clears phydev->attached_dev and
removes the PHY from the original owner without its knowledge.
When the original owner later interacts with the PHY or tries to tear it down,
could it encounter a dangling pointer or mismatched refcounts?
> + phydev->mdio_bus_notified = true;
> + }
> +
> phy_resume(phydev);
[ ... ]
> @@ -1919,6 +1926,10 @@ void phy_detach(struct phy_device *phydev)
> struct module *ndev_owner = NULL;
> struct mii_bus *bus;
>
> + if (phydev->mdio_bus_notified && phydev->mdio.bus->notify_phy_detach)
> + phydev->mdio.bus->notify_phy_detach(phydev);
> + phydev->mdio_bus_notified = false;
> +
[Severity: High]
Does this tear down sequence violate LIFO order?
In phy_attach_direct(), the setup sequence calls notify_phy_attach() before
phy_resume() and device_link_add().
To follow strict LIFO teardown, shouldn't phy_detach() call device_link_del()
and phy_suspend() before notify_phy_detach()?
If an MDIO bus driver disables resources (like power, clocks, or polling) in
the detach hook, the subsequent call to phy_suspend() could attempt to issue
MDIO commands to an unconfigured bus, potentially leading to bus timeouts or
hangs.
> if (phydev->devlink) {
> device_link_del(phydev->devlink);
> phydev->devlink = NULL;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260722062356.12291-1-markus.stockhausen@gmx.de?part=3
next prev parent reply other threads:[~2026-07-23 6:24 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-22 6:23 [PATCH net-next v5 0/8] net: mdio: realtek-rtl9300: Add RTL83xx support Markus Stockhausen
2026-07-22 6:23 ` [PATCH net-next v5 1/8] dt-bindings: net: realtek,rtl9301-mdio: Add RTL83xx series Markus Stockhausen
2026-07-22 6:23 ` [PATCH net-next v5 2/8] net: mdio: realtek-rtl9300: Add polling documentation Markus Stockhausen
2026-07-22 19:09 ` Andrew Lunn
2026-07-23 6:23 ` AW: " Markus Stockhausen
2026-07-22 6:23 ` [PATCH net-next v5 3/8] net: phy: add (*notify_phy_attach/detach)() hooks to struct mii_bus Markus Stockhausen
2026-07-22 18:43 ` Andrew Lunn
2026-07-23 6:24 ` sashiko-bot [this message]
2026-07-22 6:23 ` [PATCH net-next v5 4/8] net: mdio: realtek-rtl9300: Configure hardware polling during probing Markus Stockhausen
2026-07-22 18:50 ` Andrew Lunn
2026-07-22 6:23 ` [PATCH net-next v5 5/8] net: mdio: realtek-rtl9300: Add page tracking Markus Stockhausen
2026-07-22 18:55 ` Andrew Lunn
2026-07-22 6:23 ` [PATCH net-next v5 6/8] net: mdio: realtek-rtl9300: Increase MDIO timeout Markus Stockhausen
2026-07-22 18:55 ` Andrew Lunn
2026-07-22 6:23 ` [PATCH net-next v5 7/8] net: mdio: realtek-rtl9300: Add support for RTL838x Markus Stockhausen
2026-07-22 6:23 ` [PATCH net-next v5 8/8] net: mdio: realtek-rtl9300: Add support for RTL839x Markus Stockhausen
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=20260723062445.698D91F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=markus.stockhausen@gmx.de \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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