[<prev] [next>] [day] [month] [year] [list]
Message-id: <1471427856-23290-1-git-send-email-a.hajda@samsung.com>
Date: Wed, 17 Aug 2016 11:57:36 +0200
From: Andrzej Hajda <a.hajda@...sung.com>
To: Daniel Lezcano <daniel.lezcano@...aro.org>,
Thomas Gleixner <tglx@...utronix.de>,
linux-kernel@...r.kernel.org (open list:CLOCKSOURCE, CLOCKEVENT DRIVERS)
Cc: Andrzej Hajda <a.hajda@...sung.com>,
Bartlomiej Zolnierkiewicz <b.zolnierkie@...sung.com>,
Marek Szyprowski <m.szyprowski@...sung.com>
Subject: [PATCH] clocksource: fix __ftm_clk_init result
The function tries to return clock frequency (unsigned long) or error
(int < 0). Using int as a result could be dangerous. On the other side
caller is not interested in error value, so the best solution is to
return frequency or zero in case of error, for this unsigned long is OK.
The problem has been detected using semantic patch
scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci
Signed-off-by: Andrzej Hajda <a.hajda@...sung.com>
---
Hi Daniel,
This is old, forgotten patch. I have fixed caller as you have requested.
Regards
Andrzej
drivers/clocksource/fsl_ftm_timer.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/drivers/clocksource/fsl_ftm_timer.c b/drivers/clocksource/fsl_ftm_timer.c
index 738515b..4c33d0b 100644
--- a/drivers/clocksource/fsl_ftm_timer.c
+++ b/drivers/clocksource/fsl_ftm_timer.c
@@ -248,7 +248,7 @@ static int __init ftm_clocksource_init(unsigned long freq)
return 0;
}
-static int __init __ftm_clk_init(struct device_node *np, char *cnt_name,
+static unsigned long __init __ftm_clk_init(struct device_node *np, char *cnt_name,
char *ftm_name)
{
struct clk *clk;
@@ -257,19 +257,19 @@ static int __init __ftm_clk_init(struct device_node *np, char *cnt_name,
clk = of_clk_get_by_name(np, cnt_name);
if (IS_ERR(clk)) {
pr_err("ftm: Cannot get \"%s\": %ld\n", cnt_name, PTR_ERR(clk));
- return PTR_ERR(clk);
+ return 0;
}
err = clk_prepare_enable(clk);
if (err) {
pr_err("ftm: clock failed to prepare+enable \"%s\": %d\n",
cnt_name, err);
- return err;
+ return 0;
}
clk = of_clk_get_by_name(np, ftm_name);
if (IS_ERR(clk)) {
pr_err("ftm: Cannot get \"%s\": %ld\n", ftm_name, PTR_ERR(clk));
- return PTR_ERR(clk);
+ return 0;
}
err = clk_prepare_enable(clk);
if (err)
@@ -281,17 +281,10 @@ static int __init __ftm_clk_init(struct device_node *np, char *cnt_name,
static unsigned long __init ftm_clk_init(struct device_node *np)
{
- unsigned long freq;
-
- freq = __ftm_clk_init(np, "ftm-evt-counter-en", "ftm-evt");
- if (freq <= 0)
- return 0;
-
- freq = __ftm_clk_init(np, "ftm-src-counter-en", "ftm-src");
- if (freq <= 0)
+ if (!__ftm_clk_init(np, "ftm-evt-counter-en", "ftm-evt"))
return 0;
- return freq;
+ return __ftm_clk_init(np, "ftm-src-counter-en", "ftm-src");
}
static int __init ftm_calc_closest_round_cyc(unsigned long freq)
--
1.9.1
Powered by blists - more mailing lists