DORMANTno replies

[PATCH] mac80211: initialize sta pointer to avoid false-positive warning

From: Luciano Coelho <hidden>
Date: 2012-06-18 07:03:48
Subsystem: mac80211, the rest · Maintainers: Johannes Berg, Linus Torvalds

Some compilers (eg. gcc 4.4.1 for ARM) report a false positive warning
in mlme.c:

net/mac80211/mlme.c: In function 'ieee80211_prep_connection':
net/mac80211/mlme.c:3035: warning: 'sta' may be used uninitialized in this function

This is a false positive because the place where 'sta' is used is
inside an if with the same condition of where it is set:

[...]
        if (!have_sta) {
                sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
                if (!sta)
                        return -ENOMEM;
        }
[...]
        if (!have_sta) {
[...]
                sta->sta.supp_rates[cbss->channel->band] = rates;
[...]

For some reason the compiler doesn't understand this and warns.

While this is not a problem in the code itself, we can avoid polluting
the build logs with false positives by setting sta to NULL on
declaration.

Reported-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Luciano Coelho <redacted>
---

Johannes,

I think I recall this having been discussed before.  I don't
completely like the solution for this problem, the compiler should be
fixed (and possibly already has), but this gcc version for ARM is
still widely used.  And as Tony pointed to me, this false-positive is
showing up in Russels build system:

http://www.arm.linux.org.uk/developer/build/result.php?type=build&idx=1178

If you don't like this patch, feel free to drop it and we'll have to
live with the false warning (and hope that next time someone cries
wolf we still react to it ;).

Cheers,
Luca.

 net/mac80211/mlme.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 66e4fcd..1bb1b4c 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -3032,7 +3032,7 @@ static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
 	struct ieee80211_local *local = sdata->local;
 	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
 	struct ieee80211_bss *bss = (void *)cbss->priv;
-	struct sta_info *sta;
+	struct sta_info *sta = NULL;
 	bool have_sta = false;
 	int err;
 	int ht_cfreq;
-- 
1.7.10
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help