]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
clk: k210: Fix checking if ulongs are less than 0
authorSean Anderson <seanga2@gmail.com>
Sat, 11 Sep 2021 17:20:00 +0000 (13:20 -0400)
committerLeo Yu-Chi Liang <ycliang@andestech.com>
Thu, 7 Oct 2021 08:08:22 +0000 (16:08 +0800)
The PLL functions take ulong arguments for rate, but still check if that
rate is negative (which is never true). The correct way to handle this is
to use IS_ERR_VALUE (like is already done in k210_clk_set_rate). While
we're at it, we can move the error checking up into the caller of the pll
set/get rate functions.  This also protects our other calculations from
using bogus values for rate.

Fixes: 609bd60b94 ("clk: k210: Rewrite to remove CCF")
Reported-by: Coverity Scan <scan-admin@coverity.com>
Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
drivers/clk/clk_kendryte.c

index 31487569686d80405192255473c6184a4bf9b24f..2caa21aec9e9ed22b8f25e9c4f8fda48da806688 100644 (file)
@@ -849,9 +849,6 @@ static ulong k210_pll_set_rate(struct k210_clk_priv *priv, int id, ulong rate,
        u32 reg;
        ulong calc_rate;
 
-       if (rate_in < 0)
-               return rate_in;
-
        err = k210_pll_calc_config(rate, rate_in, &config);
        if (err)
                return err;
@@ -895,7 +892,7 @@ static ulong k210_pll_get_rate(struct k210_clk_priv *priv, int id,
        u64 r, f, od;
        u32 reg = readl(priv->base + k210_plls[id].off);
 
-       if (rate_in < 0 || (reg & K210_PLL_BYPASS))
+       if (reg & K210_PLL_BYPASS)
                return rate_in;
 
        if (!(reg & K210_PLL_PWRD))
@@ -1029,6 +1026,8 @@ static ulong do_k210_clk_get_rate(struct k210_clk_priv *priv, int id)
 
        parent = k210_clk_get_parent(priv, id);
        parent_rate = do_k210_clk_get_rate(priv, parent);
+       if (IS_ERR_VALUE(parent_rate))
+               return parent_rate;
 
        if (k210_clks[id].flags & K210_CLKF_PLL)
                return k210_pll_get_rate(priv, k210_clks[id].pll, parent_rate);
@@ -1099,6 +1098,8 @@ static ulong k210_clk_set_rate(struct clk *clk, unsigned long rate)
 
        parent = k210_clk_get_parent(priv, clk->id);
        rate_in = do_k210_clk_get_rate(priv, parent);
+       if (IS_ERR_VALUE(rate_in))
+               return rate_in;
 
        log_debug("id=%ld rate=%lu rate_in=%lu\n", clk->id, rate, rate_in);