Skip to contentSkip to conversation

mac80211: fix "warning: ‘target_metric’ may be used uninitialized"

PATCH Applied Jeff Mahoney 2 participants 6 messages Apr 4, 2016 – Apr 6, 2016 mac80211

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mac80211: fix "warning: ‘target_metric’ may be used uninitialized"

This fixes:

net/mac80211/mesh_hwmp.c:603:26: warning: ‘target_metric’ may be used uninitialized in this function

target_metric is only consumed when reply = true so no bug exists here, but gcc doesn't notice that. Initializing to 0 clears the warning.

---

 net/mac80211/mesh_hwmp.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mac80211/mesh_hwmp.c +1 -1
@@ -530,7 +530,7 @@ static void hwmp_preq_frame_process(stru
 	const u8 *target_addr, *orig_addr;
 	const u8 *da;
 	u8 target_flags, ttl, flags;
-	u32 orig_sn, target_sn, lifetime, target_metric;
+	u32 orig_sn, target_sn, lifetime, target_metric = 0;
 	bool reply = false;
 	bool forward = true;
 	bool root_is_gate;
Signature · 2 lines
Jeff Mahoney
SUSE Labs
maintainer
#1 lore raw
Quoted 9 lines · Jeff Mahoney

This fixes:

net/mac80211/mesh_hwmp.c:603:26: warning: ‘target_metric’ may be used uninitialized in this function

target_metric is only consumed when reply = true so no bug exists here,
but gcc doesn't notice that.  Initializing to 0 clears the warning.

What gcc version are you using? Mine doesn't seem to have a problem following the logic here.

johannes

#2 lore raw
Quoted 6 lines · Johannes Berg
Quoted 5 lines · Jeff Mahoney

This fixes:

net/mac80211/mesh_hwmp.c:603:26: warning: ‘target_metric’ may be used uninitialized in this function

Quoted 7 lines
Quoted 4 lines

target_metric is only consumed when reply = true so no bug exists here,
but gcc doesn't notice that. Initializing to 0 clears the warning.

What gcc version are you using? Mine doesn't seem to have a problem following the logic here.

gcc version 4.8.5 (SUSE Linux)

-Jeff

Signature · 2 lines
Jeff Mahoney
SUSE Labs
maintainer
#3 lore raw
Quoted 10 lines · Jeff Mahoney
Quoted 9 lines · Johannes Berg
Quoted 7 lines · Jeff Mahoney

This fixes:

net/mac80211/mesh_hwmp.c:603:26: warning: ‘target_metric’ may be used
uninitialized in this function

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

target_metric is only consumed when reply = true so no bug exists here,
but gcc doesn't notice that.  Initializing to 0 clears the warning.

What gcc version are you using? Mine doesn't seem to have a problem following the logic here.

gcc version 4.8.5 (SUSE Linux)

Ok, mine's significantly newer:

gcc (Debian 5.3.1-10) 5.3.1 20160224

I do wonder though if we really should do this? It might hide errors later on?

johannes

#4 lore raw
Quoted 18 lines · Johannes Berg
Quoted 17 lines · Jeff Mahoney
Quoted 16 lines · Johannes Berg
Quoted 12 lines · Jeff Mahoney

This fixes:

net/mac80211/mesh_hwmp.c:603:26: warning: ‘target_metric’ may be used
uninitialized in this function

target_metric is only consumed when reply = true so no bug exists here,
but gcc doesn't notice that. Initializing to 0 clears the warning.

What gcc version are you using? Mine doesn't seem to have a problem following the logic here.

Quoted 8 lines
Quoted 1 line

gcc version 4.8.5 (SUSE Linux)

Ok, mine's significantly newer:

gcc (Debian 5.3.1-10) 5.3.1 20160224

I do wonder though if we really should do this? It might hide errors later on?

AFAICT, the only way errors would be introduced is if someone added a new case in which reply was true *and* needed a different target_metric value (there are 3 cases it's used, 2 of which use 0). Or if there was a new case where the target_metric was used and reply wasn't true -- in which case this code would have been broken anyway.

Also, using uninitalized_var would have a higher probability of hiding an error later on. Setting it to 0 seems the safest course.

-Jeff

Signature · 2 lines
Jeff Mahoney
SUSE Labs
maintainer Applied
#5 lore raw
In reply to Jeff Mahoney
Quoted 9 lines · Jeff Mahoney

This fixes:

net/mac80211/mesh_hwmp.c:603:26: warning: ‘target_metric’ may be used uninitialized in this function

target_metric is only consumed when reply = true so no bug exists here,
but gcc doesn't notice that.  Initializing to 0 clears the warning.

Applied.

johannes