From: sashiko-bot@kernel.org
To: "Inochi Amaoto" <inochiama@gmail.com>
Cc: vkoul@kernel.org, neil.armstrong@linaro.org,
linux-phy@lists.infradead.org, olteanv@gmail.com
Subject: Re: [PATCH 1/3] phy: core: Add common helper to add phy phandle device link
Date: Mon, 31 Aug 2026 03:03:43 +0000 [thread overview]
Message-ID: <20260831030343.918691F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260831025506.95548-1-inochiama@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The `of_phy_simple_xlate` function drops the device reference before returning it, leading to a Use-After-Free if the PHY device is concurrently unregistered.
--
commit cd21d0b3786ada14d9e18e94ffc3887f9ea8b747
Author: Inochi Amaoto <inochiama@gmail.com>
phy: core: Add common helper to add phy phandle device link
It is very common for adding a device link for phy phandle
for device managed phy helper functions. So add a common
helper for future reuse.
> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index 21aaf2f76e53e..451f8f0644c13 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c
[ ... ]
> @@ -784,7 +804,6 @@ struct phy *phy_get(struct device *dev, const char *string)
> {
> int index = 0;
> struct phy *phy;
> - struct device_link *link;
[Severity: High]
This isn't a bug introduced by this patch, but could this code cause memory
corruption?
drivers/phy/phy-core.c:of_phy_simple_xlate() {
...
target_dev = class_find_device_by_of_node(&phy_class, args->np);
if (!target_dev)
return ERR_PTR(-ENODEV);
put_device(target_dev);
return to_phy(target_dev);
}
The of_phy_simple_xlate() function locates the PHY device using
class_find_device_by_of_node(), which returns it with an incremented
reference count. However, it immediately calls put_device() to drop the
reference before returning the pointer.
If a concurrent thread unregisters the PHY device (e.g., via module
removal or driver unbind), this put_device() might drop the final
reference, freeing the memory. The caller could then access the freed
pointer. Could this lead to a use-after-free race condition?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260831025506.95548-1-inochiama@gmail.com?part=1
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
prev parent reply other threads:[~2026-08-31 3:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 2:53 [PATCH 0/3] phy: core: Add phy bulk helpers support Inochi Amaoto
2026-08-31 2:55 ` [PATCH 1/3] phy: core: Add common helper to add phy phandle device link Inochi Amaoto
2026-08-31 2:55 ` [PATCH 2/3] phy: core: Add common helper for get phy phandle by index Inochi Amaoto
2026-08-31 3:03 ` sashiko-bot
2026-08-31 9:13 ` Andy Shevchenko
2026-08-31 9:48 ` Inochi Amaoto
2026-08-31 2:55 ` [PATCH 3/3] phy: core: Add phy bulk data helper functions Inochi Amaoto
2026-08-31 9:28 ` Andy Shevchenko
2026-08-31 10:00 ` Inochi Amaoto
2026-08-31 3:03 ` sashiko-bot [this message]
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=20260831030343.918691F000E9@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