Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1464458
| From | Andrzej Hajda <a.hajda@samsung.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH] clocksource: fix __ftm_clk_init result |
| Date | 2016-08-17 12:00 +0200 |
| Message-ID | <s75NI-7IP-3@gated-at.bofh.it> (permalink) |
| Organization | linux.* mail to news gateway |
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@samsung.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
Back to linux.kernel | Previous | Next | Find similar | Unroll thread
[PATCH] clocksource: fix __ftm_clk_init result Andrzej Hajda <a.hajda@samsung.com> - 2016-08-17 12:00 +0200
csiph-web