[PATCH] clk: mtk: use IS_ERR_VALUE() to check rate return values

David Lechner dlechner at baylibre.com
Wed Jan 14 23:58:57 CET 2026


Replace casting with long to IS_ERR_VALUE() macro to check for error
return values from rate calculation functions. This is the recommended
way to check the return value from clock rate functions.

Signed-off-by: David Lechner <dlechner at baylibre.com>
---
 drivers/clk/mediatek/clk-mtk.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
index 82306ae285c..a275b359227 100644
--- a/drivers/clk/mediatek/clk-mtk.c
+++ b/drivers/clk/mediatek/clk-mtk.c
@@ -12,6 +12,7 @@
 #include <asm/io.h>
 #include <linux/bitops.h>
 #include <linux/delay.h>
+#include <linux/err.h>
 
 #include "clk-mtk.h"
 
@@ -218,10 +219,10 @@ static void mtk_clk_print_rate(struct udevice *dev, int mapped_id)
 		.dev = dev,
 		.id = mapped_id,
 	};
-	long rate = clk_get_rate(&clk);
+	ulong rate = clk_get_rate(&clk);
 
-	if (rate < 0)
-		printf(", error! clk_get_rate() failed: %ld", rate);
+	if (IS_ERR_VALUE(rate))
+		printf(", error! clk_get_rate() failed: %d", (int)rate);
 	else
 		printf(", Rate: %lu Hz", rate);
 }
@@ -632,7 +633,7 @@ static ulong mtk_topckgen_get_factor_rate(struct clk *clk, u32 off)
 		rate = priv->tree->xtal_rate;
 	}
 
-	if (((long)rate) < 0)
+	if (IS_ERR_VALUE(rate))
 		return rate;
 
 	return mtk_factor_recalc_rate(fdiv, rate);
@@ -951,7 +952,7 @@ static ulong mtk_infrasys_get_factor_rate(struct clk *clk, u32 off)
 		rate = mtk_clk_find_parent_rate(clk, fdiv->parent, NULL);
 	}
 
-	if (((long)rate) < 0)
+	if (IS_ERR_VALUE(rate))
 		return rate;
 
 	return mtk_factor_recalc_rate(fdiv, rate);

---
base-commit: d503633a36767d756c7de28305cf0de79440cbc0
change-id: 20260114-clk-mtk-use-is-err-value-ad81668ac5dd

Best regards,
-- 
David Lechner <dlechner at baylibre.com>



More information about the U-Boot mailing list