From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>
Cc: linux-clk@vger.kernel.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v6 2/3] clk: en7523: generalize register clocks function
Date: Wed, 19 Aug 2026 22:27:48 +0000 [thread overview]
Message-ID: <20260819222748.F01B01F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260819221458.30040-3-ansuelsmth@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [Medium] Fragile loop boundary logic using `num_clocks - 1` risks out-of-bounds array access.
Pre-existing issues:
- [High] The PCIe clock gate is registered with an unmanaged API, leading to a Use-After-Free if probe fails.
- [High] Missing spinlock in reset controller update leads to data races and lost writes.
--
--- Patch [2]: [PATCH v6 2/3] clk: en7523: generalize register clocks function ---
commit c89fd9565e1664803408c338e740e001e5bb4ff0
Author: Christian Marangi <ansuelsmth@gmail.com>
clk: en7523: generalize register clocks function
This commit generalizes the clock registration logic for the EN7581 SoC
so it can be reused by the upcoming AN7583 SoC. It achieves this by
moving the base clocks array definition into the soc_data structure.
> diff --git a/drivers/clk/clk-en7523.c b/drivers/clk/clk-en7523.c
> index 1ab0e2eca5d32..087ff4568124f 100644
> --- a/drivers/clk/clk-en7523.c
> +++ b/drivers/clk/clk-en7523.c
[ ... ]
> @@ -711,12 +712,15 @@ static int en7523_clk_hw_init(struct platform_device *pdev,
> static void en7581_register_clocks(struct device *dev, struct clk_hw_onecell_data *clk_data,
> struct regmap *map, void __iomem *base)
> {
> + const struct en_clk_soc_data *soc_data;
> struct clk_hw *hw;
> u32 rate;
> int i;
>
> - for (i = 0; i < ARRAY_SIZE(en7581_base_clks); i++) {
> - const struct en_clk_desc *desc = &en7581_base_clks[i];
> + soc_data = device_get_match_data(dev);
> +
> + for (i = 0; i < soc_data->num_clocks - 1; i++) {
> + const struct en_clk_desc *desc = &soc_data->base_clks[i];
[Severity: Medium]
If a future SoC defines a clock provider count (num_clocks) that doesn't
exactly equal the number of elements in base_clks plus one, could this
loop iterate past the end of the base_clks array?
It seems this loop derives the base_clks array length from
soc_data->num_clocks - 1, mathematically conflating the total clock count
with the base clock array size.
While reviewing this, I noticed a couple of pre-existing issues in the same
file:
drivers/clk/clk-en7523.c:en7523_register_pcie_clk() {
...
cg = devm_kzalloc(dev, sizeof(*cg), GFP_KERNEL);
if (!cg)
return NULL;
...
if (clk_hw_register(dev, &cg->hw))
return NULL;
...
}
[Severity: High]
This is a pre-existing issue, but since the clock gate structure is allocated
using devres, won't it be automatically freed if probe fails?
Because the clock is registered with the non-managed clk_hw_register() API,
if a downstream operation during probe fails, the driver's probe will return
an error and trigger devres cleanup. Could this leave a dangling pointer
inside the Common Clock Framework and lead to a Use-After-Free?
drivers/clk/clk-en7523.c:en7523_reset_update() {
...
val = readl(addr);
if (assert)
val |= BIT(id % RST_NR_PER_BANK);
else
val &= ~BIT(id % RST_NR_PER_BANK);
writel(val, addr);
...
}
[Severity: High]
This isn't a bug introduced by this patch, but is it safe to perform this
read-modify-write operation on a shared register without a spinlock?
The reset core does not serialize .assert and .deassert operations, so if
multiple consumer drivers concurrently assert or deassert resets within the
same 32-bit register bank, it seems this unprotected read-modify-write
could lead to data races and lost writes.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260819221458.30040-1-ansuelsmth@gmail.com?part=2
next prev parent reply other threads:[~2026-08-19 22:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-19 22:14 [PATCH v6 0/3] clk: add support for Airoha AN7583 clock Christian Marangi
2026-08-19 22:14 ` [PATCH v6 1/3] dt-bindings: clock: airoha: Document support for " Christian Marangi
2026-08-19 22:21 ` sashiko-bot
2026-08-19 22:14 ` [PATCH v6 2/3] clk: en7523: generalize register clocks function Christian Marangi
2026-08-19 22:27 ` sashiko-bot [this message]
2026-08-19 22:14 ` [PATCH v6 3/3] clk: en7523: add support for Airoha AN7583 clock Christian Marangi
2026-08-19 22:27 ` sashiko-bot
2026-08-19 22:32 ` Christian Marangi
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=20260819222748.F01B01F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ansuelsmth@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=robh@kernel.org \
--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