From: sashiko-bot@kernel.org
To: "Felix Gu" <ustc.gu@gmail.com>
Cc: neil.armstrong@linaro.org, wsa+renesas@sang-engineering.com,
linux-phy@lists.infradead.org, olteanv@gmail.com,
vkoul@kernel.org
Subject: Re: [PATCH v2 1/3] phy: renesas: rcar-gen2: Fix double of_node_put on phy creation failure
Date: Tue, 04 Aug 2026 15:38:00 +0000 [thread overview]
Message-ID: <20260804153801.3EB0D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260804-rcar-gen2-v2-1-829cb84112ca@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing reference count increment for device node leads to a dangling pointer.
- [High] TOCTOU race condition between child count and iteration leads to out-of-bounds array write.
--
--- Patch [1]: [PATCH v2 1/3] phy: renesas: rcar-gen2: Fix double of_node_put on phy creation failure ---
commit 047745265c7b61da44949752ecc277b2156237a3
Author: Felix Gu <ustc.gu@gmail.com>
phy: renesas: rcar-gen2: Fix double of_node_put on phy creation failure
This commit fixes a double of_node_put() issue in the error path of
devm_phy_create(). The scoped iterator for_each_child_of_node_scoped()
already handles dropping the node reference, so the explicit of_node_put()
was redundant.
> diff --git a/drivers/phy/renesas/phy-rcar-gen2.c b/drivers/phy/renesas/phy-rcar-gen2.c
> index 6c671254c6258..5a272e25e051c 100644
> --- a/drivers/phy/renesas/phy-rcar-gen2.c
> +++ b/drivers/phy/renesas/phy-rcar-gen2.c
> @@ -405,7 +405,6 @@ static int rcar_gen2_phy_probe(struct platform_device *pdev)
> data->gen2_phy_ops);
> if (IS_ERR(phy->phy)) {
> dev_err(dev, "Failed to create PHY\n");
[Severity: High]
This is a pre-existing issue, but does this code leave a dangling pointer
when saving the node?
Looking at rcar_gen2_phy_probe(), we save np to channel->of_node:
for_each_child_of_node_scoped(dev->of_node, np) {
struct rcar_gen2_channel *channel = drv->channels + i;
...
channel->of_node = np;
Because for_each_child_of_node_scoped() automatically drops the reference on
the node when advancing or exiting, channel->of_node becomes a dangling pointer.
Later in rcar_gen2_phy_xlate(), this potentially dangling pointer is
used for comparison:
if (np == drv->channels[i].of_node)
Could this falsely match a newly allocated node due to pointer aliasing if a
DT overlay is applied and removed? Should we call of_node_get() before
saving it to channel->of_node?
[Severity: High]
This is also a pre-existing issue, but is there a potential out-of-bounds write
if the number of child nodes changes?
Earlier in rcar_gen2_phy_probe(), the driver allocates the channels array based
on the child count:
drv->num_channels = of_get_child_count(dev->of_node);
drv->channels = devm_kcalloc(dev, drv->num_channels, ...);
Then it iterates over the children and increments i:
for_each_child_of_node_scoped(dev->of_node, np) {
struct rcar_gen2_channel *channel = drv->channels + i;
...
i++;
}
If child nodes are added dynamically (e.g., via a DT overlay) between the call
to of_get_child_count() and the for_each_child_of_node_scoped() loop, could i
exceed drv->num_channels and cause an out-of-bounds write when accessing
drv->channels + i?
> - of_node_put(np);
> return PTR_ERR(phy->phy);
> }
> phy_set_drvdata(phy->phy, phy);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260804-rcar-gen2-v2-0-829cb84112ca@gmail.com?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-08-04 15:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-04 15:24 [PATCH v2 0/3] phy: renesas: rcar-gen2: three cleanups Felix Gu
2026-08-04 15:24 ` [PATCH v2 1/3] phy: renesas: rcar-gen2: Fix double of_node_put on phy creation failure Felix Gu
2026-08-04 15:38 ` sashiko-bot [this message]
2026-08-04 15:24 ` [PATCH v2 2/3] phy: renesas: rcar-gen2: Return -EINVAL for out-of-range channel reg Felix Gu
2026-08-04 15:49 ` sashiko-bot
2026-08-04 15:24 ` [PATCH v2 3/3] phy: renesas: rcar-gen2: Use dev_err_probe() in probe Felix Gu
2026-08-04 15:59 ` 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=20260804153801.3EB0D1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=neil.armstrong@linaro.org \
--cc=olteanv@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=ustc.gu@gmail.com \
--cc=vkoul@kernel.org \
--cc=wsa+renesas@sang-engineering.com \
/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