linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mac80211: fix "warning: ‘target_metric’ may be used uninitialized"
@ 2016-04-04 18:15 Jeff Mahoney
  2016-04-05  9:43 ` Johannes Berg
  2016-04-06 13:14 ` Johannes Berg
  0 siblings, 2 replies; 6+ messages in thread
From: Jeff Mahoney @ 2016-04-04 18:15 UTC (permalink / raw)
  To: Johannes Berg, linux-wireless

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.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---

 net/mac80211/mesh_hwmp.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/net/mac80211/mesh_hwmp.c
+++ b/net/mac80211/mesh_hwmp.c
@@ -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;

-- 
Jeff Mahoney
SUSE Labs

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] mac80211: fix "warning: ‘target_metric’ may be used uninitialized"
  2016-04-04 18:15 [PATCH] mac80211: fix "warning: ‘target_metric’ may be used uninitialized" Jeff Mahoney
@ 2016-04-05  9:43 ` Johannes Berg
  2016-04-05 13:33   ` Jeff Mahoney
  2016-04-06 13:14 ` Johannes Berg
  1 sibling, 1 reply; 6+ messages in thread
From: Johannes Berg @ 2016-04-05  9:43 UTC (permalink / raw)
  To: Jeff Mahoney, linux-wireless

On Mon, 2016-04-04 at 14:15 -0400, Jeff Mahoney wrote:
> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] mac80211: fix "warning: ‘target_metric’ may be used uninitialized"
  2016-04-05  9:43 ` Johannes Berg
@ 2016-04-05 13:33   ` Jeff Mahoney
  2016-04-05 13:40     ` Johannes Berg
  0 siblings, 1 reply; 6+ messages in thread
From: Jeff Mahoney @ 2016-04-05 13:33 UTC (permalink / raw)
  To: Johannes Berg, linux-wireless


[-- Attachment #1.1: Type: text/plain, Size: 573 bytes --]

On 4/5/16 5:43 AM, Johannes Berg wrote:
> On Mon, 2016-04-04 at 14:15 -0400, Jeff Mahoney wrote:
>> 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.

gcc version 4.8.5 (SUSE Linux)

-Jeff

-- 
Jeff Mahoney
SUSE Labs


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 881 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] mac80211: fix "warning: ‘target_metric’ may be used uninitialized"
  2016-04-05 13:33   ` Jeff Mahoney
@ 2016-04-05 13:40     ` Johannes Berg
  2016-04-05 13:47       ` Jeff Mahoney
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Berg @ 2016-04-05 13:40 UTC (permalink / raw)
  To: Jeff Mahoney, linux-wireless

On Tue, 2016-04-05 at 09:33 -0400, Jeff Mahoney wrote:
> On 4/5/16 5:43 AM, Johannes Berg wrote:
> > 
> > On Mon, 2016-04-04 at 14:15 -0400, Jeff Mahoney wrote:
> > > 
> > > 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.
> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] mac80211: fix "warning: ‘target_metric’ may be used uninitialized"
  2016-04-05 13:40     ` Johannes Berg
@ 2016-04-05 13:47       ` Jeff Mahoney
  0 siblings, 0 replies; 6+ messages in thread
From: Jeff Mahoney @ 2016-04-05 13:47 UTC (permalink / raw)
  To: Johannes Berg, linux-wireless


[-- Attachment #1.1: Type: text/plain, Size: 1372 bytes --]

On 4/5/16 9:40 AM, Johannes Berg wrote:
> On Tue, 2016-04-05 at 09:33 -0400, Jeff Mahoney wrote:
>> On 4/5/16 5:43 AM, Johannes Berg wrote:
>>>
>>> On Mon, 2016-04-04 at 14:15 -0400, Jeff Mahoney wrote:
>>>>
>>>> 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.
>> 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

-- 
Jeff Mahoney
SUSE Labs


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 881 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] mac80211: fix "warning: ‘target_metric’ may be used uninitialized"
  2016-04-04 18:15 [PATCH] mac80211: fix "warning: ‘target_metric’ may be used uninitialized" Jeff Mahoney
  2016-04-05  9:43 ` Johannes Berg
@ 2016-04-06 13:14 ` Johannes Berg
  1 sibling, 0 replies; 6+ messages in thread
From: Johannes Berg @ 2016-04-06 13:14 UTC (permalink / raw)
  To: Jeff Mahoney, linux-wireless

On Mon, 2016-04-04 at 14:15 -0400, Jeff Mahoney wrote:
> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-04-06 13:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-04 18:15 [PATCH] mac80211: fix "warning: ‘target_metric’ may be used uninitialized" Jeff Mahoney
2016-04-05  9:43 ` Johannes Berg
2016-04-05 13:33   ` Jeff Mahoney
2016-04-05 13:40     ` Johannes Berg
2016-04-05 13:47       ` Jeff Mahoney
2016-04-06 13:14 ` Johannes Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).