From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796404425; b=NOFS7Lh7fvw87ZYRud+5rS1qa5VGuOS+aIZkMRQtZ9Nu/chbFKaPijSynz4A3b8qstmt EhrSYiZRciR5RIoQvFv82lM9QaGS7EsrVNHPL6rIXca2EuiLeP8EMcKyQ9HlvqZ2Fvjcl ApKwi57X+cb2lbNqsp3HXh70HGwTj3g4eL7fbBNl4wiAdgpodwMejBJUjLxrOWgs7oA7s 5pnzyJyMOhltqz9CZk+/Q/wMRE/rmZ7+McltumRvePCBMc/9qAH7S5u4xR9sxUo1dLm6r E5/7oG/ISa66cYQPa2OJoNpvj1kby870gvreF+romrVOAsKNdKH8tBgDbUqxAx+r3YA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796404425; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=pfQGy7NfKYTjaZm4xq46i4oe2tAXai7Q0+D+i4b5+kg=; b=rUzWeZ7aTcXcxX/7X9HP6ZXQsrEZVM/UAfj8SwxRPjZQL8INSCrI5lxdd8g27OhhiuA/ eTlNSsws3afuue6b1U8jGgjRv6gt3d+coXwUi528DUQN/0GSsKe57kYajPzAsJW1LY4jk uwcX+U7VOyCIiQr2cay2sSrsdGaxwSEIw0+r57C6B0H2avy0vJ/HqUuWg3tDgPPLeznWp rS2AlKG5pj8U+lRcWRkTZyoRT82ZtyM7D61J1ygW5I3u2XegwMZlDyg2EbyaKIWD9hGn1 4XBunVTPaeGkzUzUkZIDX2TpH9Nk+oae7djxPcNeYq4KvOUsSFQFh7DPCeBl7pFI2LA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dupJR+Yr; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8486606A322; Fri, 4 Dec 2026 17:13:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dupJR+Yr Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56BB61F00A1D; Fri, 4 Dec 2026 17:13:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796404425; bh=pfQGy7NfKYTjaZm4xq46i4oe2tAXai7Q0+D+i4b5+kg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=dupJR+YrGarNLy/fsGUeLrOdfnjB2TlvghprqXMfBypGR1PjJkC5rZ5myPN6nWg09 2PLr06TGCLSos7WhTfX9gygyk+ocZHFp+i2AisfVLUEEgMEidrxNQfib2qarQciePQ MixXbslmmZBGzDSKoWHCMHyXOExY+V0Vw8Kie0HLHkY/UoDSkrhYZoych/lIFlZFUi w4N3FMS1CJ6I40OxdV3DERa+poOmm+HgJL1qvxhwoZ7ES/WwcLiBpfzfben6itekg7 MiByAcUCuOX2Btha7CoaMhdf1nxIVIh5OMN3Qd2rlSlv7hsajsfQohor8f5/Io3DsG NZA1DbNNlLuqA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 09/13] clk: berlin: add Synaptics clock controller helpers Reply-To: sashiko-reviews@lists.linux.dev To: "Jisheng Zhang" Cc: devicetree@vger.kernel.org, linux-clk@vger.kernel.org, linux-gpio@vger.kernel.org, mfd@lists.linux.dev, robh@kernel.org, conor+dt@kernel.org, lee@kernel.org In-Reply-To: <20261204140732.31223-10-jszhang@kernel.org> References: <20261204140732.31223-1-jszhang@kernel.org> <20261204140732.31223-10-jszhang@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 17:13:44 +0000 X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 8 potential issues to consider: - [High] clk: berlin: IRQ-unsafe spinlock in sl_sysmgr_gateclk_ops - [Medium] clk: berlin: uninitialized struct clk_init_data in sl-sysmgr-clk.c - [Medium] clk: berlin: sl_clk_determine_rate() ignores min_rate and max_rate - [Medium] clk: berlin: sl_clk_get_parent() returns 0 on unsupported selector - [Medium] clk: berlin: sl_sysmgr_clk_ops and gateclk ops omit .disable callback - [Medium] clk: berlin: sl_sysmgr_clk_setup() ignores descriptor flags - [Medium] clk: berlin: sl_clk_value() maps DIV_SEL 0, 6, 7 to 0 instead of 1 - [Low] clk: berlin: sl-sysmgr-clk.h is not self-contained and has unused items -- commit 7ae4f8ba2e3b37f62f72f67fa5bfa73fb4501645 Author: Jisheng Zhang clk: berlin: add Synaptics clock controller helpers This commit adds the shared configurable divider/gate clock driver (sl-clk.c) and the MCU system manager clock helper (sl-sysmgr-clk.c) for Synaptics SL SoCs. > diff --git a/drivers/clk/berlin/sl-clk.c b/drivers/clk/berlin/sl-clk.c > new file mode 100644 > index 0000000000000..e212320a0637d > --- /dev/null > +++ b/drivers/clk/berlin/sl-clk.c > @@ -0,0 +1,279 @@ [ ... ] > +static unsigned int sl_clk_value(u32 val) > +{ > + static const u8 div_table[] =3D { 0, 2, 4, 6, 8, 12, 0, 0 }; > + > + if (val & SL_CLK_DIV3_SWITCH) > + return 3; > + if (!(val & SL_CLK_DIV_SWITCH)) > + return 1; > + > + return div_table[FIELD_GET(SL_CLK_DIV_SEL, val)]; > +} > + > +static unsigned long sl_clk_recalc_rate(struct clk_hw *hw, > + unsigned long parent_rate) > +{ > + struct sl_clk *clk =3D to_sl_clk(hw); > + unsigned int divisor =3D sl_clk_value(readl_relaxed(clk->reg)); > + > + if (WARN_ON_ONCE(!divisor)) > + return 0; > + > + return parent_rate / divisor; > +} [Severity: Medium] Should div_table[] map SL_CLK_DIV_SEL encodings 0, 6, and 7 to 1 rather than 0? This register layout matches BERLIN2_SINGLE_DIV in berlin2-div.h, where berlin2-div.c maps those encodings to divide-by-1 in clk_div[]. If reset or firmware leaves SL_CLK_DIV_SWITCH set with SL_CLK_DIV_SEL in {0, 6, 7}, sl_clk_recalc_rate() triggers WARN_ON_ONCE(!divisor) and reports 0 Hz for the clock and its children. > + > +static unsigned int sl_clk_best(unsigned long parent_rate, > + unsigned long rate) > +{ > + unsigned long best_diff =3D ULONG_MAX; > + unsigned int best =3D 1, i; > + > + for (i =3D 0; i < ARRAY_SIZE(sl_clk_values); i++) { > + unsigned long candidate =3D parent_rate / sl_clk_values[i]; > + unsigned long diff =3D candidate > rate ? candidate - rate : > + rate - candidate; > + > + if (diff < best_diff) { > + best_diff =3D diff; > + best =3D sl_clk_values[i]; > + } > + } > + > + return best; > +} > + > +static int sl_clk_determine_rate(struct clk_hw *hw, > + struct clk_rate_request *req) > +{ > + struct clk_hw *parent =3D clk_hw_get_parent(hw); > + > + if (!parent) > + return -EINVAL; > + > + req->best_parent_hw =3D parent; > + req->best_parent_rate =3D clk_hw_get_rate(parent); > + req->rate =3D req->best_parent_rate / > + sl_clk_best(req->best_parent_rate, req->rate); > + > + return 0; > +} [Severity: Medium] Does sl_clk_determine_rate() need to respect req->min_rate and req->max_rate? sl_clk_best() picks the closest divisor across sl_clk_values[] without checking rate bounds. For example, with a 1200 MHz parent and req->max_rate =3D 360 MHz, it selects divisor 3 (400 MHz) instead of divisor 4 (300 MHz), causing clk_calc_new_rates() to reject the rate and fail clk_set_rate() with -EINVAL even though a valid in-range divisor exists. Filtering candidates to [req->min_rate, req->max_rate] and returning -EINVAL if none fits avoids this. [ ... ] > +static u8 sl_clk_get_parent(struct clk_hw *hw) > +{ > + struct sl_clk *clk =3D to_sl_clk(hw); > + u32 val =3D readl_relaxed(clk->reg); > + u8 selector; > + unsigned int index; > + > + if (!(val & SL_CLK_PLL_SWITCH)) > + return 0; > + > + selector =3D FIELD_GET(SL_CLK_PLL_SEL, val); > + index =3D selector + 1; > + if (index < clk_hw_get_num_parents(hw)) > + return index; > + > + dev_warn(clk->dev, "%s: unsupported parent selector %u\n", > + clk_hw_get_name(hw), selector); > + return 0; > +} [Severity: Medium] Should sl_clk_get_parent() return an out-of-range index instead of 0 when hardware has an unsupported parent selector? Returning 0 makes __clk_init_parent() attach the clock to parent 0 even though SL_CLK_PLL_SWITCH is still set to the invalid selector. Any later clk_set_parent() targeting parent 0 then short-circuits in clk_core_set_parent_nolock() because core->parent already matches, leaving hardware stuck on the unsupported selector. Returning index (or clk_hw_get_num_parents(hw)) lets clk_core_get_parent_by_index() treat the clock as orphaned until reparented. [ ... ] > diff --git a/drivers/clk/berlin/sl-sysmgr-clk.c b/drivers/clk/berlin/sl-s= ysmgr-clk.c > new file mode 100644 > index 0000000000000..f3cf921fc3c1a > --- /dev/null > +++ b/drivers/clk/berlin/sl-sysmgr-clk.c > @@ -0,0 +1,241 @@ [ ... ] > +static DEFINE_SPINLOCK(sl_sysmgr_gateclk_lock); > + > +#define to_sl_sysmgr_gateclk(hw) container_of(hw, struct sl_sysmgr_gatec= lk, hw) > +#define to_sl_sysmgr_clk(hw) container_of(hw, struct sl_sysmgr_clk, hw) > + > +static int sl_sysmgr_gateclk_enable(struct clk_hw *hw) > +{ > + u32 val; > + struct sl_sysmgr_gateclk *clk =3D to_sl_sysmgr_gateclk(hw); > + > + guard(spinlock)(&sl_sysmgr_gateclk_lock); > + > + val =3D readl_relaxed(clk->base); > + if (!(val & BIT(clk->bit_idx))) { > + val |=3D BIT(clk->bit_idx); > + writel_relaxed(val, clk->base); > + } > + > + return 0; > +} > + > +static int sl_sysmgr_gateclk_is_enabled(struct clk_hw *hw) > +{ > + u32 val; > + struct sl_sysmgr_gateclk *clk =3D to_sl_sysmgr_gateclk(hw); > + > + guard(spinlock)(&sl_sysmgr_gateclk_lock); > + > + val =3D readl_relaxed(clk->base); > + val &=3D BIT(clk->bit_idx); > + > + return val ? 1 : 0; > +} [Severity: High] Can acquiring sl_sysmgr_gateclk_lock without disabling interrupts cause a hardirq deadlock? clk_core_enable() calls sl_sysmgr_gateclk_enable() while holding CCF's hardirq-safe enable_lock, whereas clk_summary_show_one() calls sl_sysmgr_gateclk_is_enabled() in process context with interrupts enabled and without enable_lock: CPU0 CPU1 ---- ---- lock(&sl_sysmgr_gateclk_lock) lock(&enable_lock) lock(&sl_sysmgr_gateclk_lock) lock(&enable_lock) *** DEADLOCK *** CPU0: clk_summary_show_one() -> clk_core_is_enabled() -> sl_sysmgr_gateclk_is_enabled() clk_enable() -> clk_core_enable_lock() CPU1: clk_enable() -> clk_core_enable_lock() -> sl_sysmgr_gateclk_enable() A hardirq enabling a SysMgr gate clock on the same CPU also self-deadlocks on sl_sysmgr_gateclk_lock. Since sl_sysmgr_gateclk_is_enabled() only performs a single 32-bit readl_relaxed(), dropping the lock there and using guard(spinlock_irqsave) on the write path avoids both the deadlock and unnecessary global contention. > + > +static const struct clk_ops sl_sysmgr_gateclk_ops =3D { > + .enable =3D sl_sysmgr_gateclk_enable, > + .is_enabled =3D sl_sysmgr_gateclk_is_enabled, > +}; [Severity: Medium] Why do sl_sysmgr_gateclk_ops and sl_sysmgr_clk_ops omit .disable? Without .disable, clk_disable() and clk_disable_unused() cannot gate these clocks off in hardware once enabled. In addition, clk_is_enabled_when_prepared() checks !(ops->enable && ops->disable) and falsely returns true, causing pm_clk_acquire() to misclassify these clocks as enabled when prepared. Separately, sl_sysmgr_gateclk duplicates devm_clk_hw_register_gate(), and struct sl_sysmgr_gateclk_desc duplicates struct sl_gateclk_desc in sl-clk.h. > + > +static int > +sl_sysmgr_gateclk_register(struct device *dev, struct sl_sysmgr_gateclk = *gclk, > + const char *name, const char *parent_names, > + u8 bit_idx, void __iomem *base) > +{ > + struct clk_init_data init; > + > + init.name =3D name; > + init.ops =3D &sl_sysmgr_gateclk_ops; > + init.parent_names =3D &parent_names; > + init.num_parents =3D 1; > + init.flags =3D 0; [Severity: Medium] Does leaving init uninitialized here and in sl_sysmgr_clk_register() pass uninitialized stack memory into clk_core_populate_parent_map()? Neither function initializes init.parent_data or init.parent_hws, which clk_core_populate_parent_map() reads unconditionally during clock registration, triggering KMSAN warnings. Zero-initializing with struct clk_init_data init =3D {}; (as sl_clk_register() does) avoids this. [ ... ] > + for (i =3D 0; i < gclk_n; i++) { > + ret =3D sl_sysmgr_gateclk_register(&pdev->dev, &priv->gclks[i], > + gdescs[i].name, gdescs[i].parent_name, > + gdescs[i].bit_idx, base + gclk_offset); > + if (ret) > + return ret; > + > + id =3D gdescs[i].id; > + clk_data->hws[id] =3D &priv->gclks[i].hw; > + } > + > + for (i =3D 0; i < clk_n; i++) { > + ret =3D sl_sysmgr_clk_register(&pdev->dev, &priv->clks[i], > + descs[i].name, descs[i].parent_name, > + descs[i].div_bits, base + descs[i].offset); [Severity: Medium] Should sl_sysmgr_clk_setup() pass gdescs[i].flags and descs[i].flags to the registration helpers? Both struct sl_sysmgr_gateclk_desc and struct sl_sysmgr_clk_desc expose a flags field, but sl_sysmgr_gateclk_register() and sl_sysmgr_clk_register() hardcode init.flags =3D 0, silently discarding flags such as CLK_IS_CRITICAL or CLK_IGNORE_UNUSED. [ ... ] > diff --git a/drivers/clk/berlin/sl-sysmgr-clk.h b/drivers/clk/berlin/sl-s= ysmgr-clk.h > new file mode 100644 > index 0000000000000..5ccf388bcccbd > --- /dev/null > +++ b/drivers/clk/berlin/sl-sysmgr-clk.h > @@ -0,0 +1,44 @@ [ ... ] > +#ifndef __SL_SYSMGR_CLK_H > +#define __SL_SYSMGR_CLK_H > + > +struct sl_sysmgr_clk_desc { > + const char *name; > + const char *parent_name; > + u32 id; > + u32 offset; > + u8 div_bits; > + unsigned long flags; > +}; [ ... ] > +int sl_sysmgr_clk_setup(struct platform_device *pdev, [Severity: Low] Can sl-sysmgr-clk.h be included standalone? It uses u32, u8, and struct platform_device without including linux/types.h or forward-declaring struct platform_device, which fails to build if included before those headers. In sl-sysmgr-clk.c, linux/version.h and DIV_CHNG_EN are also unused. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204140732.3122= 3-1-jszhang@kernel.org?part=3D9