From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>
Cc: linux-clk@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v6 3/3] clk: en7523: add support for Airoha AN7583 clock
Date: Wed, 19 Aug 2026 22:27:42 +0000 [thread overview]
Message-ID: <20260819222743.5044F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260819221458.30040-4-ansuelsmth@gmail.com>
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
New issues:
- [Critical] The macro `REG_PCIE_HB_RST` is used but never defined, causing a build failure.
- [High] Requesting PCIC resets on AN7583 causes an out-of-bounds read on the `en7581_rst_ofs` array, leading to undefined hardware behavior or memory corruption.
Pre-existing issues:
- [High] Probe error paths cause a use-after-free by mixing `devm_kzalloc` with non-devres `clk_hw_register()` for the PCIe clock.
- [High] Read-modify-write operations on shared registers in the reset and clock controllers lack spinlocks, causing data races and lost writes.
- [High] The clock `.disable` callback calls `usleep_range()`, which sleeps while holding an IRQ-disabled spinlock.
--
--- Patch [3]: [PATCH v6 3/3] clk: en7523: add support for Airoha AN7583 clock ---
commit e4983d60cb386b35f51bc20a5f0912039bf92780
Author: Christian Marangi <ansuelsmth@gmail.com>
clk: en7523: add support for Airoha AN7583 clock
Add support for Airoha AN7583 clock and reset.
Airoha AN7583 SoC have the same register address of EN7581 but implement
different bits and additional base clocks. Also reset are different with
the introduction of 2 dedicated MDIO line and drop of some reset lines.
> diff --git a/drivers/clk/clk-en7523.c b/drivers/clk/clk-en7523.c
> index 087ff4568124f..493812c683f53 100644
> --- a/drivers/clk/clk-en7523.c
> +++ b/drivers/clk/clk-en7523.c
> @@ -505,6 +646,64 @@ static const u16 en751221_rst_map[] = {
> [EN751221_USB_PHY_P1_RST] = 3 * RST_NR_PER_BANK + 7,
> };
>
> +static const u16 an7583_rst_map[] = {
> + /* RST_CTRL2 */
> + [AN7583_XPON_PHY_RST] = 0,
> + [AN7583_GPON_OLT_RST] = 1,
[ ... ]
> + /* RST_PCIC */
> + [AN7583_PCIC_PERSTOUT0_RST] = 2 * RST_NR_PER_BANK + 29,
> + [AN7583_PCIC_PERSTOUT1_RST] = 2 * RST_NR_PER_BANK + 26,
> +};
[Severity: High]
Does this out-of-bounds array access corrupt memory when requesting PCIC resets?
The an7583_rst_map defines these PCIC resets in bank index 2.
When en7581_reset_register() is called later in this patch, it is passed
the en7581_rst_ofs array:
static const u16 en7581_rst_ofs[] = {
REG_RST_CTRL2,
REG_RST_CTRL1,
};
Since en7581_rst_ofs only has 2 elements, when en7523_reset_update()
dynamically calculates the bank index via id / RST_NR_PER_BANK, it evaluates
to 2. Accessing bank_ofs[2] will read out of bounds.
[ ... ]
> +static int an7583_clk_hw_init(struct platform_device *pdev,
> + struct clk_hw_onecell_data *clk_data)
> +{
> + struct device *dev = &pdev->dev;
> + struct regmap *map;
> + void __iomem *base;
> + u32 val;
> +
> + map = syscon_regmap_lookup_by_phandle(dev->of_node, "airoha,chip-scu");
> + if (IS_ERR(map))
> + return PTR_ERR(map);
> +
> + base = devm_platform_ioremap_resource(pdev, 0);
> + if (IS_ERR(base))
> + return PTR_ERR(base);
> +
> + en7581_register_clocks(dev, clk_data, map, base);
[Severity: High]
This isn't a bug introduced by this patch, but does the probe error path leave
us with a use-after-free for the PCIe clock?
In en7523_register_pcie_clk() which is called by en7581_register_clocks(),
the clk_hw structure is allocated via devm_kzalloc(), but registered with the
non-devres clk_hw_register():
cg = devm_kzalloc(dev, sizeof(*cg), GFP_KERNEL);
...
if (clk_hw_register(dev, &cg->hw))
If a subsequent initialization step fails in en7523_clk_probe() (like hw_init
returning an error), the driver core automatically frees the memory via devres,
but the clock framework retains dangling pointers to the freed clk_hw.
> +
> + val = readl(base + REG_RST_CTRL1);
> + val |= REG_PCIE_HB_RST;
[Severity: Critical]
Will this break the build due to an undefined macro?
The REG_PCIE_HB_RST macro is not defined anywhere. The existing code seems
to use REG_RESET_CONTROL_PCIEHB for this bit instead.
[Severity: High]
This is a pre-existing issue, but could this unlocked read-modify-write race
with the reset framework?
en7523_pci_prepare() modifies REG_RESET_CONTROL1 (0x834) without any locks:
val = readl(np_base + REG_RESET_CONTROL1);
mask = REG_RESET_CONTROL_PCIE1 | REG_RESET_CONTROL_PCIE2 |
REG_RESET_CONTROL_PCIEHB;
writel(val & ~mask, np_base + REG_RESET_CONTROL1);
Concurrently, en7523_reset_update() performs an unlocked read-modify-write
on the same register (REG_RST_CTRL1 is also 0x834):
val = readl(addr);
if (assert)
val |= BIT(id % RST_NR_PER_BANK);
...
writel(val, addr);
Since .prepare() runs in process context and resets can be triggered by
other probing devices concurrently, this seems likely to cause lost writes.
> + writel(val, base + REG_RST_CTRL1);
> + val &= ~REG_PCIE_HB_RST;
> + writel(val, base + REG_RST_CTRL1);
> +
> + return en7581_reset_register(dev, base, an7583_rst_map,
> + ARRAY_SIZE(an7583_rst_map),
> + en7581_rst_ofs);
> +}
[ ... ]
> +static const struct en_clk_soc_data an7583_data = {
> + .base_clks = an7583_base_clks,
> + /* We increment num_clocks by 1 to account for additional PCIe clock */
> + .num_clocks = ARRAY_SIZE(an7583_base_clks) + 1,
> + .pcie_ops = {
> + .is_enabled = en7581_pci_is_enabled,
> + .enable = en7581_pci_enable,
> + .disable = en7581_pci_disable,
> + },
[Severity: High]
This isn't a bug introduced by this patch, but does mapping en7581_pci_disable
to the .disable callback result in sleeping while in an atomic context?
The core clock framework invokes .disable callbacks with the enable_lock
spinlock held and hardware interrupts disabled.
However, en7581_pci_disable() explicitly yields and sleeps:
writel(val & ~mask, np_base + REG_PCI_CONTROL);
usleep_range(1000, 2000);
Could this cause a scheduling while atomic panic when the PCIe clock is
disabled?
> + .hw_init = an7583_clk_hw_init,
> +};
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260819221458.30040-1-ansuelsmth@gmail.com?part=3
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
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 [this message]
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=20260819222743.5044F1F000E9@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