All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Louis-Alexis Eyraud" <louisalexis.eyraud@collabora.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 10/24] clk: mediatek: pll: Add BAR reset register offsets
Date: Thu, 30 Jul 2026 10:05:30 +0000	[thread overview]
Message-ID: <20260730100530.8F78D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260729-mt8189-clocks-system-base-v4-10-e356b813a64c@collabora.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Medium] The newly added set and clear registers for the BAR reset (`rst_bar_set_addr`, `rst_bar_clr_addr`) are computed but never used in the prepare/unprepare callbacks.

Pre-existing issues:
- [High] The error handling rollback in `mtk_clk_register_plls()` blindly unregisters and frees clocks it previously skipped, leading to Use-After-Free and heap corruption.
--

--- Patch [10]: [PATCH v4 10/24] clk: mediatek: pll: Add BAR reset register offsets ---
commit 32dac933eac13088132963fe76e93c2f164b2862
Author: Louis-Alexis Eyraud <louisalexis.eyraud@collabora.com>

clk: mediatek: pll: Add BAR reset register offsets

Currently, the register offset to handle BAR reset, for PLLs that
support it, is hardcoded to CON0. On MT8189 SoC, there are separate
status, set and clr registers to handle this, so differents offsets
are needed.

> diff --git a/drivers/clk/mediatek/clk-pll.c b/drivers/clk/mediatek/clk-pll.c
> index ee478bc640851..4b0f7e2bfc5a5 100644
> --- a/drivers/clk/mediatek/clk-pll.c
> +++ b/drivers/clk/mediatek/clk-pll.c
> @@ -249,9 +249,9 @@ int mtk_pll_prepare(struct clk_hw *hw)
>  	udelay(20);
>  
>  	if (pll->data->flags & HAVE_RST_BAR) {
> -		r = readl(pll->base_addr + REG_CON0);
> +		r = readl(pll->rst_bar_addr);
>  		r |= pll->data->rst_bar_mask;
> -		writel(r, pll->base_addr + REG_CON0);
> +		writel(r, pll->rst_bar_addr);

[Severity: Medium]
Will this fail to correctly assert the hardware reset BAR on the MT8189 SoC?

The newly added rst_bar_set_addr is computed in mtk_clk_register_pll_ops(),
but it is never used here. Is it intended to write to the dedicated set
register when it exists, rather than performing a read-modify-write on
rst_bar_addr?

>  	}
>  
>  	return 0;
> @@ -263,9 +263,9 @@ void mtk_pll_unprepare(struct clk_hw *hw)
>  	u32 r;
>  
>  	if (pll->data->flags & HAVE_RST_BAR) {
> -		r = readl(pll->base_addr + REG_CON0);
> +		r = readl(pll->rst_bar_addr);
>  		r &= ~pll->data->rst_bar_mask;
> -		writel(r, pll->base_addr + REG_CON0);
> +		writel(r, pll->rst_bar_addr);

[Severity: Medium]
Similar to mtk_pll_prepare(), should this be writing to the newly added
rst_bar_clr_addr instead of read-modify-writing rst_bar_addr?

>  	}
>  
>  	__mtk_pll_tuner_disable(pll);

[ ... ]

> int mtk_clk_register_plls(struct device *dev,
> 			  const struct mtk_pll_data *plls, int num_plls,
> 			  struct clk_hw_onecell_data *clk_data)
> {

[ ... ]

> 	for (i = 0; i < num_plls; i++) {
> 		const struct mtk_pll_data *pll = &plls[i];
> 
> 		if (!IS_ERR_OR_NULL(clk_data->hws[pll->id])) {
> 			pr_warn("%pOF: Trying to register duplicate clock ID: %d\n",
> 				dev->of_node, pll->id);
> 			continue;
> 		}

[ ... ]

> 	return 0;
> 
> err:
> 	while (--i >= 0) {
> 		const struct mtk_pll_data *pll = &plls[i];
> 
> 		mtk_clk_unregister_pll(clk_data->hws[pll->id]);

[Severity: High]
This isn't a bug introduced by this patch, but does this error handling
rollback cause a use-after-free and memory corruption?

If the registration loop encounters a duplicate clock ID and skips it using
continue, a subsequent failure in the array will trigger this rollback loop.

The rollback loop unconditionally unregisters clocks for all indices less than
the failing index i.  This will cause kfree() to be called on a clock
object that was skipped by this function and passed in from elsewhere,
destroying an actively used resource.

Should the rollback loop verify that the clock was actually registered by
this function before unregistering it?

> 		clk_data->hws[pll->id] = ERR_PTR(-ENOENT);
> 	}
> 
> 	iounmap(base);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260729-mt8189-clocks-system-base-v4-0-e356b813a64c@collabora.com?part=10

  reply	other threads:[~2026-07-30 10:05 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29 10:02 [PATCH v4 00/24] MT8189: Add support for system and base clock controllers Louis-Alexis Eyraud
2026-07-29 10:02 ` [PATCH v4 01/24] dt-bindings: clock: mediatek: Make '#clock-cells' required for MT8186 Louis-Alexis Eyraud
2026-07-30 10:05   ` sashiko-bot
2026-07-29 10:02 ` [PATCH v4 02/24] dt-bindings: clock: mediatek: Make '#clock-cells' required for MT8192 Louis-Alexis Eyraud
2026-07-29 10:02 ` [PATCH v4 03/24] dt-bindings: clock: mediatek: Make '#clock-cells' required for MT8195 Louis-Alexis Eyraud
2026-07-29 10:02 ` [PATCH v4 04/24] dt-bindings: clock: mediatek: reorder MT8186 compatibles Louis-Alexis Eyraud
2026-07-29 10:02 ` [PATCH v4 05/24] dt-bindings: clock: mediatek: regroup MT8188 dt-bindings into MT8186 Louis-Alexis Eyraud
2026-07-30 10:05   ` sashiko-bot
2026-07-29 10:02 ` [PATCH v4 06/24] dt-bindings: clock: mediatek: regroup MT8192 " Louis-Alexis Eyraud
2026-07-30 10:05   ` sashiko-bot
2026-07-29 10:02 ` [PATCH v4 07/24] dt-bindings: clock: mediatek: regroup MT8195 " Louis-Alexis Eyraud
2026-07-29 10:02 ` [PATCH v4 08/24] dt-bindings: clock: mediatek: Add MT8189 system/base clocks and resets Louis-Alexis Eyraud
2026-07-29 10:02 ` [PATCH v4 09/24] clk: mediatek: Harmonize mtk_pll_fenc related symbol names Louis-Alexis Eyraud
2026-07-29 10:02 ` [PATCH v4 10/24] clk: mediatek: pll: Add BAR reset register offsets Louis-Alexis Eyraud
2026-07-30 10:05   ` sashiko-bot [this message]
2026-07-29 10:02 ` [PATCH v4 11/24] clk: mediatek: pll: split default prepare/unprepare callbacks Louis-Alexis Eyraud
2026-07-29 10:02 ` [PATCH v4 12/24] clk: mediatek: pll: Add ops for PLLs using set/clr regs Louis-Alexis Eyraud
2026-07-30 10:05   ` sashiko-bot
2026-07-29 10:02 ` [PATCH v4 13/24] clk: mediatek: pllfh: Add configurable clock ops to mtk_pllfh_data Louis-Alexis Eyraud
2026-07-30 10:05   ` sashiko-bot
2026-07-29 10:02 ` [PATCH v4 14/24] clk: mediatek: pllfh: Add ops for PLLs using set/clr regs Louis-Alexis Eyraud
2026-07-30 10:05   ` sashiko-bot
2026-07-29 10:02 ` [PATCH v4 15/24] clk: mediatek: Add MT8189 apmixedsys clock support Louis-Alexis Eyraud
2026-07-30 10:05   ` sashiko-bot
2026-07-29 10:03 ` [PATCH v4 16/24] clk: mediatek: Add MT8189 topckgen " Louis-Alexis Eyraud
2026-07-30 10:05   ` sashiko-bot
2026-07-29 10:03 ` [PATCH v4 17/24] clk: mediatek: Add MT8189 vlpckgen " Louis-Alexis Eyraud
2026-07-29 10:03 ` [PATCH v4 18/24] clk: mediatek: Add MT8189 vlpcfg " Louis-Alexis Eyraud
2026-07-29 10:03 ` [PATCH v4 19/24] clk: mediatek: Add MT8189 bus " Louis-Alexis Eyraud
2026-07-29 10:03 ` [PATCH v4 20/24] clk: mediatek: Add MT8189 dbgao " Louis-Alexis Eyraud
2026-07-29 10:03 ` [PATCH v4 21/24] clk: mediatek: Add MT8189 dvfsrc " Louis-Alexis Eyraud
2026-07-29 10:03 ` [PATCH v4 22/24] clk: mediatek: Add MT8189 i2c " Louis-Alexis Eyraud
2026-07-29 10:03 ` [PATCH v4 23/24] clk: mediatek: Add MT8189 scp " Louis-Alexis Eyraud
2026-07-29 10:03 ` [PATCH v4 24/24] clk: mediatek: Add MT8189 ufs " Louis-Alexis Eyraud
2026-07-30 10:05   ` 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=20260730100530.8F78D1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=louisalexis.eyraud@collabora.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.