Skip to content

Commit 16c8eba

Browse files
arndbIngo Molnar
authored andcommitted
clocksource/drivers/kona: Fix get_counter() error handling
I could not figure out why, but GCC cannot prove that the kona_timer_init() function always initializes its two outputs, and we get a warning for the use of the 'lsw' variable later, which is obviously correct. drivers/clocksource/bcm_kona_timer.c: In function 'kona_timer_init': drivers/clocksource/bcm_kona_timer.c:119:13: error: 'lsw' may be used uninitialized in this function [-Werror=maybe-uninitialized] Slightly reordering the loop makes the warning disappear, after it becomes more obvious to the compiler that the loop is always entered on the first iteration. As pointed out by Ray Jui, there is a related problem in the way we deal with the loop running into the limit, as we just keep going there with an invalid counter data, so instead we now propagate a -ETIMEDOUT result to the caller. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Acked-by: Ray Jui <ray.jui@broadcom.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: bcm-kernel-feedback-list@broadcom.com Link: http://lkml.kernel.org/r/1471429296-9053-2-git-send-email-daniel.lezcano@linaro.org Link: https://patchwork.kernel.org/patch/9174261/ Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 0e62fd8 commit 16c8eba

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

drivers/clocksource/bcm_kona_timer.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ static void kona_timer_disable_and_clear(void __iomem *base)
6666

6767
}
6868

69-
static void
69+
static int
7070
kona_timer_get_counter(void __iomem *timer_base, uint32_t *msw, uint32_t *lsw)
7171
{
72-
int loop_limit = 4;
72+
int loop_limit = 3;
7373

7474
/*
7575
* Read 64-bit free running counter
@@ -83,18 +83,19 @@ kona_timer_get_counter(void __iomem *timer_base, uint32_t *msw, uint32_t *lsw)
8383
* if new hi-word is equal to previously read hi-word then stop.
8484
*/
8585

86-
while (--loop_limit) {
86+
do {
8787
*msw = readl(timer_base + KONA_GPTIMER_STCHI_OFFSET);
8888
*lsw = readl(timer_base + KONA_GPTIMER_STCLO_OFFSET);
8989
if (*msw == readl(timer_base + KONA_GPTIMER_STCHI_OFFSET))
9090
break;
91-
}
91+
} while (--loop_limit);
9292
if (!loop_limit) {
9393
pr_err("bcm_kona_timer: getting counter failed.\n");
9494
pr_err(" Timer will be impacted\n");
95+
return -ETIMEDOUT;
9596
}
9697

97-
return;
98+
return 0;
9899
}
99100

100101
static int kona_timer_set_next_event(unsigned long clc,
@@ -112,8 +113,11 @@ static int kona_timer_set_next_event(unsigned long clc,
112113

113114
uint32_t lsw, msw;
114115
uint32_t reg;
116+
int ret;
115117

116-
kona_timer_get_counter(timers.tmr_regs, &msw, &lsw);
118+
ret = kona_timer_get_counter(timers.tmr_regs, &msw, &lsw);
119+
if (ret)
120+
return ret;
117121

118122
/* Load the "next" event tick value */
119123
writel(lsw + clc, timers.tmr_regs + KONA_GPTIMER_STCM0_OFFSET);

0 commit comments

Comments
 (0)