[PATCH] clk: spacemit: Fix empty PLL rate table handling

Junhui Liu <[email protected]>
Newsgroups org.u-boot-project.lists.u-boot
Message-ID <[email protected]>
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 <[email protected]>
Signed-off-by: Junhui Liu <[email protected]>
---
 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 <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.