From: sashiko-bot@kernel.org
To: "Radhey Shyam Pandey" <radhey.shyam.pandey@amd.com>
Cc: linux-clk@vger.kernel.org
Subject: Re: [PATCH 3/3] clk: zynqmp: Fix unchecked type index into clock topology tables
Date: Tue, 01 Dec 2026 06:54:43 +0000 [thread overview]
Message-ID: <sashiko-outbox-242733@kernel.org> (raw)
In-Reply-To: <20261201064353.238312-4-radhey.shyam.pandey@amd.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] clk: zynqmp: stale num_nodes on error in
zynqmp_clock_get_topology()
--
commit 77850bd46c12a2a7c44b3c382e25533305881a70
Author: Beesam Sridhar Sagar <sagar.beesamsridhar@amd.com>
clk: zynqmp: Fix unchecked type index into clock topology tables
This commit validates the clock topology type returned by firmware against
the size of clk_topology[] and propagates the error from
__zynqmp_clock_get_topology().
> diff --git a/drivers/clk/zynqmp/clkc.c b/drivers/clk/zynqmp/clkc.c
> index 5d827b2bb0ad3..4ce376023d7fd 100644
> --- a/drivers/clk/zynqmp/clkc.c
> +++ b/drivers/clk/zynqmp/clkc.c
> @@ -418,6 +418,8 @@ static int __zynqmp_clock_get_topology(struct clock_topology *topology,
> type = FIELD_GET(CLK_TOPOLOGY_TYPE, response->topology[i]);
> if (type == TYPE_INVALID)
> return END_OF_TOPOLOGY_NODE;
> + if (type >= ARRAY_SIZE(clk_topology))
> + return -EINVAL;
> topology[*nnodes].type = type;
> topology[*nnodes].flag = FIELD_GET(CLK_TOPOLOGY_FLAGS,
> response->topology[i]);
> @@ -459,6 +461,8 @@ static int zynqmp_clock_get_topology(u32 clk_id,
> num_nodes);
> if (ret == END_OF_TOPOLOGY_NODE)
> return 0;
> + if (ret < 0)
> + return ret;
> }
>
> return 0;
[Severity: Medium]
Does returning an error here without resetting *num_nodes to 0 leave a
partially populated topology when an invalid type appears after one or more
valid nodes?
In zynqmp_get_clock_info(), a failure from zynqmp_clock_get_topology()
skips zynqmp_clock_get_parents(), leaving clock[i].num_nodes > 0 and
clock[i].num_parents == 0 while the clock remains valid:
drivers/clk/zynqmp/clkc.c:zynqmp_get_clock_info() {
...
ret = zynqmp_clock_get_topology(i, clock[i].node,
&clock[i].num_nodes);
if (ret)
continue;
ret = zynqmp_clock_get_parents(i, clock[i].parent,
&clock[i].num_parents);
...
}
zynqmp_register_clocks() then calls zynqmp_register_clk_topology() on the
partial nodes with total_parents == 0 and an untouched parent_names[]
array. Callbacks such as zynqmp_clk_register_fixed_factor() and
zynqmp_clk_register_gate() unconditionally pass parent_names[0] to the
clock framework, dereferencing either an uninitialized stack pointer or the
clk_out[j] buffer freed at the end of the previous clock's
zynqmp_register_clk_topology() call.
Resetting *num_nodes = 0 before returning a negative error from
zynqmp_clock_get_topology() would prevent registering the partial nodes.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201064353.238312-1-radhey.shyam.pandey@amd.com?part=3
prev parent reply other threads:[~2026-12-01 6:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 6:43 [PATCH 0/3] clk: zynqmp: fix out-of-bounds accesses in firmware clock parsing Radhey Shyam Pandey
2026-12-01 6:43 ` [PATCH 1/3] clk: zynqmp: Fix off-by-one loop bound in zynqmp_clock_get_topology() Radhey Shyam Pandey
2026-12-01 6:43 ` [PATCH 2/3] clk: zynqmp: Fix unbounded parent array overflow in clock parent lookup Radhey Shyam Pandey
2026-12-01 6:43 ` [PATCH 3/3] clk: zynqmp: Fix unchecked type index into clock topology tables Radhey Shyam Pandey
2026-12-01 6:54 ` 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=sashiko-outbox-242733@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=radhey.shyam.pandey@amd.com \
--cc=sashiko-reviews@lists.linux.dev \
/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