diff mbox

[U-Boot,v2] ext2fs: fix warning: 'blocknxt' may be used uninitialized

Message ID 20120703174156.a1082309c2b205216606a004@freescale.com
State Accepted
Commit b8032734ee94f4031c71aa40f100e9ef181ea0ef
Headers show

Commit Message

Kim Phillips July 3, 2012, 10:41 p.m. UTC
This warning was introduced in 436da3c "ext2load: increase read
speed":

ext2fs.c: In function 'ext2fs_read_file':
ext2fs.c:458:19: warning: 'blocknxt' may be used uninitialized in this function [-Wuninitialized]

this change makes it go away.

Cc: Eric Nelson <eric.nelson@boundarydevices.com>
Cc: Thierry Reding <thierry.reding@avionic-design.de>
Cc: Jason Cooper <u-boot@lakedaemon.net>
Cc: Andreas Bießmann <andreas.devel@googlemail.com>
Cc: Reinhard Arlt <reinhard.arlt@esd-electronics.com>
Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
---
v2: changed to Thierry's recommendation in:

http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/134043

build-tested only - please ack

 fs/ext2/ext2fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Thierry Reding July 4, 2012, 6:09 a.m. UTC | #1
On Tue, Jul 03, 2012 at 05:41:56PM -0500, Kim Phillips wrote:
> This warning was introduced in 436da3c "ext2load: increase read
> speed":
> 
> ext2fs.c: In function 'ext2fs_read_file':
> ext2fs.c:458:19: warning: 'blocknxt' may be used uninitialized in this function [-Wuninitialized]
> 
> this change makes it go away.
> 
> Cc: Eric Nelson <eric.nelson@boundarydevices.com>
> Cc: Thierry Reding <thierry.reding@avionic-design.de>
> Cc: Jason Cooper <u-boot@lakedaemon.net>
> Cc: Andreas Bießmann <andreas.devel@googlemail.com>
> Cc: Reinhard Arlt <reinhard.arlt@esd-electronics.com>
> Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
> ---
> v2: changed to Thierry's recommendation in:
> 
> http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/134043
> 
> build-tested only - please ack

Tested on TEC, seems to behave the same as before:

Tested-by: Thierry Reding <thierry.reding@avionic-design.de>

Thierry
u-boot@lakedaemon.net July 6, 2012, 1:31 p.m. UTC | #2
On Tue, Jul 03, 2012 at 05:41:56PM -0500, Kim Phillips wrote:
> This warning was introduced in 436da3c "ext2load: increase read
> speed":
> 
> ext2fs.c: In function 'ext2fs_read_file':
> ext2fs.c:458:19: warning: 'blocknxt' may be used uninitialized in this function [-Wuninitialized]
> 
> this change makes it go away.
> 
> Cc: Eric Nelson <eric.nelson@boundarydevices.com>
> Cc: Thierry Reding <thierry.reding@avionic-design.de>
> Cc: Jason Cooper <u-boot@lakedaemon.net>
> Cc: Andreas Bießmann <andreas.devel@googlemail.com>
> Cc: Reinhard Arlt <reinhard.arlt@esd-electronics.com>
> Signed-off-by: Kim Phillips <kim.phillips@freescale.com>

Acked-By: Jason Cooper <u-boot@lakedaemon.net>

thx,

Jason.

> ---
> v2: changed to Thierry's recommendation in:
> 
> http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/134043
> 
> build-tested only - please ack
> 
>  fs/ext2/ext2fs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ext2/ext2fs.c b/fs/ext2/ext2fs.c
> index f1fce48..182f0ac 100644
> --- a/fs/ext2/ext2fs.c
> +++ b/fs/ext2/ext2fs.c
> @@ -438,7 +438,7 @@ int ext2fs_read_file
>  		}
>  
>  		/* grab middle blocks in one go */
> -		if (i != pos / blocksize && i != blockcnt - 1 && blockcnt > 3) {
> +		if (i != pos / blocksize && i < blockcnt - 1 && blockcnt > 3) {
>  			int oldblk = blknr;
>  			int blocknxt;
>  			while (i < blockcnt - 1) {
> -- 
> 1.7.11.1
> 
>
Wolfgang Denk July 8, 2012, 8:55 p.m. UTC | #3
Dear Kim Phillips,

In message <20120703174156.a1082309c2b205216606a004@freescale.com> you wrote:
> This warning was introduced in 436da3c "ext2load: increase read
> speed":
> 
> ext2fs.c: In function 'ext2fs_read_file':
> ext2fs.c:458:19: warning: 'blocknxt' may be used uninitialized in this func=
> tion [-Wuninitialized]
> 
> this change makes it go away.
> 
> Cc: Eric Nelson <eric.nelson@boundarydevices.com>
> Cc: Thierry Reding <thierry.reding@avionic-design.de>
> Cc: Jason Cooper <u-boot@lakedaemon.net>
> Cc: Andreas Bie=DFmann <andreas.devel@googlemail.com>
> Cc: Reinhard Arlt <reinhard.arlt@esd-electronics.com>
> Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
> ---
> v2: changed to Thierry's recommendation in:
> 
> http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/134043
> 
> build-tested only - please ack
> 
>  fs/ext2/ext2fs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks.

Best regards,

Wolfgang Denk
Tom Rini July 23, 2012, 6:56 p.m. UTC | #4
On Sun, Jul 08, 2012 at 10:55:16PM +0200, Wolfgang Denk wrote:
> Dear Kim Phillips,
> 
> In message <20120703174156.a1082309c2b205216606a004@freescale.com> you wrote:
> > This warning was introduced in 436da3c "ext2load: increase read
> > speed":
> > 
> > ext2fs.c: In function 'ext2fs_read_file':
> > ext2fs.c:458:19: warning: 'blocknxt' may be used uninitialized in this func=
> > tion [-Wuninitialized]
> > 
> > this change makes it go away.
> > 
> > Cc: Eric Nelson <eric.nelson@boundarydevices.com>
> > Cc: Thierry Reding <thierry.reding@avionic-design.de>
> > Cc: Jason Cooper <u-boot@lakedaemon.net>
> > Cc: Andreas Bie=DFmann <andreas.devel@googlemail.com>
> > Cc: Reinhard Arlt <reinhard.arlt@esd-electronics.com>
> > Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
> > ---
> > v2: changed to Thierry's recommendation in:
> > 
> > http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/134043
> > 
> > build-tested only - please ack
> > 
> >  fs/ext2/ext2fs.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Applied, thanks.

This doesn't fix the warning for ELDK 4.2 toolchains (gcc 4.2.2):
ext2fs.c: In function 'ext2fs_read_file':
ext2fs.c:443: warning: 'blocknxt' may be used uninitialized in this
function
Thierry Reding July 24, 2012, 4:59 a.m. UTC | #5
On Mon, Jul 23, 2012 at 11:56:00AM -0700, Tom Rini wrote:
> On Sun, Jul 08, 2012 at 10:55:16PM +0200, Wolfgang Denk wrote:
> > Dear Kim Phillips,
> > 
> > In message <20120703174156.a1082309c2b205216606a004@freescale.com> you wrote:
> > > This warning was introduced in 436da3c "ext2load: increase read
> > > speed":
> > > 
> > > ext2fs.c: In function 'ext2fs_read_file':
> > > ext2fs.c:458:19: warning: 'blocknxt' may be used uninitialized in this func=
> > > tion [-Wuninitialized]
> > > 
> > > this change makes it go away.
> > > 
> > > Cc: Eric Nelson <eric.nelson@boundarydevices.com>
> > > Cc: Thierry Reding <thierry.reding@avionic-design.de>
> > > Cc: Jason Cooper <u-boot@lakedaemon.net>
> > > Cc: Andreas Bie=DFmann <andreas.devel@googlemail.com>
> > > Cc: Reinhard Arlt <reinhard.arlt@esd-electronics.com>
> > > Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
> > > ---
> > > v2: changed to Thierry's recommendation in:
> > > 
> > > http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/134043
> > > 
> > > build-tested only - please ack
> > > 
> > >  fs/ext2/ext2fs.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > Applied, thanks.
> 
> This doesn't fix the warning for ELDK 4.2 toolchains (gcc 4.2.2):
> ext2fs.c: In function 'ext2fs_read_file':
> ext2fs.c:443: warning: 'blocknxt' may be used uninitialized in this
> function

I've seen older toolchains fail a lot at detecting situations like this.
I think starting with 4.5 things got a lot better.

Thierry
diff mbox

Patch

diff --git a/fs/ext2/ext2fs.c b/fs/ext2/ext2fs.c
index f1fce48..182f0ac 100644
--- a/fs/ext2/ext2fs.c
+++ b/fs/ext2/ext2fs.c
@@ -438,7 +438,7 @@  int ext2fs_read_file
 		}
 
 		/* grab middle blocks in one go */
-		if (i != pos / blocksize && i != blockcnt - 1 && blockcnt > 3) {
+		if (i != pos / blocksize && i < blockcnt - 1 && blockcnt > 3) {
 			int oldblk = blknr;
 			int blocknxt;
 			while (i < blockcnt - 1) {