Linux-PHY Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Inochi Amaoto" <inochiama@gmail.com>
Cc: olteanv@gmail.com, neil.armstrong@linaro.org, vkoul@kernel.org,
	linux-phy@lists.infradead.org
Subject: Re: [PATCH 2/3] phy: core: Add common helper for get phy phandle by index
Date: Mon, 31 Aug 2026 03:03:07 +0000	[thread overview]
Message-ID: <20260831030307.C640F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260831025506.95548-2-inochiama@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Pre-existing race condition where the PHY module and device references are temporarily dropped before being re-acquired, risking a use-after-free.
--

commit 21ec40d6cb3e559164837267cde1582380a6bfd2
Author: Inochi Amaoto <inochiama@gmail.com>

phy: core: Add common helper for get phy phandle by index

This commit refactors phy lookup by extracting the index-based retrieval
logic from of_phy_get() and devm_of_phy_get_by_index() into a new common
helper function, of_phy_get_by_index().

> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index 451f8f0644c13..2259f0dff0822 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c
[ ... ]
> -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 isn't a bug introduced by this patch, but is there a race condition
here that could lead to a use-after-free?

Looking at the full body of of_phy_get_by_index():

    phy = _of_phy_get(np, index);
    if (IS_ERR(phy))
            return phy;

    if (!try_module_get(phy->ops->owner))
            return ERR_PTR(-EPROBE_DEFER);

Inside _of_phy_get(), a module reference is temporarily acquired to call the
of_xlate() callback, but it is explicitly dropped via
module_put(phy_provider->owner) before returning the phy pointer.

Additionally, common of_xlate() implementations like of_phy_simple_xlate()
temporarily acquire a device reference but drop it via put_device() before
returning.

Could a concurrent sysfs unbind or module unload of the PHY driver free the
phy structure during the window between _of_phy_get() returning and
of_phy_get_by_index() evaluating phy->ops->owner?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260831025506.95548-1-inochiama@gmail.com?part=2

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

  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 [this message]
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   ` [PATCH 1/3] phy: core: Add common helper to add phy phandle device link sashiko-bot

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=20260831030307.C640F1F000E9@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