From: sashiko-bot@kernel.org
To: "Bryan O'Donoghue" <bryan.odonoghue@linaro.org>
Cc: robh@kernel.org, olteanv@gmail.com, devicetree@vger.kernel.org,
media-ci@linuxtv.org, linux-phy@lists.infradead.org,
neil.armstrong@linaro.org, conor+dt@kernel.org, vkoul@kernel.org
Subject: Re: [PATCH v13 1/5] phy: core: Add phy_get_by_of_node()
Date: Tue, 28 Jul 2026 09:46:19 +0000 [thread overview]
Message-ID: <20260728094619.830C91F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260728-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v13-1-ae811e2f0799@linaro.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] The newly introduced phy_get_by_of_node() API bypasses the usb-nop-xceiv compatibility check, leading to infinite probe deferral.
Pre-existing issues:
- [High] A Time-of-Check to Time-of-Use (TOCTOU) race condition during PHY lookup returns an unpinned pointer, allowing concurrent PHY destruction to cause a Use-After-Free.
--
--- Patch [1]: [PATCH v13 1/5] phy: core: Add phy_get_by_of_node() ---
commit 2964f1957e7138a13d72185f47a72cbb1e4e193c
Author: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
phy: core: Add phy_get_by_of_node()
Add new function phy_get_by_of_node() allowing lookup of a phy by
device_node. Separates existing logic in _of_phy_get() into an internal
helper method _of_phy_get_with_args() to allow for reuse in new method.
> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index 21aaf2f76e53e..ebfad5325072e 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c
[ ... ]
> @@ -607,54 +607,69 @@ int phy_validate(struct phy *phy, enum phy_mode mode, int submode,
[ ... ]
> +static struct phy *_of_phy_get(struct device_node *np, int index)
> +{
> + int ret;
> + struct phy *phy;
> + struct of_phandle_args args;
> +
> + ret = of_parse_phandle_with_args(np, "phys", "#phy-cells",
> + index, &args);
> + if (ret)
> + return ERR_PTR(-ENODEV);
> +
> + /* This phy type handled by the usb-phy subsystem for now */
> + if (of_device_is_compatible(args.np, "usb-nop-xceiv")) {
> + phy = ERR_PTR(-ENODEV);
> + goto out_put_node;
> + }
> +
> + phy = _of_phy_get_with_args(&args);
[Severity: High]
If a caller uses the new phy_get_by_of_node() API on a device node compatible
with "usb-nop-xceiv", will it bypass this check?
Because the compatibility check was left here in _of_phy_get() instead of
being moved into the shared _of_phy_get_with_args() helper, it appears the
new API will skip this fallback and could enter an infinite probe deferral
instead of correctly returning -ENODEV.
[ ... ]
> @@ -986,6 +1001,34 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
> }
> EXPORT_SYMBOL_GPL(devm_of_phy_get_by_index);
>
> +/**
> + * phy_get_by_of_node() - lookup and obtain a reference to a phy by device_node
> + * @np: node containing the phy
> + *
> + * Returns the phy associated with the device node or ERR_PTR.
> + */
> +struct phy *phy_get_by_of_node(struct device_node *np)
> +{
> + struct of_phandle_args args = { .np = np, .args_count = 0 };
> + struct phy *phy;
> +
> + if (!np)
> + return ERR_PTR(-EINVAL);
> +
> + phy = _of_phy_get_with_args(&args);
> +
> + if (IS_ERR(phy))
> + return phy;
> +
> + if (!try_module_get(phy->ops->owner))
[Severity: High]
This isn't a bug introduced by this patch, but is there a race condition
here between retrieving the phy and pinning its module?
The _of_phy_get_with_args() helper retrieves the phy pointer via the
provider's of_xlate callback. Typical callbacks (like of_phy_simple_xlate())
drop the PHY device reference before returning. _of_phy_get_with_args() then
unlocks phy_provider_mutex and drops the provider's module reference.
Could a concurrent thread unbinding the PHY provider destroy the PHY object
before this caller evaluates try_module_get(phy->ops->owner), resulting in a
use-after-free?
> + return ERR_PTR(-EPROBE_DEFER);
> +
> + get_device(&phy->dev);
> +
> + return phy;
> +}
> +EXPORT_SYMBOL_GPL(phy_get_by_of_node);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260728-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v13-0-ae811e2f0799@linaro.org?part=1
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
next prev parent reply other threads:[~2026-07-28 9:46 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-28 9:35 [PATCH v13 0/5] Add dt-bindings and PHY updates for CAMSS on x1e80100 silicon Bryan O'Donoghue
2026-07-28 9:35 ` [PATCH v13 1/5] phy: core: Add phy_get_by_of_node() Bryan O'Donoghue
2026-07-28 9:46 ` sashiko-bot [this message]
2026-07-28 10:01 ` Bryan O'Donoghue
2026-07-28 9:35 ` [PATCH v13 2/5] phy: core: Add devm_phy_get_by_of_node() Bryan O'Donoghue
2026-07-28 9:47 ` sashiko-bot
2026-07-28 10:21 ` Bryan O'Donoghue
2026-07-28 10:46 ` Dmitry Baryshkov
2026-07-28 10:51 ` Bryan O'Donoghue
2026-07-28 9:35 ` [PATCH v13 3/5] media: qcom: camss: Add support for PHY API devices Bryan O'Donoghue
2026-07-28 9:51 ` sashiko-bot
2026-07-28 10:48 ` Dmitry Baryshkov
2026-07-28 11:02 ` Loic Poulain
2026-07-28 9:35 ` [PATCH v13 4/5] dt-bindings: media: qcom,x1e80100-camss: Describe iommu entries Bryan O'Donoghue
2026-07-28 9:35 ` [PATCH v13 5/5] dt-bindings: media: qcom,x1e80100-camss: Make vdd-csiphy supplies optional Bryan O'Donoghue
2026-07-28 9:42 ` sashiko-bot
2026-07-28 10:06 ` Bryan O'Donoghue
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=20260728094619.830C91F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bryan.odonoghue@linaro.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=media-ci@linuxtv.org \
--cc=neil.armstrong@linaro.org \
--cc=olteanv@gmail.com \
--cc=robh@kernel.org \
--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