u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: u-boot@lists.denx.de, Leo Liang <ycliang@andestech.com>
Cc: Bin Meng <bmeng.cn@gmail.com>,
	Damien Le Moal <Damien.LeMoal@wdc.com>,
	Lukasz Majewski <lukma@denx.de>,
	Sean Anderson <seanga2@gmail.com>,
	Coverity Scan <scan-admin@coverity.com>
Subject: [PATCH v2 1/4] clk: k210: Fix checking if ulongs are less than 0
Date: Sat, 11 Sep 2021 13:20:00 -0400	[thread overview]
Message-ID: <20210911172003.899301-1-seanga2@gmail.com> (raw)

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>
---

Changes in v2:
- Reworked patch to use IS_ERR_VALUE instead of changing arguments to long

 drivers/clk/clk_kendryte.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/clk_kendryte.c b/drivers/clk/clk_kendryte.c
index 3148756968..2caa21aec9 100644
--- a/drivers/clk/clk_kendryte.c
+++ b/drivers/clk/clk_kendryte.c
@@ -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);
 
-- 
2.33.0


             reply	other threads:[~2021-09-11 17:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-11 17:20 Sean Anderson [this message]
2021-09-11 17:20 ` [PATCH v2 2/4] k210: clk: Refactor out_of_spec tests Sean Anderson
2021-09-14  8:45   ` Leo Liang
2021-09-11 17:20 ` [PATCH v2 3/4] test: dm: k210: Reduce duplication in test cases Sean Anderson
2021-09-14  8:48   ` Leo Liang
2021-09-11 17:20 ` [PATCH v2 4/4] clk: k210: Try harder to get the best config Sean Anderson
2021-09-30  4:08   ` Simon Glass
2021-09-14  8:39 ` [PATCH v2 1/4] clk: k210: Fix checking if ulongs are less than 0 Leo Liang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210911172003.899301-1-seanga2@gmail.com \
    --to=seanga2@gmail.com \
    --cc=Damien.LeMoal@wdc.com \
    --cc=bmeng.cn@gmail.com \
    --cc=lukma@denx.de \
    --cc=scan-admin@coverity.com \
    --cc=u-boot@lists.denx.de \
    --cc=ycliang@andestech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).