All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] mac80211: initialize sta pointer to avoid false-positive warning
@ 2012-06-18 12:52 Luciano Coelho
  2012-06-20  8:52 ` Johannes Berg
  0 siblings, 1 reply; 5+ messages in thread
From: Luciano Coelho @ 2012-06-18 12:52 UTC (permalink / raw)
  To: johannes; +Cc: linville, linux-wireless, tony

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 and checking for sta instead of !have_sta in the second if.

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

In v2:

   Changed the second if to "if (sta)" to make it cleaner, as Johannes
   suggested.


 net/mac80211/mlme.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 66e4fcd..1094ada 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;
@@ -3126,7 +3126,7 @@ static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
 	local->oper_channel = cbss->channel;
 	ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
 
-	if (!have_sta) {
+	if (sta) {
 		u32 rates = 0, basic_rates = 0;
 		bool have_higher_than_11mbit;
 		int min_rate = INT_MAX, min_rate_index = -1;
-- 
1.7.10


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

* Re: [PATCH v2] mac80211: initialize sta pointer to avoid false-positive warning
  2012-06-18 12:52 [PATCH v2] mac80211: initialize sta pointer to avoid false-positive warning Luciano Coelho
@ 2012-06-20  8:52 ` Johannes Berg
  2012-06-20  8:55   ` Luciano Coelho
  0 siblings, 1 reply; 5+ messages in thread
From: Johannes Berg @ 2012-06-20  8:52 UTC (permalink / raw)
  To: Luciano Coelho; +Cc: linville, linux-wireless, tony

On Mon, 2012-06-18 at 15:52 +0300, Luciano Coelho wrote:
> 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:

I still think it's a workaround, but what the hell ... applied.

johannes


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

* Re: [PATCH v2] mac80211: initialize sta pointer to avoid false-positive warning
  2012-06-20  8:52 ` Johannes Berg
@ 2012-06-20  8:55   ` Luciano Coelho
  2012-06-20  9:05     ` Johannes Berg
  0 siblings, 1 reply; 5+ messages in thread
From: Luciano Coelho @ 2012-06-20  8:55 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linville, linux-wireless, tony

On Wed, 2012-06-20 at 10:52 +0200, Johannes Berg wrote:
> On Mon, 2012-06-18 at 15:52 +0300, Luciano Coelho wrote:
> > 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:
> 
> I still think it's a workaround, but what the hell ... applied.

Yes, it is a workaround, but a lean one.  :) And I think after your
suggestion it makes the code slightly more readable.

Thanks for applying!

BTW, when you say you applied, does it mean you have pushed to your
tree? We want to remove some of our mac80211 patches from our internal
trees and "inherit" them from upstream instead, that's why I'm
asking. ;)

--
Luca.


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

* Re: [PATCH v2] mac80211: initialize sta pointer to avoid false-positive warning
  2012-06-20  8:55   ` Luciano Coelho
@ 2012-06-20  9:05     ` Johannes Berg
  2012-06-20  9:07       ` Luciano Coelho
  0 siblings, 1 reply; 5+ messages in thread
From: Johannes Berg @ 2012-06-20  9:05 UTC (permalink / raw)
  To: Luciano Coelho; +Cc: linville, linux-wireless, tony

On Wed, 2012-06-20 at 11:55 +0300, Luciano Coelho wrote:

> BTW, when you say you applied, does it mean you have pushed to your
> tree? We want to remove some of our mac80211 patches from our internal
> trees and "inherit" them from upstream instead, that's why I'm
> asking. ;)

It may or may not mean that, I've not quite figured out the entire
workflow.

So far, it has basically meant "I'm happy with it and I picked it up
into my (local) git tree". I will also push it into one of the
mac80211/mac80211-next repositories.

However, I make no guarantees that I don't have to rebase those
repositories sometimes, if I were you I wouldn't merge from me right
now, at least until I've figured out my workflow completely...

I do plan on sending a pull request to John every week or so though, and
when I do I've obviously committed to the code :)

johannes


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

* Re: [PATCH v2] mac80211: initialize sta pointer to avoid false-positive warning
  2012-06-20  9:05     ` Johannes Berg
@ 2012-06-20  9:07       ` Luciano Coelho
  0 siblings, 0 replies; 5+ messages in thread
From: Luciano Coelho @ 2012-06-20  9:07 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linville, linux-wireless, tony

On Wed, 2012-06-20 at 11:05 +0200, Johannes Berg wrote:
> On Wed, 2012-06-20 at 11:55 +0300, Luciano Coelho wrote:
> 
> > BTW, when you say you applied, does it mean you have pushed to your
> > tree? We want to remove some of our mac80211 patches from our internal
> > trees and "inherit" them from upstream instead, that's why I'm
> > asking. ;)
> 
> It may or may not mean that, I've not quite figured out the entire
> workflow.
> 
> So far, it has basically meant "I'm happy with it and I picked it up
> into my (local) git tree". I will also push it into one of the
> mac80211/mac80211-next repositories.
> 
> However, I make no guarantees that I don't have to rebase those
> repositories sometimes, if I were you I wouldn't merge from me right
> now, at least until I've figured out my workflow completely...
> 
> I do plan on sending a pull request to John every week or so though, and
> when I do I've obviously committed to the code :)

Cool, I think I'll wait for your pull then.

--
Luca.


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

end of thread, other threads:[~2012-06-20  9:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-18 12:52 [PATCH v2] mac80211: initialize sta pointer to avoid false-positive warning Luciano Coelho
2012-06-20  8:52 ` Johannes Berg
2012-06-20  8:55   ` Luciano Coelho
2012-06-20  9:05     ` Johannes Berg
2012-06-20  9:07       ` Luciano Coelho

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.