Skip to contentSkip to conversation

fsl: sys_eeprom: Fix 'may be used uninitialized' warning

PATCH Superseded Anton Vorontsov 5 participants 13 messages Sep 1, 2009 – Sep 4, 2009

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 fsl: sys_eeprom: Fix 'may be used uninitialized' warning

The warning is bogus, so silence it with uninitialized_var().

---
 board/freescale/common/sys_eeprom.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
board/freescale/common/sys_eeprom.c +3 -1
index c0fff68..a765b39 100644
@@ -24,6 +24,7 @@
  */
 
 #include <common.h>
+#include <compiler.h>
 #include <command.h>
 #include <i2c.h>
 #include <linux/ctype.h>
@@ -204,7 +205,8 @@ static void update_crc(void)
  */
 static int prog_eeprom(void)
 {
-	int ret, i;
+	int uninitialized_var(ret);
+	int i;
 	void *p;
 #ifdef CONFIG_SYS_EEPROM_BUS_NUM
 	unsigned int bus;
Signature · 1 line
1.6.3.3
#1 lore raw

PATCH 2/2 fsl: sys_eeprom: Fix 'may be used uninitialized' warning

Quoted 21 lines · Anton Vorontsov

The warning is bogus, so silence it with uninitialized_var().

---
board/freescale/common/sys_eeprom.c | 4 +++-

1 files changed, 3 insertions(+), 1 deletions(-)
board/freescale/ renamed from board/freescale/common/sys_eeprom.c +0 -0

common/sys_eeprom.c
index c0fff68..a765b39 100644

board/freescale/common/sys_eeprom.c +1 -0
@@ -24,6 +24,7 @@
 */
 
 #include <common.h>
+#include <compiler.h>
 #include <command.h>
 #include <i2c.h>
 #include <linux/ctype.h>

board/freescale/common/sys_eeprom.c static void update_crc(void) · line 209

Quoted 6 lines
board/freescale/common/sys_eeprom.c +2 -1
@@ -204,7 +205,8 @@ static void update_crc(void)
 */
 static int prog_eeprom(void)
 {
-	int ret, i;
+	int uninitialized_var(ret);
+	int i;

why don't we init ret = 0; seems like we should be doing that since we might not enter the for loop

- k

#2 lore raw

PATCH 2/2 fsl: sys_eeprom: Fix 'may be used uninitialized' warning

Quoted 18 lines · Kumar Gala
Quoted 15 lines · Anton Vorontsov

The warning is bogus, so silence it with uninitialized_var().

---
board/freescale/common/sys_eeprom.c | 4 +++-

1 files changed, 3 insertions(+), 1 deletions(-)
board/freescale/common/sys_eeprom.c +0 -0
index c0fff68..a765b39 100644
@@ -24,6 +24,7 @@
 */
 
Quoted 15 lines

board/freescale/common/sys_eeprom.c static void update_crc(void) · line 209

Quoted 12 lines
board/freescale/common/sys_eeprom.c +3 -1
 #include <common.h>
+#include <compiler.h>
 #include <command.h>
 #include <i2c.h>
 #include <linux/ctype.h>
@@ -204,7 +205,8 @@ static void update_crc(void)
 */
 static int prog_eeprom(void)
 {
-	int ret, i;
+	int uninitialized_var(ret);
+	int i;

why don't we init ret = 0; seems like we should be doing that since we might not enter the for loop

No, we always enter the for loop:

for (i = 0, p = &e; i < sizeof(e); i += 8, p += 8) {

sizeof(e) always > 0 because:

#if !defined(CONFIG_SYS_I2C_EEPROM_CCID) && !defined(CONFIG_SYS_I2C_EEPROM_NXID) #error "Please define either CONFIG_SYS_I2C_EEPROM_CCID or CONFIG_SYS_I2C_EEPROM_NXID" #endif

static struct __attribute__ ((__packed__)) eeprom {

#ifdef CONFIG_SYS_I2C_EEPROM_CCID
        u8 id[4];         /* 0x00 - 0x03 EEPROM Tag 'CCID' */
...
#endif
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
        u8 id[4];         /* 0x00 - 0x03 EEPROM Tag 'NXID' */

...
#endif
} e;

Signature · 3 lines
Anton Vorontsov
email: cbouatmailru at gmail.com
irc://irc.freenode.net/bd2
#3 lore raw

[U-Boot] invalid core multipliers?

Hello,

I am bootstrapping an mpc5121e board.

When the cpu speed is calculated (cpu/mpc512x/speed.c) there is a comment about all core pll settings above 7 are invalid....

I can't see anything about that in the CPU documentation so I am wondering if anyone has reference to where this is defined as invalid.

The board I am using is using CORE PLL index 0x8, i.e. multiplier of 4.

If this comment in the code is wrong then the following patch should be o.k...

mpc512x/speed.c +1 -1
Index: cpu/mpc512x/speed.c
===================================================================
@@ -44,7 +44,7 @@
  	{1, 1}, {3, 2},
  	{2, 1}, {5, 2},
  	{3, 1}, {7, 2},
-	{0, 1}, {0, 1}, /* and all above 7 are not valid too */
+	{4, 1}, {0, 1}, /* and all above 7 are not valid too.... I doubt this claim */
  	{0, 1}, {0, 1},
  	{0, 1}, {0, 1},
  	{0, 1}, {0, 1}

rg
kd

#5 lore raw

PATCH 2/2 fsl: sys_eeprom: Fix 'may be used uninitialized' warning

In reply to Anton Vorontsov

On Tue, Sep 01, 2009 at 09:38:14PM +0400, Anton Vorontsov wrote:
[...]

Quoted 26 lines
Quoted 8 lines

Review

Quoted 5 lines

static int prog_eeprom(void)
{

(quoted diff) +2 -1
-	int ret, i;
+	int uninitialized_var(ret);
+	int i;

why don't we init ret = 0; seems like we should be doing that since we might not enter the for loop

No, we always enter the for loop:

for (i = 0, p = &e; i < sizeof(e); i += 8, p += 8) {

sizeof(e) always > 0 because:

#if !defined(CONFIG_SYS_I2C_EEPROM_CCID) && !defined(CONFIG_SYS_I2C_EEPROM_NXID) #error "Please define either CONFIG_SYS_I2C_EEPROM_CCID or CONFIG_SYS_I2C_EEPROM_NXID" #endif

static struct __attribute__ ((__packed__)) eeprom {

#ifdef CONFIG_SYS_I2C_EEPROM_CCID
        u8 id[4];         /* 0x00 - 0x03 EEPROM Tag 'CCID' */
...
#endif
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
        u8 id[4];         /* 0x00 - 0x03 EEPROM Tag 'NXID' */
Quoted 3 lines

...
#endif
} e;

Another option is to turn the for loop into do {} while, so we can avoid unitialized_var() usage. Something like that:

board/freescale/common/sys_eeprom.c +6 -5
index c0fff68..a4e0980 100644
@@ -204,8 +204,8 @@ static void update_crc(void)
  */
 static int prog_eeprom(void)
 {
-	int ret, i;
-	void *p;
+	int ret;
+	int i = 0;
 #ifdef CONFIG_SYS_EEPROM_BUS_NUM
 	unsigned int bus;
 #endif
@@ -224,13 +224,14 @@ static int prog_eeprom(void)
 	i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
 #endif
 
-	for (i = 0, p = &e; i < sizeof(e); i += 8, p += 8) {
+	do {
 		ret = i2c_write(CONFIG_SYS_I2C_EEPROM_ADDR, i, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
-			p, min((sizeof(e) - i), 8));
+			(void *)&e + i, min((sizeof(e) - i), 8));
 		if (ret)
 			break;
 		udelay(5000);	/* 5ms write cycle timing */
-	}
+		i += 8;
+	} while (i < sizeof(e));
 
 #ifdef CONFIG_SYS_EEPROM_BUS_NUM
 	i2c_set_bus_num(bus);
#6 lore raw

PATCH 2/2 fsl: sys_eeprom: Fix 'may be used uninitialized' warning

board/freescale/common/sys_eeprom.c static int prog_eeprom(void) · line 234

Quoted 11 lines · Anton Vorontsov
board/freescale/common/sys_eeprom.c +4 -3
-	for (i = 0, p = &e; i < sizeof(e); i += 8, p += 8) {
+	do {
 		ret = i2c_write(CONFIG_SYS_I2C_EEPROM_ADDR, i, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
-			p, min((sizeof(e) - i), 8));
+			(void *)&e + i, min((sizeof(e) - i), 8));
 		if (ret)
 			break;
 		udelay(5000);	/* 5ms write cycle timing */
-	}
+		i += 8;
+	} while (i < sizeof(e));

Or we could remove the loop altogether and just do the write in one shot. Is there any reason to believe that any of Freescale's 8[356]xx boards can't handle a large I2C block write of about 50 bytes or so?

Signature · 2 lines
Timur Tabi
Linux kernel developer@Freescale
#9 lore raw

PATCH 2/2 fsl: sys_eeprom: Fix 'may be used uninitialized' warning

In reply to Anton Vorontsov

Dear Anton Vorontsov,

Quoted 1 line · In message <[email protected]> you wrote:

The warning is bogus, so silence it with uninitialized_var().

Which tool chain issues a warning here?

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Change is the essential process of all existence.
	-- Spock, "Let That Be Your Last Battlefield",
	   stardate 5730.2
#7 lore raw

PATCH 2/2 fsl: sys_eeprom: Fix 'may be used uninitialized' warningп

In reply to Timur Tabi
Quoted 15 lines · Timur Tabi

board/freescale/common/sys_eeprom.c static int prog_eeprom(void) · line 234

Quoted 11 lines · Anton Vorontsov
board/freescale/common/sys_eeprom.c +4 -3
-	for (i = 0, p = &e; i < sizeof(e); i += 8, p += 8) {
+	do {
 		ret = i2c_write(CONFIG_SYS_I2C_EEPROM_ADDR, i, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
-			p, min((sizeof(e) - i), 8));
+			(void *)&e + i, min((sizeof(e) - i), 8));
 		if (ret)
 			break;
 		udelay(5000);	/* 5ms write cycle timing */
-	}
+		i += 8;
+	} while (i < sizeof(e));

Or we could remove the loop altogether and just do the write in one shot. Is there any reason to believe that any of Freescale's 8[356]xx boards can't handle a large I2C block write of about 50 bytes or so?

I guess "udelay(5000); /* 5ms write cycle timing */" hints that
it's EEPROM chip dependant, so has nothing to do with i2c controller capabilities.

Thanks,

Signature · 3 lines
Anton Vorontsov
email: cbouatmailru at gmail.com
irc://irc.freenode.net/bd2
#10 lore raw

PATCH 2/2 fsl: sys_eeprom: Fix 'may be used uninitialized' warning

In reply to Wolfgang Denk
Quoted 6 lines · Wolfgang Denk

Dear Anton Vorontsov,

Quoted 1 line · In message <[email protected]> you wrote:

The warning is bogus, so silence it with uninitialized_var().

Which tool chain issues a warning here?

gcc version 4.0.0 (DENX ELDK 4.0 4.0.0) ;-)

Thanks,

Signature · 3 lines
Anton Vorontsov
email: cbouatmailru at gmail.com
irc://irc.freenode.net/bd2
#8 lore raw

PATCH 2/2 fsl: sys_eeprom: Fix 'may be used uninitialized' warning

In reply to Anton Vorontsov

Dear Anton Vorontsov,

Quoted 3 lines · In message <[email protected]> you wrote:

Another option is to turn the for loop into do {} while, so we can avoid unitialized_var() usage. Something like that:

This is much more difficult to read.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Witch!  Witch!  They'll burn ya!
	-- Hag, "Tomorrow is Yesterday", stardate unknown
#11 lore raw

PATCH 2/2 fsl: sys_eeprom: Fix 'may be used uninitialized' warning

In reply to Anton Vorontsov

Dear Anton Vorontsov,

Quoted 9 lines · In message <[email protected]> you wrote:
Quoted 6 lines · Wolfgang Denk

Dear Anton Vorontsov,

Quoted 1 line · In message <[email protected]> you wrote:

The warning is bogus, so silence it with uninitialized_var().

Which tool chain issues a warning here?

gcc version 4.0.0 (DENX ELDK 4.0 4.0.0) ;-)

Heh, indeed.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
A Chairman was as necessary to a Board planet  as  the  zero  was  in
mathematics, but being a zero had big disadvantages...
                         - Terry Pratchett, _The Dark Side of the Sun_
#4 lore raw

[U-Boot] invalid core multipliers?

In reply to Kári Davíðsson

Dear =?ISO-8859-1?Q?K=E1ri_Dav=ED=F0sson?=,

Quoted 10 lines · In message <[email protected]> you wrote:

I am bootstrapping an mpc5121e board.

When the cpu speed is calculated (cpu/mpc512x/speed.c) there is a comment about all core pll settings above 7 are invalid....

I can't see anything about that in the CPU documentation so I am wondering if anyone has reference to where this is defined as invalid.

The board I am using is using CORE PLL index 0x8, i.e. multiplier of 4.

I tried and checked some old versions of the UM and the old errata sheets, but I didn't keep all the very early ones, and in the ones left I didn't find it. Guess this might have been a restriction ofthe very first silicon.

John, do you happen to remember any details?

Quoted 1 line

If this comment in the code is wrong then the following patch should be o.k...

Guess so, ut then why not fill up the table?

And please add your SoB line, too.

mpc512x/speed.c line 50

Quoted 13 lines

Index: cpu/mpc512x/speed.c
===================================================================

mpc512x/speed.c +1 -1
@@ -44,7 +44,7 @@
  	{1, 1}, {3, 2},
  	{2, 1}, {5, 2},
  	{3, 1}, {7, 2},
-	{0, 1}, {0, 1}, /* and all above 7 are not valid too */
+	{4, 1}, {0, 1}, /* and all above 7 are not valid too.... I doubt this claim */
  	{0, 1}, {0, 1},
  	{0, 1}, {0, 1},
  	{0, 1}, {0, 1}

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"It was the Law of the Sea, they said. Civilization ends at  the  wa-
terline.  Beyond  that,  we  all enter the food chain, and not always
right at the top."                               - Hunter S. Thompson