Skip to contentSkip to conversation

DM RAID: validate_raid_redundancy: Silence uninitialized variable warning

PATCH Superseded Tim Gardner 5 participants 8 messages Feb 20, 2013 – Jun 13, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 DM RAID: validate_raid_redundancy: Silence uninitialized variable warning

drivers/md/dm-raid.c: In function 'raid_ctr':
drivers/md/dm-raid.c:453:53: warning: 'rebuilds_per_group' may be used uninitialized in this function [-Wuninitialized] drivers/md/dm-raid.c:383:11: note: 'rebuilds_per_group' was declared here

It appears unlikely that rebuilds_per_group could be used before set, but set it to 0 anyways just to shutup GCC.

---
 drivers/md/dm-raid.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-raid.c +1 -1
index 9d6bf19..8005caf 100644
@@ -380,7 +380,7 @@ static int validate_region_size(struct raid_set *rs, unsigned long region_size)
 static int validate_raid_redundancy(struct raid_set *rs)
 {
 	unsigned i, rebuild_cnt = 0;
-	unsigned rebuilds_per_group, copies, d;
+	unsigned rebuilds_per_group = 0, copies, d;
 	unsigned group_size, last_group_start;
 
 	for (i = 0; i < rs->md.raid_disks; i++)
Signature · 1 line
1.7.9.5
#1 lore raw

Dear Tim,

thanks for the patch.

Am Mittwoch, den 20.02.2013, 13:31 -0700 schrieb Tim Gardner:

Noting the gcc version and build environment is never wrong. ;-)

Quoted 5 lines

drivers/md/dm-raid.c: In function 'raid_ctr':
drivers/md/dm-raid.c:453:53: warning: 'rebuilds_per_group' may be used uninitialized in this function [-Wuninitialized] drivers/md/dm-raid.c:383:11: note: 'rebuilds_per_group' was declared here

It appears unlikely that rebuilds_per_group could be used before set,

Why? Otherwise the compiler would not complain, right?

Quoted 1 line

but set it to 0 anyways just to shutup GCC.

Unfortunately I do not know what linux-next version you tested, so the line numbers are off in.

        $ git describe
        v3.7.5-4-g9c2ab66
Quoted 14 lines
---
 drivers/md/dm-raid.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-raid.c +0 -0
index 9d6bf19..8005caf 100644

drivers/md/dm-raid.c static int validate_region_size(struct raid_set *rs, unsigned long region_size) · line 386

Quoted 8 lines
drivers/md/dm-raid.c +1 -1
@@ -380,7 +380,7 @@ static int validate_region_size(struct raid_set *rs, unsigned long region_size)
 static int validate_raid_redundancy(struct raid_set *rs)
 {
 	unsigned i, rebuild_cnt = 0;
-	unsigned rebuilds_per_group, copies, d;
+	unsigned rebuilds_per_group = 0, copies, d;
 	unsigned group_size, last_group_start;
 
 	for (i = 0; i < rs->md.raid_disks; i++)

Thanks,

Paul

#2 lore raw

Dear Tim,

Am Mittwoch, den 20.02.2013, 23:16 +0100 schrieb Paul Menzel:

Quoted 12 lines

Am Mittwoch, den 20.02.2013, 13:31 -0700 schrieb Tim Gardner:

Noting the gcc version and build environment is never wrong. ;-)

Quoted 5 lines

drivers/md/dm-raid.c: In function 'raid_ctr':
drivers/md/dm-raid.c:453:53: warning: 'rebuilds_per_group' may be used uninitialized in this function [-Wuninitialized] drivers/md/dm-raid.c:383:11: note: 'rebuilds_per_group' was declared here

It appears unlikely that rebuilds_per_group could be used before set,

Why? Otherwise the compiler would not complain, right?

Quoted 7 lines
Quoted 1 line

but set it to 0 anyways just to shutup GCC.

Unfortunately I do not know what linux-next version you tested, so the line numbers are off in.

        $ git describe
        v3.7.5-4-g9c2ab66

See below …

Quoted 11 lines

drivers/md/dm-raid.c

Quoted 11 lines
---
 drivers/md/dm-raid.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-raid.c +0 -0
index 9d6bf19..8005caf 100644

Git to the rescue. I guess I should be able to find that commit to make sense of the line numbers.

Quoted 11 lines

drivers/md/dm-raid.c static int validate_region_size(struct raid_set *rs, unsigned long region_size) · line 386

Quoted 11 lines
drivers/md/dm-raid.c +1 -1
@@ -380,7 +380,7 @@ static int validate_region_size(struct raid_set *rs, unsigned long region_size)
 static int validate_raid_redundancy(struct raid_set *rs)
 {
 	unsigned i, rebuild_cnt = 0;
-	unsigned rebuilds_per_group, copies, d;
+	unsigned rebuilds_per_group = 0, copies, d;
 	unsigned group_size, last_group_start;
 
 	for (i = 0; i < rs->md.raid_disks; i++)

Thanks,

Paul

#3 lore raw
In reply to Paul Menzel
Quoted 10 lines · On Wed, 20 Feb 2013 23:16:37 +0100 Paul Menzel <[email protected]> wrote:

Dear Tim,

thanks for the patch.

Am Mittwoch, den 20.02.2013, 13:31 -0700 schrieb Tim Gardner:

Noting the gcc version and build environment is never wrong. ;-)

Quoted 7 lines
Quoted 5 lines

drivers/md/dm-raid.c: In function 'raid_ctr':
drivers/md/dm-raid.c:453:53: warning: 'rebuilds_per_group' may be used uninitialized in this function [-Wuninitialized] drivers/md/dm-raid.c:383:11: note: 'rebuilds_per_group' was declared here

It appears unlikely that rebuilds_per_group could be used before set,

Why? Otherwise the compiler would not complain, right?

It is not simply unlikely, it is impossible. But gcc isn't that clever yet.

Quoted 8 lines

drivers/md/dm-raid.c static int validate_region_size(struct raid_set *rs, unsigned long region_size) · line 383

Quoted 8 lines
drivers/md/dm-raid.c +1 -1
@@ -380,7 +380,7 @@ static int validate_region_size(struct raid_set *rs, unsigned long region_size)
 static int validate_raid_redundancy(struct raid_set *rs)
 {
 	unsigned i, rebuild_cnt = 0;
-	unsigned rebuilds_per_group, copies, d;
+	unsigned rebuilds_per_group = 0, copies, d;

This should either be:

        unsigned uninitialized_var(rebuilds_per_group);
        unsigned copies, d;

which the old way and is being deprecated, but at least is consistent with the kernel as it is, or

        unsigned rebuilds_per_group = 0 /* GCC */;
	unsigned copies,d;

which is apparently the new way which I believe is due to be imposed on the kernel immediately after 3.9-rc1
https://lwn.net/Articles/529954/

NeilBrown

#4 lore raw
In reply to Tim Gardner
Quoted 6 lines · Tim Gardner

drivers/md/dm-raid.c: In function 'raid_ctr':
drivers/md/dm-raid.c:453:53: warning: 'rebuilds_per_group' may be used uninitialized in this function [-Wuninitialized] drivers/md/dm-raid.c:383:11: note: 'rebuilds_per_group' was declared here

It appears unlikely that rebuilds_per_group could be used before set, but set it to 0 anyways just to shutup GCC.

Looks bogus to me.
uninitialized_var() please.

Alasdair

#5 lore raw

PATCH v2 1/1 DM RAID: validate_raid_redundancy: Silence uninitialized variable warning

drivers/md/dm-raid.c:453:53: warning: 'rebuilds_per_group' may be used uninitialized in this function [-Wuninitialized] drivers/md/dm-raid.c:383:11: note: 'rebuilds_per_group' was declared here

It is impossible that rebuilds_per_group could be used before set, but set it to 0 anyways to silence GCC warnings.

---

v2 - Added GCC comment. Update commit log with a more definite explanation.

As Neil has pointed out, https://lwn.net/Articles/529954/ indicates uninitialized_var() is going away.

 drivers/md/dm-raid.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/dm-raid.c +2 -1
index 9d6bf19..1dbc341 100644
@@ -380,7 +380,8 @@ static int validate_region_size(struct raid_set *rs, unsigned long region_size)
 static int validate_raid_redundancy(struct raid_set *rs)
 {
 	unsigned i, rebuild_cnt = 0;
-	unsigned rebuilds_per_group, copies, d;
+	unsigned rebuilds_per_group = 0; /* GCC 4.6.3 */
+	unsigned copies, d;
 	unsigned group_size, last_group_start;
 
 	for (i = 0; i < rs->md.raid_disks; i++)
Signature · 1 line
1.7.9.5
#6 lore raw

2013/2/21 Tim Gardner <[email protected]>:

Quoted 2 lines

drivers/md/dm-raid.c:453:53: warning: 'rebuilds_per_group' may be used uninitialized in this function [-Wuninitialized] drivers/md/dm-raid.c:383:11: note: 'rebuilds_per_group' was declared here

Hello, is this patch getting merged? I'm also seeing this exact same compiler warning in my mainline builds.

Tommi

Quoted 41 lines

It is impossible that rebuilds_per_group could be used before set, but set it to 0 anyways to silence GCC warnings.

---

v2 - Added GCC comment. Update commit log with a more definite explanation.

As Neil has pointed out, https://lwn.net/Articles/529954/ indicates uninitialized_var() is going away.

 drivers/md/dm-raid.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/dm-raid.c +2 -2
index 9d6bf19..1dbc341 100644
@@ -380,7 +380,8 @@ static int validate_region_size(struct raid_set *rs, unsigned long region_size)
 static int validate_raid_redundancy(struct raid_set *rs)
 {
        unsigned i, rebuild_cnt = 0;
-       unsigned rebuilds_per_group, copies, d;
+       unsigned rebuilds_per_group = 0; /* GCC 4.6.3 */
+       unsigned copies, d;
        unsigned group_size, last_group_start;
 
        for (i = 0; i < rs->md.raid_disks; i++)
--

1.7.9.5

--
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/

#7 lore raw
Quoted 9 lines · Tommi Rantala

2013/2/21 Tim Gardner <[email protected]>:

Quoted 2 lines

drivers/md/dm-raid.c:453:53: warning: 'rebuilds_per_group' may be used uninitialized in this function [-Wuninitialized] drivers/md/dm-raid.c:383:11: note: 'rebuilds_per_group' was declared here

Hello, is this patch getting merged? I'm also seeing this exact same compiler warning in my mainline builds.

Tommi

Dunno. I haven't hassled anyone because it _is_ just a warning.

Signature · 1 line
Tim Gardner [email protected]