linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cw1200: fix bogus maybe-uninitialized warning
@ 2016-10-24 15:41 Arnd Bergmann
  2016-10-25 13:24 ` David Laight
  0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2016-10-24 15:41 UTC (permalink / raw)
  To: Solomon Peachy, Kalle Valo
  Cc: Arnd Bergmann, Johannes Berg, linux-wireless, netdev, linux-kernel

On x86, the cw1200 driver produces a rather silly warning about the
possible use of the 'ret' variable without an initialization
presumably after being confused by the architecture specific definition
of WARN_ON:

drivers/net/wireless/st/cw1200/wsm.c: In function ‘wsm_handle_rx’:
drivers/net/wireless/st/cw1200/wsm.c:1457:9: error: ‘ret’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

As the driver just checks the same variable twice here, we can simplify
it by removing the second condition, which makes it more readable and
avoids the warning.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/net/wireless/st/cw1200/wsm.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wireless/st/cw1200/wsm.c b/drivers/net/wireless/st/cw1200/wsm.c
index 680d60eabc75..094e6637ade2 100644
--- a/drivers/net/wireless/st/cw1200/wsm.c
+++ b/drivers/net/wireless/st/cw1200/wsm.c
@@ -385,14 +385,13 @@ static int wsm_multi_tx_confirm(struct cw1200_common *priv,
 	if (WARN_ON(count <= 0))
 		return -EINVAL;
 
-	if (count > 1) {
-		/* We already released one buffer, now for the rest */
-		ret = wsm_release_tx_buffer(priv, count - 1);
-		if (ret < 0)
-			return ret;
-		else if (ret > 0)
-			cw1200_bh_wakeup(priv);
-	}
+	/* We already released one buffer, now for the rest */
+	ret = wsm_release_tx_buffer(priv, count - 1);
+	if (ret < 0)
+		return ret;
+
+	if (ret > 0)
+		cw1200_bh_wakeup(priv);
 
 	cw1200_debug_txed_multi(priv, count);
 	for (i = 0; i < count; ++i) {
-- 
2.9.0

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

* RE: [PATCH] cw1200: fix bogus maybe-uninitialized warning
  2016-10-24 15:41 [PATCH] cw1200: fix bogus maybe-uninitialized warning Arnd Bergmann
@ 2016-10-25 13:24 ` David Laight
  2016-10-25 18:13   ` Solomon Peachy
  2016-10-25 20:19   ` Arnd Bergmann
  0 siblings, 2 replies; 4+ messages in thread
From: David Laight @ 2016-10-25 13:24 UTC (permalink / raw)
  To: 'Arnd Bergmann', Solomon Peachy, Kalle Valo
  Cc: Johannes Berg, linux-wireless, netdev, linux-kernel

From: Of Arnd Bergmann
> Sent: 24 October 2016 16:42
 
> On x86, the cw1200 driver produces a rather silly warning about the
> possible use of the 'ret' variable without an initialization
> presumably after being confused by the architecture specific definition
> of WARN_ON:
> 
> drivers/net/wireless/st/cw1200/wsm.c: In function wsm_handle_rx:
> drivers/net/wireless/st/cw1200/wsm.c:1457:9: error: ret may be used uninitialized in this function [-
> Werror=maybe-uninitialized]
> 
> As the driver just checks the same variable twice here, we can simplify
> it by removing the second condition, which makes it more readable and
> avoids the warning.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/net/wireless/st/cw1200/wsm.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/wireless/st/cw1200/wsm.c b/drivers/net/wireless/st/cw1200/wsm.c
> index 680d60eabc75..094e6637ade2 100644
> --- a/drivers/net/wireless/st/cw1200/wsm.c
> +++ b/drivers/net/wireless/st/cw1200/wsm.c
> @@ -385,14 +385,13 @@ static int wsm_multi_tx_confirm(struct cw1200_common *priv,
>  	if (WARN_ON(count <= 0))
>  		return -EINVAL;
> 
> -	if (count > 1) {
> -		/* We already released one buffer, now for the rest */
> -		ret = wsm_release_tx_buffer(priv, count - 1);
> -		if (ret < 0)
> -			return ret;
> -		else if (ret > 0)
> -			cw1200_bh_wakeup(priv);
> -	}
> +	/* We already released one buffer, now for the rest */
> +	ret = wsm_release_tx_buffer(priv, count - 1);
> +	if (ret < 0)
> +		return ret;
> +
> +	if (ret > 0)
> +		cw1200_bh_wakeup(priv);

That doesn't look equivalent to me (when count == 1).

> 
>  	cw1200_debug_txed_multi(priv, count);
>  	for (i = 0; i < count; ++i) {

Convert this loop into a do ... while so the body executes at least once.

	David

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

* Re: [PATCH] cw1200: fix bogus maybe-uninitialized warning
  2016-10-25 13:24 ` David Laight
@ 2016-10-25 18:13   ` Solomon Peachy
  2016-10-25 20:19   ` Arnd Bergmann
  1 sibling, 0 replies; 4+ messages in thread
From: Solomon Peachy @ 2016-10-25 18:13 UTC (permalink / raw)
  To: David Laight
  Cc: 'Arnd Bergmann',
	Kalle Valo, Johannes Berg, linux-wireless, netdev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 839 bytes --]

On Tue, Oct 25, 2016 at 01:24:55PM +0000, David Laight wrote:
> > -	if (count > 1) {
> > -		/* We already released one buffer, now for the rest */
> > -		ret = wsm_release_tx_buffer(priv, count - 1);
> > -		if (ret < 0)
> > -			return ret;
> > -		else if (ret > 0)
> > -			cw1200_bh_wakeup(priv);
> > -	}
> > +	/* We already released one buffer, now for the rest */
> > +	ret = wsm_release_tx_buffer(priv, count - 1);
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	if (ret > 0)
> > +		cw1200_bh_wakeup(priv);
> 
> That doesn't look equivalent to me (when count == 1).

I concur, this patch should not be applied in its current form.

 - Solomon
-- 
Solomon Peachy        		       pizza at shaftnet dot org
Delray Beach, FL                          ^^ (email/xmpp) ^^
Quidquid latine dictum sit, altum viditur.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 163 bytes --]

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

* Re: [PATCH] cw1200: fix bogus maybe-uninitialized warning
  2016-10-25 13:24 ` David Laight
  2016-10-25 18:13   ` Solomon Peachy
@ 2016-10-25 20:19   ` Arnd Bergmann
  1 sibling, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2016-10-25 20:19 UTC (permalink / raw)
  To: David Laight
  Cc: Solomon Peachy, Kalle Valo, Johannes Berg, linux-wireless,
	netdev, linux-kernel

On Tuesday, October 25, 2016 1:24:55 PM CEST David Laight wrote:
> > diff --git a/drivers/net/wireless/st/cw1200/wsm.c b/drivers/net/wireless/st/cw1200/wsm.c
> > index 680d60eabc75..094e6637ade2 100644
> > --- a/drivers/net/wireless/st/cw1200/wsm.c
> > +++ b/drivers/net/wireless/st/cw1200/wsm.c
> > @@ -385,14 +385,13 @@ static int wsm_multi_tx_confirm(struct cw1200_common *priv,
> >       if (WARN_ON(count <= 0))
> >               return -EINVAL;
> > 
> > -     if (count > 1) {
> > -             /* We already released one buffer, now for the rest */
> > -             ret = wsm_release_tx_buffer(priv, count - 1);
> > -             if (ret < 0)
> > -                     return ret;
> > -             else if (ret > 0)
> > -                     cw1200_bh_wakeup(priv);
> > -     }
> > +     /* We already released one buffer, now for the rest */
> > +     ret = wsm_release_tx_buffer(priv, count - 1);
> > +     if (ret < 0)
> > +             return ret;
> > +
> > +     if (ret > 0)
> > +             cw1200_bh_wakeup(priv);
> 
> That doesn't look equivalent to me (when count == 1).

Ah, that's what I missed, thanks for pointing that out!

> > 
> >       cw1200_debug_txed_multi(priv, count);
> >       for (i = 0; i < count; ++i) {
> 
> Convert this loop into a do ... while so the body executes at least once.

Good idea. Version 2 coming now.

	Arnd

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

end of thread, other threads:[~2016-10-25 20:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-24 15:41 [PATCH] cw1200: fix bogus maybe-uninitialized warning Arnd Bergmann
2016-10-25 13:24 ` David Laight
2016-10-25 18:13   ` Solomon Peachy
2016-10-25 20:19   ` Arnd Bergmann

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).