All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Markus Stockhausen" <markus.stockhausen@gmx.de>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH net-next v7 4/8] net: mdio: realtek-rtl9300: Configure hardware polling during probing
Date: Mon, 27 Jul 2026 07:18:44 +0000	[thread overview]
Message-ID: <20260727071844.9DB181F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260726071751.1359156-5-markus.stockhausen@gmx.de>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Use-After-Free in `otto_emdio_notify_phy_detach` due to devm lifetime mismatch.
--

--- Patch [4]: [PATCH net-next v7 4/8] net: mdio: realtek-rtl9300: Configure hardware polling during probing ---
commit 66c265d23ecd919426f5681d91b6f6d07bc6bd53
Author: Markus Stockhausen <markus.stockhausen@gmx.de>

net: mdio: realtek-rtl9300: Configure hardware polling during probing

This patch configures hardware polling for Realtek Otto switches to prevent
interference during PHY probing and firmware loading. It disables polling
when the MDIO driver starts, reenables it after a PHY is attached, and
disables it before a PHY is detached.

> diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c
> index 3dee5bff41349..c607dad9f0a31 100644
> --- a/drivers/net/mdio/mdio-realtek-rtl9300.c
> +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c

[ ... ]

> @@ -582,6 +591,32 @@ static int otto_emdio_9310_setup_controller(struct otto_emdio_priv *priv)
>  	return 0;
>  }
>  
> +static int otto_emdio_notify_phy_attach(struct phy_device *phydev)
> +{

[ ... ]

> +}
> +
> +static void otto_emdio_notify_phy_detach(struct phy_device *phydev)
> +{
> +	struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(phydev->mdio.bus);
> +	int port = otto_emdio_phy_to_port(phydev->mdio.bus, phydev->mdio.addr);
> +	struct mii_bus *bus = phydev->mdio.bus;
> +	int ret;
> +
> +	if (port < 0)
> +		return;
> +
> +	ret = otto_emdio_set_port_polling(priv, port, false);

[Severity: High]
Could this lead to a use-after-free if the MDIO driver is unbound?

The priv structure is allocated with devm_kzalloc() during probe, which
ties its lifetime to the platform device. However, the MDIO bus is allocated
with devm_mdiobus_alloc_size(), which is reference counted.

If the MDIO driver is unbound via sysfs, devres will free priv immediately.
If a MAC driver still holds a reference to a PHY device on the bus, the
mii_bus will remain alive.

When the MAC driver later detaches the PHY, for example when the network
interface is brought down, phy_detach() will call bus->notify_phy_detach().
This executes otto_emdio_notify_phy_detach(), which will dereference the
freed priv pointer inside otto_emdio_set_port_polling().

> +	if (ret)
> +		dev_err(bus->parent, "failed to disable polling for port %d\n", port);
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260726071751.1359156-1-markus.stockhausen@gmx.de?part=4

  reply	other threads:[~2026-07-27  7:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-26  7:17 [PATCH net-next v7 0/8] net: mdio: realtek-rtl9300: Add RTL83xx support Markus Stockhausen
2026-07-26  7:17 ` [PATCH net-next v7 1/8] dt-bindings: net: realtek,rtl9301-mdio: Add RTL83xx series Markus Stockhausen
2026-07-26  7:17 ` [PATCH net-next v7 2/8] net: mdio: realtek-rtl9300: Add polling documentation Markus Stockhausen
2026-07-26  7:17 ` [PATCH net-next v7 3/8] net: phy: add (*notify_phy_attach/detach)() hooks to struct mii_bus Markus Stockhausen
2026-07-27  7:18   ` sashiko-bot
2026-07-26  7:17 ` [PATCH net-next v7 4/8] net: mdio: realtek-rtl9300: Configure hardware polling during probing Markus Stockhausen
2026-07-27  7:18   ` sashiko-bot [this message]
2026-07-26  7:17 ` [PATCH net-next v7 5/8] net: mdio: realtek-rtl9300: Add page tracking Markus Stockhausen
2026-07-26  7:17 ` [PATCH net-next v7 6/8] net: mdio: realtek-rtl9300: Increase MDIO timeout Markus Stockhausen
2026-07-26  7:17 ` [PATCH net-next v7 7/8] net: mdio: realtek-rtl9300: Add support for RTL838x Markus Stockhausen
2026-07-26  7:17 ` [PATCH net-next v7 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=20260727071844.9DB181F000E9@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.