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 v3 4/8] net: mdio: realtek-rtl9300: Configure hardware polling during probing
Date: Mon, 06 Jul 2026 16:36:28 +0000 [thread overview]
Message-ID: <20260706163630.A39DD1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260705163532.2853959-5-markus.stockhausen@gmx.de>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Data race due to unprotected lockless read of `priv->phy_poll`.
--
commit 5dc09b6df4d4ed1cb80ef56b8de6e9aa03870333
Author: Markus Stockhausen <markus.stockhausen@gmx.de>
net: mdio: realtek-rtl9300: Configure hardware polling during probing
This commit synchronizes kernel and hardware polling for Realtek Otto switches
by disabling polling for all ports on start and managing it per-PHY during
attach and detach. This prevents hardware polling from interfering with
complex configuration sequences or firmware loading.
Link: https://github.com/openwrt/openwrt/blob/main/target/linux/realtek/files-6.18/drivers/net/mdio/mdio-realtek-otto.c#L818
Link: https://lore.kernel.org/netdev/680696024a8648535ce6dee771fe4de67802e0e8.1769053496.git.daniel@makrotopia.org/
> diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c
> index 562f9c7f2895d..c36244cd9a66e 100644
> --- a/drivers/net/mdio/mdio-realtek-rtl9300.c
> +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c
[ ... ]
> @@ -576,6 +588,47 @@ 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)
> +{
> + 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);
> + int ret;
> +
> + if (port < 0)
> + return port;
> +
> + if (test_bit(port, priv->phy_poll))
> + return 0;
[Severity: Medium]
Could this lockless read of priv->phy_poll result in a data race?
While this test_bit() is lockless, the updates in the guarded sections below
use the non-atomic __set_bit() and __clear_bit(). If multiple PHYs on the
same MDIO bus are attached or detached concurrently, the plain
read-modify-write from __set_bit() or __clear_bit() on the same word could
race with this read, causing KCSAN warnings and undefined behavior.
Should this test_bit() check be moved inside the scoped_guard() block, which
safely supports early returns?
> +
> + scoped_guard(mutex, &priv->lock) {
> + ret = otto_emdio_set_port_polling(priv, port, true);
> + if (!ret)
> + __set_bit(port, priv->phy_poll);
> + }
> +
> + return ret;
> +}
> +
> +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;
> +
> + scoped_guard(mutex, &priv->lock) {
> + ret = otto_emdio_set_port_polling(priv, port, false);
> + if (!ret)
> + __clear_bit(port, priv->phy_poll);
> + }
> +
> + if (ret)
> + dev_err(bus->parent, "failed to disable polling for port %d\n", port);
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260705163532.2853959-1-markus.stockhausen@gmx.de?part=4
next prev parent reply other threads:[~2026-07-06 16:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-05 16:35 [PATCH net-next v3 0/8] net: mdio: realtek-rtl9300: Add RTL83xx support Markus Stockhausen
2026-07-05 16:35 ` [PATCH net-next v3 1/8] dt-bindings: net: realtek,rtl9301-mdio: Add RTL83xx series Markus Stockhausen
2026-07-06 17:08 ` Conor Dooley
2026-07-05 16:35 ` [PATCH net-next v3 2/8] net: mdio: realtek-rtl9300: Add polling documentation Markus Stockhausen
2026-07-05 16:35 ` [PATCH net-next v3 3/8] net: phy: add (*notify_phy_attach/detach)() hooks to struct mii_bus Markus Stockhausen
2026-07-06 16:36 ` sashiko-bot
2026-07-05 16:35 ` [PATCH net-next v3 4/8] net: mdio: realtek-rtl9300: Configure hardware polling during probing Markus Stockhausen
2026-07-06 16:36 ` sashiko-bot [this message]
2026-07-05 16:35 ` [PATCH net-next v3 5/8] net: mdio: realtek-rtl9300: Add page tracking Markus Stockhausen
2026-07-05 16:35 ` [PATCH net-next v3 6/8] net: mdio: realtek-rtl9300: Increase MDIO timeout Markus Stockhausen
2026-07-05 16:35 ` [PATCH net-next v3 7/8] net: mdio: realtek-rtl9300: Add support for RTL838x Markus Stockhausen
2026-07-05 16:35 ` [PATCH net-next v3 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=20260706163630.A39DD1F000E9@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