Skip to contentSkip to conversation

ext4_lazyinit_thread: 'ret' may be used uninitialized in this function

DISCUSSION Stefan Richter 6 participants 10 messages Oct 31, 2010 – Nov 2, 2010 ext4 file system

lore
Share & tools
lore
#0 lore raw

Commit bfff68738f1c "ext4: add support for lazy inode table initialization" added the following build warning:

fs/ext4/super.c: In function 'ext4_lazyinit_thread':
fs/ext4/super.c:2702: warning: 'ret' may be used uninitialized in this function

This warning is due to an actual bug. But I don't know what the fix is.

Signature · 3 lines
Stefan Richter
-=====-==-=- =-=- =====
http://arcgraph.de/sr/
#1 lore raw
Quoted 8 lines · Stefan Richter

Commit bfff68738f1c "ext4: add support for lazy inode table initialization" added the following build warning:

fs/ext4/super.c: In function 'ext4_lazyinit_thread':
fs/ext4/super.c:2702: warning: 'ret' may be used uninitialized in this function

This warning is due to an actual bug. But I don't know what the fix is.

Hi Stefan,

thank you for noticing this, because I actually do not see the warning (I wonder why...), but it is definitely a bug, so the trivial patch below should fix that.

Thanks!
-Lukas

Quoted 1 line

From 3594c17e3f724356ea8cc0a1579ab09990a771ac Mon Sep 17 00:00:00 2001

From: Lukas Czerner <[email protected]>
Date: Mon, 1 Nov 2010 15:44:54 +0100
Subject: [PATCH] ext4: fix using uninitialized variable

The ret variable might be used uninitialized. Fix this by initializing it in definition.

---
 fs/ext4/super.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/ext4/super.c +1 -1
index 8d1d942..aff17cf 100644
@@ -2699,7 +2699,7 @@ static int ext4_lazyinit_thread(void *arg)
 	struct ext4_li_request *elr;
 	unsigned long next_wakeup;
 	DEFINE_WAIT(wait);
-	int ret;
+	int ret = 0;
 
 	BUG_ON(NULL == eli);
 
Signature · 1 line
1.7.2.3
#2 lore raw
Quoted 2 lines · Lukas Czerner

thank you for noticing this, because I actually do not see the warning (I wonder why...),

Probably because of different gcc versions. Here: 4.3.4

Signature · 3 lines
Stefan Richter
-=====-==-=- =-== ----=
http://arcgraph.de/sr/
maintainer
#3 lore raw
In reply to Lukas Czerner
Quoted 4 lines · Lukas Czerner

thank you for noticing this, because I actually do not see the warning (I wonder why...), but it is definitely a bug, so the trivial patch below should fix that.

This is a slightly less trivial fix that eliminates the need for the "ret" variable entirely.

- Ted

commit e048924538f0c62d18306e2fea0e22dac0140f6e

Author: Theodore Ts'o <[email protected]>
Date:   Tue Nov 2 14:19:30 2010 -0400

ext4: "ret" may be used uninitialized in ext4_lazyinit_thread()

Newer GCC's reported the following build warning:

fs/ext4/super.c: In function 'ext4_lazyinit_thread':
fs/ext4/super.c:2702: warning: 'ret' may be used uninitialized in this function

Fix it by removing the need for the ret variable in the first place.

fs/ext4/super.c +0 -3
index 8d1d942..4d7ef31 100644
@@ -2699,7 +2699,6 @@ static int ext4_lazyinit_thread(void *arg)
 	struct ext4_li_request *elr;
 	unsigned long next_wakeup;
 	DEFINE_WAIT(wait);
-	int ret;
 
 	BUG_ON(NULL == eli);
 
@@ -2723,13 +2722,12 @@ cont_thread:
 			elr = list_entry(pos, struct ext4_li_request,
 					 lr_request);
 
-			if (time_after_eq(jiffies, elr->lr_next_sched))
-				ret = ext4_run_li_request(elr);
#4 lore raw
Quoted 51 lines · Ted Ts'o
Quoted 4 lines · Lukas Czerner

thank you for noticing this, because I actually do not see the warning (I wonder why...), but it is definitely a bug, so the trivial patch below should fix that.

This is a slightly less trivial fix that eliminates the need for the "ret" variable entirely.

                                               - Ted

commit e048924538f0c62d18306e2fea0e22dac0140f6e
Author: Theodore Ts'o <[email protected]>
Date:   Tue Nov 2 14:19:30 2010 -0400

   ext4: "ret" may be used uninitialized in ext4_lazyinit_thread()

   Newer GCC's reported the following build warning:

      fs/ext4/super.c: In function 'ext4_lazyinit_thread':
      fs/ext4/super.c:2702: warning: 'ret' may be used uninitialized in this function

   Fix it by removing the need for the ret variable in the first place.

fs/ext4/super.c +0 -7
index 8d1d942..4d7ef31 100644
@@ -2699,7 +2699,6 @@ static int ext4_lazyinit_thread(void *arg)
        struct ext4_li_request *elr;
        unsigned long next_wakeup;
        DEFINE_WAIT(wait);
-       int ret;
 
        BUG_ON(NULL == eli);
 
@@ -2723,13 +2722,12 @@ cont_thread:
                        elr = list_entry(pos, struct ext4_li_request,
                                         lr_request);
 
-                       if (time_after_eq(jiffies, elr->lr_next_sched))
-                               ret = ext4_run_li_request(elr);
-
-                       if (ret) {
-                               ret = 0;
-                               ext4_remove_li_request(elr);

fs/ext4/super.c cont_thread: · line 2733

Quoted 10 lines
fs/ext4/super.c +6 -1
-                               continue;
+                       if (time_after_eq(jiffies, elr->lr_next_sched)) {
+                               if (ext4_run_li_request(elr) != 0) {
+                                       /* error, remove the lazy_init job */
+                                       ext4_remove_li_request(elr);
+                                       continue;
+                               }
                        }
 
                        if (time_before(elr->lr_next_sched, next_wakeup))

What do you think about this option for the second hunk? (not anything-tested)

@@ -2723,13 +2722,11 @@ cont_thread:
elr = list_entry(pos, struct ext4_li_request,
lr_request);
- if (time_after_eq(jiffies, elr->lr_next_sched))
- ret = ext4_run_li_request(elr);
-
- if (ret) {

-                               ret = 0;
-                               ext4_remove_li_request(elr);
-                               continue;
+                       if (time_after_eq(jiffies, elr->lr_next_sched) &&
+                           ext4_run_li_request(elr) != 0) {
+                               /* error, remove the lazy_init job */
+                               ext4_remove_li_request(elr);
+                               continue;
                       }

                       if (time_before(elr->lr_next_sched, next_wakeup))

--

Though obviously it's a pretty subjective style issue. Kevin Granade

Quoted 4 lines

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 85 lines · kevin granade
Quoted 51 lines · Ted Ts'o
Quoted 4 lines · Lukas Czerner

thank you for noticing this, because I actually do not see the warning (I wonder why...), but it is definitely a bug, so the trivial patch below should fix that.

This is a slightly less trivial fix that eliminates the need for the "ret" variable entirely.

                                               - Ted

commit e048924538f0c62d18306e2fea0e22dac0140f6e
Author: Theodore Ts'o <[email protected]>
Date:   Tue Nov 2 14:19:30 2010 -0400

   ext4: "ret" may be used uninitialized in ext4_lazyinit_thread()

   Newer GCC's reported the following build warning:

      fs/ext4/super.c: In function 'ext4_lazyinit_thread':
      fs/ext4/super.c:2702: warning: 'ret' may be used uninitialized in this function

   Fix it by removing the need for the ret variable in the first place.

fs/ext4/super.c +0 -7
index 8d1d942..4d7ef31 100644
@@ -2699,7 +2699,6 @@ static int ext4_lazyinit_thread(void *arg)
        struct ext4_li_request *elr;
        unsigned long next_wakeup;
        DEFINE_WAIT(wait);
-       int ret;
 
        BUG_ON(NULL == eli);
 
@@ -2723,13 +2722,12 @@ cont_thread:
                        elr = list_entry(pos, struct ext4_li_request,
                                         lr_request);
 
-                       if (time_after_eq(jiffies, elr->lr_next_sched))
-                               ret = ext4_run_li_request(elr);
-
-                       if (ret) {
-                               ret = 0;
-                               ext4_remove_li_request(elr);

fs/ext4/super.c cont_thread: · line 2733

Quoted 10 lines
fs/ext4/super.c +6 -1
-                               continue;
+                       if (time_after_eq(jiffies, elr->lr_next_sched)) {
+                               if (ext4_run_li_request(elr) != 0) {
+                                       /* error, remove the lazy_init job */
+                                       ext4_remove_li_request(elr);
+                                       continue;
+                               }
                        }
 
                        if (time_before(elr->lr_next_sched, next_wakeup))

What do you think about this option for the second hunk? (not anything-tested)

(quoted diff) +5 -8
@@ -2723,13 +2722,11 @@ cont_thread:
                       elr = list_entry(pos, struct ext4_li_request,
                                        lr_request);
-                       if (time_after_eq(jiffies, elr->lr_next_sched))
-                               ret = ext4_run_li_request(elr);
-
-                       if (ret) {
-                               ret = 0;
-                               ext4_remove_li_request(elr);
-                               continue;
+                       if (time_after_eq(jiffies, elr->lr_next_sched) &&
+                           ext4_run_li_request(elr) != 0) {
+                               /* error, remove the lazy_init job */
+                               ext4_remove_li_request(elr);
+                               continue;
                       }
 
                       if (time_before(elr->lr_next_sched, next_wakeup))
--
Quoted 2 lines

Though obviously it's a pretty subjective style issue. Kevin Granade

Hmm this relies on the fact that if the first part of the condition would not be true, the second part (after and) would never be invoked, however I am not really sure that we can rely on that on every architecture, or can we ?

Quoted 6 lines
Quoted 5 lines

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Thanks!

-Lukas

#6 lore raw
Quoted 4 lines · Lukas Czerner

Hmm this relies on the fact that if the first part of the condition would not be true, the second part (after and) would never be invoked, however I am not really sure that we can rely on that on every architecture, or can we ?

This behaviour of the && operator is guaranteed by the C standard.

Signature · 1 line
Nick Bowler, Elliptic Technologies (http://www.elliptictech.com/)
#7 lore raw
In reply to Lukas Czerner
Quoted 11 lines · Lukas Czerner
Quoted 10 lines · kevin granade
(quoted diff) +5 -1
+                       if (time_after_eq(jiffies, elr->lr_next_sched) &&
+                           ext4_run_li_request(elr) != 0) {
+                               /* error, remove the lazy_init job */
+                               ext4_remove_li_request(elr);
+                               continue;
                       }
 
                       if (time_before(elr->lr_next_sched, next_wakeup))
--
Quoted 7 lines
Quoted 2 lines

Though obviously it's a pretty subjective style issue. Kevin Granade

Hmm this relies on the fact that if the first part of the condition would not be true, the second part (after and) would never be invoked, however I am not really sure that we can rely on that on every architecture, or can we ?

It is not about architecture but a C language feature. It is relied upon everywhere in the kernel. For example,

	if (p != NULL && p->m == something) {
		...

is very common. The || operator has the same property: Evaluation stops as soon as the end result is known. I do not know since when this minimum evaluation feature is guaranteed in the language, but it has to be ages now.

(This is not an endorsement of one or the other coding of the patch. :-)

Signature · 3 lines
Stefan Richter
-=====-==-=- =-== ---=-
http://arcgraph.de/sr/
#8 lore raw

Indeed. In clause 4 of Section 6.5.13 of C99, short circuit evaluation is guaranteed in addition to left to right evaluation.

Quoted 41 lines · Stefan Richter
Quoted 11 lines · Lukas Czerner
Quoted 10 lines · kevin granade
(quoted diff) +5 -1
+                       if (time_after_eq(jiffies, elr->lr_next_sched) &&
+                           ext4_run_li_request(elr) != 0) {
+                               /* error, remove the lazy_init job */
+                               ext4_remove_li_request(elr);
+                               continue;
                       }
 
                       if (time_before(elr->lr_next_sched, next_wakeup))
--
Quoted 7 lines
Quoted 2 lines

Though obviously it's a pretty subjective style issue. Kevin Granade

Hmm this relies on the fact that if the first part of the condition would not be true, the second part (after and) would never be invoked, however I am not really sure that we can rely on that on every architecture, or can we ?

It is not about architecture but a C language feature. It is relied upon everywhere in the kernel. For example,

	if (p != NULL && p->m == something) {
		...

is very common. The || operator has the same property: Evaluation stops as soon as the end result is known. I do not know since when this minimum evaluation feature is guaranteed in the language, but it has to be ages now.

(This is not an endorsement of one or the other coding of the patch. :-) --
Stefan Richter
-=====-==-=- =-== ---=-
http://arcgraph.de/sr/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 3 lines
Brian Gitonga Marete
Toshnix Systems
Tel: +254722151590
#9 lore raw
In reply to Ted Ts'o
Quoted 44 lines · Ted Ts'o
Quoted 4 lines · Lukas Czerner

thank you for noticing this, because I actually do not see the warning (I wonder why...), but it is definitely a bug, so the trivial patch below should fix that.

This is a slightly less trivial fix that eliminates the need for the "ret" variable entirely.

- Ted

commit e048924538f0c62d18306e2fea0e22dac0140f6e

Author: Theodore Ts'o <[email protected]>
Date:   Tue Nov 2 14:19:30 2010 -0400

ext4: "ret" may be used uninitialized in ext4_lazyinit_thread()

Newer GCC's reported the following build warning:

fs/ext4/super.c: In function 'ext4_lazyinit_thread':
fs/ext4/super.c:2702: warning: 'ret' may be used uninitialized in this function

Fix it by removing the need for the ret variable in the first place.

fs/ext4/super.c +0 -1
index 8d1d942..4d7ef31 100644
@@ -2699,7 +2699,6 @@ static int ext4_lazyinit_thread(void *arg)
 	struct ext4_li_request *elr;
 	unsigned long next_wakeup;
 	DEFINE_WAIT(wait);
-	int ret;
 
 	BUG_ON(NULL == eli);
 
@@ -2723,13 +2722,12 @@ cont_thread:
 			elr = list_entry(pos, struct ext4_li_request,
 					 lr_request);
 

fs/ext4/super.c cont_thread: · line 2727

Quoted 10 lines
fs/ext4/super.c +3 -7
-			if (time_after_eq(jiffies, elr->lr_next_sched))
-				ret = ext4_run_li_request(elr);
-
-			if (ret) {
-				ret = 0;
-				ext4_remove_li_request(elr);
-				continue;
+			if (time_after_eq(jiffies, elr->lr_next_sched)) {
+				if (ext4_run_li_request(elr) != 0) {
+					/* error, remove the lazy_init job */

It is not removed only in the case of error, but even if it hits the last group, so I would just omit the "error" part.

fs/ext4/super.c cont_thread: · line 2733

Quoted 7 lines
fs/ext4/super.c +3 -0
+					ext4_remove_li_request(elr);
+					continue;
+				}
 			}
 
 			if (time_before(elr->lr_next_sched, next_wakeup))

Otherwise looks good to me.

-Lukas