Skip to contentSkip to conversation

rtc-ds1307.c: array overrun

DISCUSSION Adrian Bunk 3 participants 3 messages Jul 23, 2007 – Jul 25, 2007 Real time clock (RTC)

lore
Share & tools
lore
#0 lore raw

The Coverity checker spotted the following array overrun in drivers/rtc/rtc-ds1307.c:

<-- snip -->

...
#define DS1337_REG_CONTROL 0x0e
...

struct ds1307 {
        u8                      reg_addr;
        u8                      regs[8];

...
};
...
static int __devinit ds1307_probe(struct i2c_client *client) {
...

                                        ds1307->regs[DS1337_REG_CONTROL]

...

<-- snip -->

0x0e > 8

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#1 lore raw
Quoted 2 lines · Adrian Bunk

The Coverity checker spotted the following array overrun in drivers/rtc/rtc-ds1307.c:

Typo -- thanks, fix is attached.

======== CUT HERE
Fix a typo turned up by a Coverity check: referring to the wrong register, which could cause problems restarting DS1338 RTCs after their oscillator halted. (For example, if the backup battery died.)

---
 drivers/rtc/rtc-ds1307.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-ds1307.c +1 -1
@@ -352,7 +352,7 @@ read_rtc:
 		/* oscillator fault?  clear flag, and warn */
 		if (ds1307->regs[DS1307_REG_CONTROL] & DS1338_BIT_OSF) {
 			i2c_smbus_write_byte_data(client, DS1307_REG_CONTROL,
-					ds1307->regs[DS1337_REG_CONTROL]
+					ds1307->regs[DS1307_REG_CONTROL]
 					& ~DS1338_BIT_OSF);
 			dev_warn(&client->dev, "SET TIME!\n");
 			goto read_rtc;
#2 lore raw
Quoted 5 lines · On Sun, 22 Jul 2007 18:17:17 -0700 David Brownell <[email protected]> wrote:
Quoted 2 lines · Adrian Bunk

The Coverity checker spotted the following array overrun in drivers/rtc/rtc-ds1307.c:

Quoted 8 lines

Typo -- thanks, fix is attached.

======== CUT HERE
Fix a typo turned up by a Coverity check: referring to the wrong register, which could cause problems restarting DS1338 RTCs after their oscillator halted. (For example, if the backup battery died.)

Signature · 6 lines
 Best regards,

 Alessandro Zummo,
  Tower Technologies - Torino, Italy

  http://www.towertech.it