From: sashiko-bot@kernel.org
To: "Inochi Amaoto" <inochiama@gmail.com>
Cc: linux-phy@lists.infradead.org, vkoul@kernel.org,
neil.armstrong@linaro.org, olteanv@gmail.com
Subject: Re: [PATCH v2 2/4] phy: core: Add common helper for get phy phandle by index
Date: Fri, 04 Sep 2026 08:48:31 +0000 [thread overview]
Message-ID: <20260904084832.4E3671F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260904083709.425893-3-inochiama@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Use-After-Free race condition due to momentarily dropping the PHY provider's module reference.
--
commit 82b3a08205293dd6de5d86ce337bb43664f65534
Author: Inochi Amaoto <inochiama@gmail.com>
phy: core: Add common helper for get phy phandle by index
This commit refactors several PHY helpers that use an index to retrieve
the PHY phandle of a device node, adding a common helper function to
allow for future reuse.
> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index ea79913fbb87f..a7d7acb5d3c2a 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c
[ ... ]
> @@ -682,21 +682,18 @@ static struct phy *_of_phy_get(struct device_node *np, int index)
> }
>
> /**
> - * of_phy_get() - lookup and obtain a reference to a phy using a device_node.
> + * of_phy_get_by_index() - lookup and obtain a reference to a phy using a
> + * device_node by index.
> * @np: device_node for which to get the phy
> - * @con_id: name of the phy from device's point of view
> + * @index: index of the phy from device's point of view
> *
> - * Returns the phy driver, after getting a refcount to it; or
> + * Returns: the phy driver, after getting a refcount to it; or
> * -ENODEV if there is no such phy. The caller is responsible for
> * calling of_phy_put() to release that count.
> */
> -struct phy *of_phy_get(struct device_node *np, const char *con_id)
> +static struct phy *of_phy_get_by_index(struct device_node *np, int index)
> {
> - struct phy *phy = NULL;
> - int index = 0;
> -
> - if (con_id)
> - index = of_property_match_string(np, "phy-names", con_id);
> + struct phy *phy;
>
> phy = _of_phy_get(np, index);
> if (IS_ERR(phy))
[Severity: High]
This is a pre-existing issue, but does this pattern risk a use-after-free
race condition if a concurrent module unload occurs?
Looking at _of_phy_get(), it temporarily acquires the PHY provider module
reference, but drops it before returning the bare phy pointer:
_of_phy_get() {
...
phy = phy_provider->of_xlate(phy_provider->dev, &args);
out_put_module:
module_put(phy_provider->owner);
out_unlock:
mutex_unlock(&phy_provider_mutex);
...
return phy;
}
By the time execution continues in this helper and calls
try_module_get(phy->ops->owner) slightly further down, the module
reference is no longer held. If a concurrent module unload proceeds during
this brief window, the PHY provider could be unregistered and the phy
struct freed, causing the dereference of phy->ops to access freed memory.
Could this refactoring be an opportunity to address this race window?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260904083709.425893-1-inochiama@gmail.com?part=2
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
next prev parent reply other threads:[~2026-09-04 8:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 8:37 [PATCH v2 0/4] phy: core: Add phy bulk helpers support Inochi Amaoto
2026-09-04 8:37 ` [PATCH v2 1/4] phy: core: Add common helper to add phy phandle device link Inochi Amaoto
2026-09-04 8:50 ` sashiko-bot
2026-09-05 8:02 ` Andy Shevchenko
2026-09-04 8:37 ` [PATCH v2 2/4] phy: core: Add common helper for get phy phandle by index Inochi Amaoto
2026-09-04 8:48 ` sashiko-bot [this message]
2026-09-05 8:14 ` Andy Shevchenko
2026-09-04 8:37 ` [PATCH v2 3/4] phy: core: Add phy bulk data helper functions Inochi Amaoto
2026-09-04 8:50 ` sashiko-bot
2026-09-04 8:37 ` [PATCH v2 4/4] phy: core: Add managed " Inochi Amaoto
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=20260904084832.4E3671F00A3D@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=inochiama@gmail.com \
--cc=linux-phy@lists.infradead.org \
--cc=neil.armstrong@linaro.org \
--cc=olteanv@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vkoul@kernel.org \
/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