Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yu-Chun Lin" <eleanor.lin@realtek.com>
Cc: krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org,
	devicetree@vger.kernel.org
Subject: Re: [PATCH v7 06/10] clk: realtek: Add support for mux clock
Date: Fri, 08 May 2026 22:21:11 +0000	[thread overview]
Message-ID: <20260508222112.6108EC2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260508111641.3192177-7-eleanor.lin@realtek.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] `clk_regmap_mux_get_parent()` masks hardware read errors and invalid states by defaulting to parent index 0.
- [Medium] Potential signed integer overflow in `clk_regmap_mux_set_parent()` when shifting the `u8 index` parameter.
--

commit 462409aad9f9756e1384cae76faf89758f477e12
Author: Cheng-Yu Lee <cylee12@realtek.com>

clk: realtek: Add support for mux clock

This commit adds a regmap-based clk_ops implementation for Realtek mux
clocks, supporting parent selection and rate determination.

> diff --git a/drivers/clk/realtek/clk-regmap-mux.c b/drivers/clk/realtek/clk-regmap-mux.c
> new file mode 100644
> index 0000000000000..1b0b8419d651f
> --- /dev/null
> +++ b/drivers/clk/realtek/clk-regmap-mux.c
[ ... ]
> +static u8 clk_regmap_mux_get_parent(struct clk_hw *hw)
> +{
> +	struct clk_regmap_mux *clkm = to_clk_regmap_mux(hw);
> +	int num_parents = clk_hw_get_num_parents(hw);
> +	u32 val;
> +	int ret;
> +
> +	ret = regmap_read(clkm->clkr.regmap, clkm->mux_ofs, &val);
> +	if (ret)
> +		return 0;
> +
> +	val = (val >> clkm->shift) & clkm->mask;
> +
> +	return val >= num_parents ? 0 : val;

Does returning 0 on hardware read errors or invalid states mask the error
from the clock framework?

If 0 is returned here, the framework might cache 0 as the active parent. If
a consumer later requests to set the parent to 0, the framework could
incorrectly assume the hardware is already in the correct state and skip the
set_parent call entirely.

Could this return an out-of-bounds index (like -EINVAL cast to u8) instead,
so the framework recognizes the parent as unknown and forces a hardware
update when a valid parent is requested?

> +}
> +
> +static int clk_regmap_mux_set_parent(struct clk_hw *hw, u8 index)
> +{
> +	struct clk_regmap_mux *clkm = to_clk_regmap_mux(hw);
> +
> +	return regmap_update_bits(clkm->clkr.regmap, clkm->mux_ofs,
> +				  clkm->mask << clkm->shift, index << clkm->shift);

Could the shift operation index << clkm->shift cause a signed integer
overflow?

Since index is a u8, it is implicitly promoted to a signed 32-bit int. If
the clock mux is configured at the most significant bit of a 32-bit
register (where clkm->shift is 31), shifting a non-zero index into the sign
bit triggers undefined behavior.

This might trigger a shift-out-of-bounds splat, which could lead to a panic
on systems with panic_on_warn enabled.

Would it be safer to explicitly cast index to an unsigned type, such as
(u32)index << clkm->shift?

> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260508111641.3192177-1-eleanor.lin@realtek.com?part=6

  reply	other threads:[~2026-05-08 22:21 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-08 11:16 [PATCH v7 00/10] clk: realtek: Add RTD1625 clock support Yu-Chun Lin
2026-05-08 11:16 ` [PATCH v7 01/10] dt-bindings: clock: Add Realtek RTD1625 Clock & Reset Controller Yu-Chun Lin
2026-05-08 11:16 ` [PATCH v7 02/10] reset: Add Realtek basic reset support Yu-Chun Lin
2026-05-08 11:16 ` [PATCH v7 03/10] clk: realtek: Introduce a common probe() Yu-Chun Lin
2026-05-08 21:24   ` sashiko-bot
2026-05-08 11:16 ` [PATCH v7 04/10] clk: realtek: Add support for phase locked loops (PLLs) Yu-Chun Lin
2026-05-08 21:41   ` sashiko-bot
2026-05-08 11:16 ` [PATCH v7 05/10] clk: realtek: Add support for gate clock Yu-Chun Lin
2026-05-08 11:16 ` [PATCH v7 06/10] clk: realtek: Add support for mux clock Yu-Chun Lin
2026-05-08 22:21   ` sashiko-bot [this message]
2026-05-08 11:16 ` [PATCH v7 07/10] clk: realtek: Add support for MMC-tuned PLL clocks Yu-Chun Lin
2026-05-08 22:42   ` sashiko-bot
2026-05-08 11:16 ` [PATCH v7 08/10] clk: realtek: Add RTD1625-CRT clock controller driver Yu-Chun Lin
2026-05-08 23:17   ` sashiko-bot
2026-05-08 11:16 ` [PATCH v7 09/10] clk: realtek: Add RTD1625-ISO " Yu-Chun Lin
2026-05-08 23:50   ` sashiko-bot
2026-05-08 11:16 ` [PATCH v7 10/10] arm64: dts: realtek: Add clock support for RTD1625 Yu-Chun Lin
2026-05-08 23:55   ` 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=20260508222112.6108EC2BCB0@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=eleanor.lin@realtek.com \
    --cc=krzk+dt@kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko@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