[U-Boot] [PATCH] clk: mediatek: use unsigned type for returning the clk rate

Fabien Parent fparent at baylibre.com
Thu Oct 17 19:02:05 UTC 2019

mtk_clk_find_parent_rate is calling clk_get_rate to know the rate
of a parent clock. clk_get_rate returns a ulong, while
mtk_clk_find_parent_rate returns an int. This implicit cast creates
an issue for clock rates big enough to need the full 32 bits to
store its data. When that happen the clk rate will become incorrect
because of the implicit cast between ulong -> int -> ulong.

This commit change the return type of mtk_clk_find_parent_rate to

Signed-off-by: Fabien Parent <fparent at baylibre.com>
 drivers/clk/mediatek/clk-mtk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
index 6c6b500d9b71..c74766dd22c7 100644
--- a/drivers/clk/mediatek/clk-mtk.c
+++ b/drivers/clk/mediatek/clk-mtk.c
@@ -39,8 +39,8 @@
  * this function is recursively called to find the parent to calculate
  * the accurate frequency.
-static int mtk_clk_find_parent_rate(struct clk *clk, int id,
-				    const struct driver *drv)
+static ulong mtk_clk_find_parent_rate(struct clk *clk, int id,
+				      const struct driver *drv)
 	struct clk parent = { .id = id, };

More information about the U-Boot mailing list