Skip to contentSkip to conversation

rtc: pcf8563: fix uninitialized use warning

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

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

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) {
#1 lore raw

Hello.

Quoted 23 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.

drivers/rtc/rtc-pcf8563.c +0 -0
index 5a197d9dc7e7..3a6f994c4da8 100644

drivers/rtc/rtc-pcf8563.c static irqreturn_t pcf8563_irq(int irq, void *dev_id) · line 171

Quoted 6 lines
drivers/rtc/rtc-pcf8563.c +1 -1
@@ -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;

Returning negative values from the IRQ handler doesn't seem valid.
Arbitrary positive value aren't good either. Perhaps should return IRQ_NONE instead?

WBR, Sergei

#2 lore raw
Quoted 7 lines · On Monday 08 September 2014 15:02:00 Sergei Shtylyov wrote:
Quoted 7 lines
drivers/rtc/rtc-pcf8563.c +0 -0
index 5a197d9dc7e7..3a6f994c4da8 100644
@@ -167,7 +167,7 @@ static irqreturn_t pcf8563_irq(int irq, void *dev_id)
      char pending;
 
Quoted 8 lines

drivers/rtc/rtc-pcf8563.c static irqreturn_t pcf8563_irq(int irq, void *dev_id) · line 171

Quoted 4 lines
drivers/rtc/rtc-pcf8563.c +1 -1
      err = pcf8563_get_alarm_mode(pcf8563->client, NULL, &pending);
-     if (err < 0)
+     if (err)
              return err;

Returning negative values from the IRQ handler doesn't seem valid.
Arbitrary positive value aren't good either. Perhaps should return IRQ_NONE instead?

Good point. This is unrelated to the problem I was trying to fix, but it seems like a good idea to fix both.

Arnd

#3 lore raw
Quoted 16 lines · Arnd Bergmann
Quoted 7 lines
Quoted 7 lines
drivers/rtc/rtc-pcf8563.c +0 -0
index 5a197d9dc7e7..3a6f994c4da8 100644
@@ -167,7 +167,7 @@ static irqreturn_t pcf8563_irq(int irq, void *dev_id)
       char pending;
 
Quoted 8 lines

drivers/rtc/rtc-pcf8563.c static irqreturn_t pcf8563_irq(int irq, void *dev_id) · line 171

Quoted 4 lines
drivers/rtc/rtc-pcf8563.c +1 -1
       err = pcf8563_get_alarm_mode(pcf8563->client, NULL, &pending);
-     if (err < 0)
+     if (err)
               return err;

Returning negative values from the IRQ handler doesn't seem valid.
Arbitrary positive value aren't good either. Perhaps should return IRQ_NONE instead?

Quoted 2 lines

Good point. This is unrelated to the problem I was trying to fix, but it seems like a good idea to fix both.

Then it would be good if you fix this issue with a separate patch.

Quoted 1 line

Arnd

WBR, Sergei