Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Junhui Liu" <junhui.liu@pigmoral.tech>
Cc: robh@kernel.org, conor+dt@kernel.org,
	linux-sunxi@lists.linux.dev, devicetree@vger.kernel.org
Subject: Re: [PATCH v2 5/8] clk: sunxi-ng: a733: Add bus clocks support
Date: Sun, 12 Jul 2026 08:13:41 +0000	[thread overview]
Message-ID: <20260712081341.9D1431F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260711-a733-clk-v2-5-974d188cbe0c@pigmoral.tech>

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

Pre-existing issues:
- [Critical] Defining `mbus_clk` with a 0-width `P` prescaler causes undefined behavior in `ccu_mp_set_rate()`, leading to the critical memory bus clock register being completely cleared.
- [High] The MBUS clock requires an update bit to commit rate changes, but it is defined using `ccu_mp` operations which completely ignore the `CCU_FEATURE_UPDATE_BIT` flag.
--

--- Patch [5]: [PATCH v2 5/8] clk: sunxi-ng: a733: Add bus clocks support ---
commit 40f96b18647c7ab7dc42f9a7456046beab510ac6
Author: Junhui Liu <junhui.liu@pigmoral.tech>

clk: sunxi-ng: a733: Add bus clocks support

This commit adds the essential bus clocks in the Allwinner A733 CCU,
including AHB, APB0, APB1, APB_UART, and MBUS. It also marks the MBUS
clock as critical to ensure the memory bus remains operational.

> diff --git a/drivers/clk/sunxi-ng/ccu-sun60i-a733.c b/drivers/clk/sunxi-ng/ccu-sun60i-a733.c
> --- a/drivers/clk/sunxi-ng/ccu-sun60i-a733.c
> +++ b/drivers/clk/sunxi-ng/ccu-sun60i-a733.c

[ ... ]

> +static const struct clk_parent_data mbus_parents[] = {
> +	{ .hw = &sys_24M_clk.hw },
> +	{ .hw = &pll_periph1_600M_clk.hw },
> +	{ .hw = &pll_ddr_clk.common.hw },
> +	{ .hw = &pll_periph1_480M_clk.common.hw },
> +	{ .hw = &pll_periph1_400M_clk.hw },
> +	{ .hw = &pll_npu_clk.common.hw },
> +};
> +static SUNXI_CCU_MP_DATA_WITH_MUX_GATE_FEAT(mbus_clk, "mbus", mbus_parents, 0x588,
> +					    0, 5,	/* M */
> +					    0, 0,	/* no P */

[Severity: Critical]
This is a pre-existing issue in the framework, but does defining mbus_clk
with a 0-width P prescaler cause undefined behavior when the rate is set?

When ccu_mp_set_rate() is called in drivers/clk/sunxi-ng/ccu_mp.c, it
evaluates the mask for the P prescaler:

drivers/clk/sunxi-ng/ccu_mp.c:ccu_mp_set_rate() {
    ...
    reg &= ~GENMASK(cmp->p.width + cmp->p.shift - 1, cmp->p.shift);
    ...
}

Since p.width is 0, this expands to GENMASK(-1, 0). On 64-bit architectures,
the shift by 64 is masked to 0, which makes ~GENMASK evaluate to 0 and clears
the entire mbus_clk register, including the critical clock gate bit.

Could this lead to a system crash during boot or runtime frequency scaling?

> +					    24, 3,	/* mux */
> +					    BIT(31),	/* gate */
> +					    CLK_IS_CRITICAL,
> +					    CCU_FEATURE_UPDATE_BIT);

[Severity: High]
This is also a pre-existing issue in the framework, but will the hardware
actually commit rate changes for this clock?

The commit message notes that the hardware requires bit 27 to be set for
the configuration to take effect. However, ccu_mp_set_rate() does not
process the CCU_FEATURE_UPDATE_BIT flag before writing the register:

drivers/clk/sunxi-ng/ccu_mp.c:ccu_mp_set_rate() {
    ...
    writel(reg, cmp->common.base + cmp->common.reg);

    spin_unlock_irqrestore(cmp->common.lock, flags);
    ...
}

Since the update bit is never toggled by the ccu_mp operations, does this
leave the software state permanently out of sync with the hardware state
when the mbus_clk rate is configured?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260711-a733-clk-v2-0-974d188cbe0c@pigmoral.tech?part=5

  reply	other threads:[~2026-07-12  8:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-11  8:10 [PATCH v2 0/8] clk: sunxi-ng: Add support for Allwinner A733 CCU and PRCM Junhui Liu
2026-07-11  8:10 ` [PATCH v2 1/8] dt-bindings: clk: sun60i-a733-ccu: Add allwinner A733 support Junhui Liu
2026-07-12  8:13   ` sashiko-bot
2026-07-12 14:35   ` Krzysztof Kozlowski
2026-07-11  8:10 ` [PATCH v2 2/8] clk: sunxi-ng: sdm: Add dual patterns support Junhui Liu
2026-07-11  8:10 ` [PATCH v2 3/8] clk: sunxi-ng: a733: Add PRCM CCU Junhui Liu
2026-07-12  8:13   ` sashiko-bot
2026-07-11  8:10 ` [PATCH v2 4/8] clk: sunxi-ng: a733: Add PLL clocks support Junhui Liu
2026-07-12  8:13   ` sashiko-bot
2026-07-11  8:10 ` [PATCH v2 5/8] clk: sunxi-ng: a733: Add bus " Junhui Liu
2026-07-12  8:13   ` sashiko-bot [this message]
2026-07-11  8:10 ` [PATCH v2 6/8] clk: sunxi-ng: a733: Add mod " Junhui Liu
2026-07-12  8:13   ` sashiko-bot
2026-07-12 14:25   ` Junhui Liu
2026-07-11  8:10 ` [PATCH v2 7/8] clk: sunxi-ng: a733: Add bus clock gates Junhui Liu
2026-07-12  8:13   ` sashiko-bot
2026-07-12 14:29   ` Junhui Liu
2026-07-11  8:10 ` [PATCH v2 8/8] clk: sunxi-ng: a733: Add reset lines Junhui Liu
2026-07-12  8:13   ` 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=20260712081341.9D1431F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=junhui.liu@pigmoral.tech \
    --cc=linux-sunxi@lists.linux.dev \
    --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