[PATCH] clk: renesas: Do not test unsigned variable to be less than 0

Andrew Goodbody andrew.goodbody at linaro.org
Thu Jul 24 12:48:12 CEST 2025


In rcar_clk_set_rate64_div_table the unsigned variable 'value' is used
to receive the return value from rcar_clk_get_table_val which returns an
int and then attempts to test for being less than 0, which can never be
true. Instead declare value as an int so the code can behave as
expected. Also remove initial values from 'value' and 'div' as they are
not needed.

This issue was found by Smatch.

Signed-off-by: Andrew Goodbody <andrew.goodbody at linaro.org>
---
 drivers/clk/renesas/rcar-cpg-lib.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/renesas/rcar-cpg-lib.c b/drivers/clk/renesas/rcar-cpg-lib.c
index ea33bfd3239..60ab2cb379e 100644
--- a/drivers/clk/renesas/rcar-cpg-lib.c
+++ b/drivers/clk/renesas/rcar-cpg-lib.c
@@ -92,7 +92,8 @@ int rcar_clk_set_rate64_div_table(unsigned int parent, u64 parent_rate, ulong ra
 				  void __iomem *reg, const u32 mask,
 				  const struct clk_div_table *table, char *name)
 {
-	u32 value = 0, div = 0;
+	u32 div;
+	int value;
 
 	div = DIV_ROUND_CLOSEST(parent_rate, rate);
 	value = rcar_clk_get_table_val(table, div);
@@ -101,7 +102,7 @@ int rcar_clk_set_rate64_div_table(unsigned int parent, u64 parent_rate, ulong ra
 
 	clrsetbits_le32(reg, mask, field_prep(mask, value));
 
-	debug("%s[%i] %s clk: parent=%i div=%u rate=%lu => val=%u\n",
+	debug("%s[%i] %s clk: parent=%i div=%u rate=%lu => val=%d\n",
 	      __func__, __LINE__, name, parent, div, rate, value);
 
 	return 0;

---
base-commit: bd0ade7d090a334b3986936d63a34001d99722ad
change-id: 20250724-rcar-cpg-lib-d13c0763257e

Best regards,
-- 
Andrew Goodbody <andrew.goodbody at linaro.org>



More information about the U-Boot mailing list