Skip to contentSkip to conversation

clocksource: kona: avoid bogus warning

PATCH In review Arnd Bergmann 2 participants 2 messages Jun 13, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clocksource: kona: avoid bogus warning

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.

---
 drivers/clocksource/bcm_kona_timer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/clocksource/bcm_kona_timer.c +3 -3
index 70d9c1e482dd..bbbfb03b46dd 100644
@@ -69,7 +69,7 @@ static void kona_timer_disable_and_clear(void __iomem *base)
 static void
 kona_timer_get_counter(void __iomem *timer_base, uint32_t *msw, uint32_t *lsw)
 {
-	int loop_limit = 4;
+	int loop_limit = 3;
 
 	/*
 	 * Read 64-bit free running counter
@@ -83,12 +83,12 @@ kona_timer_get_counter(void __iomem *timer_base, uint32_t *msw, uint32_t *lsw)
 	 *      if new hi-word is equal to previously read hi-word then stop.
 	 */
 
-	while (--loop_limit) {
+	do {
 		*msw = readl(timer_base + KONA_GPTIMER_STCHI_OFFSET);
 		*lsw = readl(timer_base + KONA_GPTIMER_STCLO_OFFSET);
 		if (*msw == readl(timer_base + KONA_GPTIMER_STCHI_OFFSET))
 			break;
-	}
+	} while (--loop_limit);
 	if (!loop_limit) {
 		pr_err("bcm_kona_timer: getting counter failed.\n");
 		pr_err(" Timer will be impacted\n");
Signature · 1 line
2.7.0
#1 lore raw

Hi Arnd,

Quoted 36 lines · Arnd Bergmann

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.

---
 drivers/clocksource/bcm_kona_timer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/clocksource/bcm_kona_timer.c +1 -2
index 70d9c1e482dd..bbbfb03b46dd 100644
@@ -69,7 +69,7 @@ static void kona_timer_disable_and_clear(void __iomem *base)
 static void
 kona_timer_get_counter(void __iomem *timer_base, uint32_t *msw, uint32_t *lsw)
 {
-	int loop_limit = 4;
+	int loop_limit = 3;
 
 	/*
 	 * Read 64-bit free running counter
@@ -83,12 +83,12 @@ kona_timer_get_counter(void __iomem *timer_base, uint32_t *msw, uint32_t *lsw)
 	 *      if new hi-word is equal to previously read hi-word then stop.
 	 */
 
-	while (--loop_limit) {

drivers/clocksource/bcm_kona_timer.c kona_timer_get_counter(void __iomem *timer_base, uint32_t *msw, uint32_t *lsw) · line 94

Quoted 10 lines
drivers/clocksource/bcm_kona_timer.c +2 -1
+	do {
 		*msw = readl(timer_base + KONA_GPTIMER_STCHI_OFFSET);
 		*lsw = readl(timer_base + KONA_GPTIMER_STCLO_OFFSET);
 		if (*msw == readl(timer_base + KONA_GPTIMER_STCHI_OFFSET))
 			break;
-	}
+	} while (--loop_limit);
 	if (!loop_limit) {
 		pr_err("bcm_kona_timer: getting counter failed.\n");
 		pr_err(" Timer will be impacted\n");

This fix of compiler warning looks fine to me.

Btw, this also exposes another issue in the code:

Does it make more sense to have "kona_timer_get_counter" return -ETIMEDOUT in the case when "loop_limit" reaches zero, and in "kona_timer_set_net_event", it should bail out immediately when error is returned from "kona_timer_get_counter":

ret = kona_timer_get_counter(timers.tmr_regs, &msw, &lsw); if (ret)

    return ret;

Thanks,

Ray