Skip to contentSkip to conversation

rtc: pcf8563: fix uninitialized use warning

PATCH Superseded Arnd Bergmann 2 participants 4 messages Sep 8, 2014 – Sep 9, 2014 Real time clock (RTC)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rtc: pcf8563: fix uninitialized use warning

gcc-4.9 found a potential condition under which the 'pending' variable may be used uninitialized:

drivers/rtc/rtc-pcf8563.c: In function 'pcf8563_irq':
drivers/rtc/rtc-pcf8563.c:173:5: warning: 'pending' may be used uninitialized in this function [-Wmaybe-uninitialized]

This is because in the pcf8563_get_alarm_mode() function, we check any nonzero return of pcf8563_read_block_data, but in the irq function we only check for negative values, so a possible positive value does not get detected if the compiler chooses not to inline the entire call chain.

Checking for any non-zero value in the interrupt handler as well is just as correct and lets the compiler know what we are doing, without needing a bogus initialization.

As pointed out by Sergei Shtylyov, the same code section contains another bug: an interrupt handler is not supposed to return an errno value. Let's fix this as well by returning IRQ_NONE in case of a communication error.

drivers/rtc/rtc-pcf8563.c +2 -2
index 5a197d9dc7e7..c2ef0a22ee94 100644
@@ -167,8 +167,8 @@ static irqreturn_t pcf8563_irq(int irq, void *dev_id)
 	char pending;
 
 	err = pcf8563_get_alarm_mode(pcf8563->client, NULL, &pending);
-	if (err < 0)
-		return err;
+	if (err)
+		return IRQ_NONE;
 
 	if (pending) {
 		rtc_update_irq(pcf8563->rtc, 1, RTC_IRQF | RTC_AF);
#1 lore raw
Quoted 16 lines · Arnd Bergmann

gcc-4.9 found a potential condition under which the 'pending' variable may be used uninitialized:

drivers/rtc/rtc-pcf8563.c: In function 'pcf8563_irq':
drivers/rtc/rtc-pcf8563.c:173:5: warning: 'pending' may be used uninitialized in this function [-Wmaybe-uninitialized]

This is because in the pcf8563_get_alarm_mode() function, we check any nonzero return of pcf8563_read_block_data, but in the irq function we only check for negative values, so a possible positive value does not get detected if the compiler chooses not to inline the entire call chain.

Checking for any non-zero value in the interrupt handler as well is just as correct and lets the compiler know what we are doing, without needing a bogus initialization.

Quoted 6 lines

As pointed out by Sergei Shtylyov, the same code section contains another bug: an interrupt handler is not supposed to return an errno value. Let's fix this as well by returning IRQ_NONE in case of a communication error.

If you're fixing both issues in one patch, it probably needs somewhat
modified subject, like "rtc: pcf8356: fix error handling".

WBR, Sergei

#2 lore raw

PATCH v3 1/2 rtc: pcf8563: fix uninitialized use warning

gcc-4.9 found a potential condition under which the 'pending' variable may be used uninitialized:

drivers/rtc/rtc-pcf8563.c: In function 'pcf8563_irq':
drivers/rtc/rtc-pcf8563.c:173:5: warning: 'pending' may be used uninitialized in this function [-Wmaybe-uninitialized]

This is because in the pcf8563_get_alarm_mode() function, we check any nonzero return of pcf8563_read_block_data, but in the irq function we only check for negative values, so a possible positive value does not get detected if the compiler chooses not to inline the entire call chain.

Checking for any non-zero value in the interrupt handler as well is just as correct and lets the compiler know what we are doing, without needing a bogus initialization.

drivers/rtc/rtc-pcf8563.c +1 -1
index 5a197d9dc7e7..3a6f994c4da8 100644
@@ -167,7 +167,7 @@ static irqreturn_t pcf8563_irq(int irq, void *dev_id)
 	char pending;
 
 	err = pcf8563_get_alarm_mode(pcf8563->client, NULL, &pending);
-	if (err < 0)
+	if (err)
 		return err;
 
 	if (pending) {
#3 lore raw

PATCH v3 2/2 rtc: pcf8563: fix pcf8563_irq error return value

In reply to Sergei Shtylyov

As pointed out by Sergei Shtylyov, the pcf8563_irq function contains a bug in the error handling: an interrupt handler is not supposed to return an errno value but an 'enum irqreturn'.

Let's fix this by returning IRQ_NONE in case of a communication error.

drivers/rtc/rtc-pcf8563.c +1 -1
index 3a6f994c4da8..c2ef0a22ee94 100644
@@ -168,7 +168,7 @@ static irqreturn_t pcf8563_irq(int irq, void *dev_id)
 
 	err = pcf8563_get_alarm_mode(pcf8563->client, NULL, &pending);
 	if (err)
-		return err;
+		return IRQ_NONE;
 
 	if (pending) {
 		rtc_update_irq(pcf8563->rtc, 1, RTC_IRQF | RTC_AF);