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, devicetree@vger.kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v3 09/18] clk: mediatek: Add MT8189 apmixedsys clock support
Date: Tue, 21 Jul 2026 10:05:31 +0000	[thread overview]
Message-ID: <20260721100531.5F98A1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260720-mt8189-clocks-system-base-v3-9-8e6d99ab3ad2@collabora.com>

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

New issues:
- [High] The `PLL_SETCLR` macro omits `.ops` and `.pwr_reg`, causing `mtk_pll_prepare()` to corrupt offset 0 of the APMIXEDSYS controller.

Pre-existing issues:
- [High] Stale state in the static `pllfhs` array persists after unbind, causing unmapped memory access (Use-After-Free) if the driver is rebound and `fhctl_parse_dt()` fails.
--

--- Patch [9]: [PATCH v3 09/18] clk: mediatek: Add MT8189 apmixedsys clock support ---
commit 025aa9a1940ce762ce47408b18d63d2592369750
Author: Louis-Alexis Eyraud <louisalexis.eyraud@collabora.com>

clk: mediatek: Add MT8189 apmixedsys clock support

Add support for the MT8189 apmixedsys clock controller, which provides
PLLs generated from SoC 26m.

> diff --git a/drivers/clk/mediatek/clk-mt8189-apmixedsys.c b/drivers/clk/mediatek/clk-mt8189-apmixedsys.c
> new file mode 100644
> --- /dev/null
> +++ b/drivers/clk/mediatek/clk-mt8189-apmixedsys.c

[ ... ]

> +#define PLL_SETCLR(_id, _name, _reg, _en_setclr_bit,		\
> +			_rstb_setclr_bit, _flags, _pd_reg,	\
> +			_pd_shift, _tuner_reg, _tuner_en_reg,	\
> +			_tuner_en_bit, _pcw_reg, _pcw_shift,	\
> +			_pcwbits) {				\
> +		.id = _id,					\
> +		.name = _name,					\
> +		.en_reg = MT8189_PLLEN_OFS,			\
> +		.reg = _reg,					\
> +		.pll_en_bit = _en_setclr_bit,			\
> +		.rst_bar_mask = BIT(_rstb_setclr_bit),		\
> +		.flags = _flags,				\
> +		.fmax = MT8189_PLL_FMAX,			\
> +		.fmin = MT8189_PLL_FMIN,			\
> +		.pd_reg = _pd_reg,				\
> +		.pd_shift = _pd_shift,				\
> +		.tuner_reg = _tuner_reg,			\
> +		.tuner_en_reg = _tuner_en_reg,			\
> +		.tuner_en_bit = _tuner_en_bit,			\
> +		.pcw_reg = _pcw_reg,				\
> +		.pcw_shift = _pcw_shift,			\
> +		.pcwbits = _pcwbits,				\
> +		.pcwibits = MT8189_INTEGER_BITS,		\
> +	}

[Severity: High]
Does this macro need to initialize .ops and .pwr_reg?

Because .pwr_reg defaults to 0 and .ops is missing, the clock core will fall
back to the default mtk_pll_ops. When mtk_pll_prepare() is called, it seems
it will unconditionally read and write to base + 0 (since pwr_reg is 0).

Will this inadvertently toggle bits 0 and 1 of the register at offset 0
every time a PLL is prepared or unprepared?

Additionally, falling back to the default ops causes the driver to perform
non-atomic read-modify-write operations on the enable register instead of
using the intended SET/CLR operations.

[ ... ]

> +static struct mtk_pllfh_data pllfhs[] = {
> +	FH(CLK_APMIXED_ARMPLL_LL, 0, 0x003C),
> +	FH(CLK_APMIXED_ARMPLL_BL, 1, 0x0050),
> +	FH(CLK_APMIXED_CCIPLL, 2, 0x0064),
> +	FH(CLK_APMIXED_MAINPLL, 3, 0x0078),
> +	FH(CLK_APMIXED_MMPLL, 4, 0x008C),
> +	FH(CLK_APMIXED_MFGPLL, 5, 0x00A0),
> +	FH(CLK_APMIXED_EMIPLL, 6, 0x00B4),
> +	FH(CLK_APMIXED_TVDPLL1, 7, 0x00C8),
> +	FH(CLK_APMIXED_TVDPLL2, 8, 0x00DC),
> +	FH(CLK_APMIXED_MSDCPLL, 9, 0x00F0),
> +	FH(CLK_APMIXED_UFSPLL, 10, 0x0104),
> +	FH(CLK_APMIXED_APUPLL, 11, 0x0118),
> +	FH(CLK_APMIXED_APUPLL2, 12, 0x012c),
> +};

[Severity: High]
This is a pre-existing issue, but does this static array retain stale state
across driver unbind and rebind cycles?

During a successful probe, fhctl_parse_dt() sets pllfh->state.fh_enable = 1
and stores the mapped I/O pointer in pllfh->state.base. When the driver is
unbound, mtk_clk_unregister_pllfhs() unmaps this memory but doesn't appear
to clear the state in the static array.

If the driver is later rebound and fhctl_parse_dt() fails (for example, due
to an of_iomap failure), it returns without updating the array. Will
mtk_clk_register_pllfhs() then read the stale fh_enable == 1 and pass the
unmapped state.base pointer to the clock framework, leading to unmapped memory
accesses on subsequent clock operations?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260720-mt8189-clocks-system-base-v3-0-8e6d99ab3ad2@collabora.com?part=9

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

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-20 10:04 [PATCH v3 00/18] MT8189: Add support for system and base clock controllers Louis-Alexis Eyraud
2026-07-20 10:04 ` [PATCH v3 01/18] dt-bindings: clock: mediatek: Make '#clock-cells' required for MT8186 Louis-Alexis Eyraud
2026-07-20 10:04 ` [PATCH v3 02/18] dt-bindings: clock: mediatek: Make '#clock-cells' required for MT8192 Louis-Alexis Eyraud
2026-07-21 10:05   ` sashiko-bot
2026-07-20 10:04 ` [PATCH v3 03/18] dt-bindings: clock: mediatek: Make '#clock-cells' required for MT8195 Louis-Alexis Eyraud
2026-07-21 10:05   ` sashiko-bot
2026-07-20 10:04 ` [PATCH v3 04/18] dt-bindings: clock: mediatek: reorder MT8186 compatibles Louis-Alexis Eyraud
2026-07-20 10:04 ` [PATCH v3 05/18] dt-bindings: clock: mediatek: regroup MT8188 dt-bindings into MT8186 Louis-Alexis Eyraud
2026-07-21 10:05   ` sashiko-bot
2026-07-20 10:04 ` [PATCH v3 06/18] dt-bindings: clock: mediatek: regroup MT8192 " Louis-Alexis Eyraud
2026-07-20 10:04 ` [PATCH v3 07/18] dt-bindings: clock: mediatek: regroup MT8195 " Louis-Alexis Eyraud
2026-07-21 10:05   ` sashiko-bot
2026-07-20 10:04 ` [PATCH v3 08/18] dt-bindings: clock: mediatek: Add MT8189 system/base clocks and resets Louis-Alexis Eyraud
2026-07-21 10:05   ` sashiko-bot
2026-07-20 10:04 ` [PATCH v3 09/18] clk: mediatek: Add MT8189 apmixedsys clock support Louis-Alexis Eyraud
2026-07-21 10:05   ` sashiko-bot [this message]
2026-07-21 23:04   ` Brian Masney
2026-07-20 10:04 ` [PATCH v3 10/18] clk: mediatek: Add MT8189 topckgen " Louis-Alexis Eyraud
2026-07-21 10:05   ` sashiko-bot
2026-07-20 10:04 ` [PATCH v3 11/18] clk: mediatek: Add MT8189 vlpckgen " Louis-Alexis Eyraud
2026-07-20 10:04 ` [PATCH v3 12/18] clk: mediatek: Add MT8189 vlpcfg " Louis-Alexis Eyraud
2026-07-20 10:04 ` [PATCH v3 13/18] clk: mediatek: Add MT8189 bus " Louis-Alexis Eyraud
2026-07-21 10:05   ` sashiko-bot
2026-07-20 10:04 ` [PATCH v3 14/18] clk: mediatek: Add MT8189 dbgao " Louis-Alexis Eyraud
2026-07-20 10:04 ` [PATCH v3 15/18] clk: mediatek: Add MT8189 dvfsrc " Louis-Alexis Eyraud
2026-07-20 10:04 ` [PATCH v3 16/18] clk: mediatek: Add MT8189 i2c " Louis-Alexis Eyraud
2026-07-21 10:05   ` sashiko-bot
2026-07-20 10:04 ` [PATCH v3 17/18] clk: mediatek: Add MT8189 scp " Louis-Alexis Eyraud
2026-07-20 10:04 ` [PATCH v3 18/18] clk: mediatek: Add MT8189 ufs " Louis-Alexis Eyraud
2026-07-21 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=20260721100531.5F98A1F000E9@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.