All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: spacemit: Fix empty PLL rate table handling
@ 2026-08-01  8:54 Junhui Liu
  2026-08-01 16:57 ` Yao Zi
  0 siblings, 1 reply; 2+ messages in thread
From: Junhui Liu @ 2026-08-01  8:54 UTC (permalink / raw)
  To: Raymond Mao, Junhui Liu, u-boot
  Cc: Lukasz Majewski, Tom Rini, Guodong Xu, Yixun Lan, Coverity Scan

ccu_pll_lookup_best_rate() leaves best_entry uninitialized when the rate
table is empty. Initialize it to NULL and have ccu_pll_set_rate() return
-EINVAL when no matching entry is available.

Fixes: 3aa2882a3e1a ("clk: spacemit: Add support for K1 SoC")
Reported-by: Coverity Scan <scan-admin@coverity.com>
Signed-off-by: Junhui Liu <junhui.liu@pigmoral.tech>
---
 drivers/clk/spacemit/clk_pll.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/spacemit/clk_pll.c b/drivers/clk/spacemit/clk_pll.c
index 56da70af58af..d0fa43a4ee63 100644
--- a/drivers/clk/spacemit/clk_pll.c
+++ b/drivers/clk/spacemit/clk_pll.c
@@ -10,6 +10,7 @@
 #include <regmap.h>
 #include <linux/bug.h>
 #include <linux/clk-provider.h>
+#include <linux/errno.h>
 
 #include "clk_pll.h"
 
@@ -24,8 +25,8 @@
 static const struct ccu_pll_rate_tbl *ccu_pll_lookup_best_rate(struct ccu_pll *pll,
 							       unsigned long rate)
 {
+	const struct ccu_pll_rate_tbl *best_entry = NULL;
 	struct ccu_pll_config *config = &pll->config;
-	const struct ccu_pll_rate_tbl *best_entry;
 	unsigned long best_delta = ULONG_MAX;
 	int i;
 
@@ -105,6 +106,9 @@ static unsigned long ccu_pll_set_rate(struct clk *clk, unsigned long rate)
 	const struct ccu_pll_rate_tbl *entry;
 
 	entry = ccu_pll_lookup_best_rate(pll, rate);
+	if (!entry)
+		return -EINVAL;
+
 	ccu_pll_update_param(pll, entry);
 
 	return 0;

---
base-commit: 100e12ea78c73071b9710f08b32fd4590019266f
change-id: 20260801-k1-pll-fix-35dad5749dbb

Best regards,
--  
Junhui Liu <junhui.liu@pigmoral.tech>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] clk: spacemit: Fix empty PLL rate table handling
  2026-08-01  8:54 [PATCH] clk: spacemit: Fix empty PLL rate table handling Junhui Liu
@ 2026-08-01 16:57 ` Yao Zi
  0 siblings, 0 replies; 2+ messages in thread
From: Yao Zi @ 2026-08-01 16:57 UTC (permalink / raw)
  To: Junhui Liu, Raymond Mao, u-boot
  Cc: Lukasz Majewski, Tom Rini, Guodong Xu, Yixun Lan, Coverity Scan,
	Yao Zi

On Sat, Aug 01, 2026 at 04:54:24PM +0800, Junhui Liu wrote:
> ccu_pll_lookup_best_rate() leaves best_entry uninitialized when the rate
> table is empty. Initialize it to NULL and have ccu_pll_set_rate() return
> -EINVAL when no matching entry is available.

Does a PLL with no rate entries make any sense? No operation in ccu_pll.c
seems valid with an empty rate table, not only ccu_pll_lookup_best_rate().
And all PLLs defined so far come with at least one entry in their tables.

> Fixes: 3aa2882a3e1a ("clk: spacemit: Add support for K1 SoC")
> Reported-by: Coverity Scan <scan-admin@coverity.com>

So this looks like a false positive.

> Signed-off-by: Junhui Liu <junhui.liu@pigmoral.tech>

Regards,
Yao Zi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-01 16:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-01  8:54 [PATCH] clk: spacemit: Fix empty PLL rate table handling Junhui Liu
2026-08-01 16:57 ` Yao Zi

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.