All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cfg80211: Change an 'else if' into an 'else' in cfg80211_calculate_bitrate_he
@ 2019-03-07 23:57 Nathan Chancellor
  2019-03-08  0:10 ` Nick Desaulniers
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Nathan Chancellor @ 2019-03-07 23:57 UTC (permalink / raw)
  To: Johannes Berg
  Cc: linux-wireless, David S. Miller, netdev, linux-kernel,
	clang-built-linux, Nick Desaulniers, Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

net/wireless/util.c:1223:11: warning: variable 'result' is used
uninitialized whenever 'if' condition is false
[-Wsometimes-uninitialized]

Clang can't evaluate at this point that WARN(1, ...) always returns true
because __ret_warn_on is defined as !!(condition), which isn't
immediately evaluated as 1. Change this branch to else so that it's
clear to Clang that we intend to bail out here.

Link: https://github.com/ClangBuiltLinux/linux/issues/382
Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
 net/wireless/util.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/wireless/util.c b/net/wireless/util.c
index e4b8db5e81ec..75899b62bdc9 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -1220,9 +1220,11 @@ static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate)
 	else if (rate->bw == RATE_INFO_BW_HE_RU &&
 		 rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_26)
 		result = rates_26[rate->he_gi];
-	else if (WARN(1, "invalid HE MCS: bw:%d, ru:%d\n",
-		      rate->bw, rate->he_ru_alloc))
+	else {
+		WARN(1, "invalid HE MCS: bw:%d, ru:%d\n",
+		     rate->bw, rate->he_ru_alloc);
 		return 0;
+	}
 
 	/* now scale to the appropriate MCS */
 	tmp = result;
-- 
2.21.0


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

* Re: [PATCH] cfg80211: Change an 'else if' into an 'else' in cfg80211_calculate_bitrate_he
  2019-03-07 23:57 [PATCH] cfg80211: Change an 'else if' into an 'else' in cfg80211_calculate_bitrate_he Nathan Chancellor
@ 2019-03-08  0:10 ` Nick Desaulniers
  2019-03-20 19:10 ` Nathan Chancellor
  2019-03-22 14:16 ` Arnd Bergmann
  2 siblings, 0 replies; 5+ messages in thread
From: Nick Desaulniers @ 2019-03-08  0:10 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Johannes Berg, linux-wireless, David S. Miller, netdev, LKML,
	clang-built-linux

On Thu, Mar 7, 2019 at 3:57 PM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> When building with -Wsometimes-uninitialized, Clang warns:
>
> net/wireless/util.c:1223:11: warning: variable 'result' is used
> uninitialized whenever 'if' condition is false
> [-Wsometimes-uninitialized]
>
> Clang can't evaluate at this point that WARN(1, ...) always returns true
> because __ret_warn_on is defined as !!(condition), which isn't
> immediately evaluated as 1. Change this branch to else so that it's
> clear to Clang that we intend to bail out here.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/382
> Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Thanks for the quick fix!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>  net/wireless/util.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/net/wireless/util.c b/net/wireless/util.c
> index e4b8db5e81ec..75899b62bdc9 100644
> --- a/net/wireless/util.c
> +++ b/net/wireless/util.c
> @@ -1220,9 +1220,11 @@ static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate)
>         else if (rate->bw == RATE_INFO_BW_HE_RU &&
>                  rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_26)
>                 result = rates_26[rate->he_gi];
> -       else if (WARN(1, "invalid HE MCS: bw:%d, ru:%d\n",
> -                     rate->bw, rate->he_ru_alloc))
> +       else {
> +               WARN(1, "invalid HE MCS: bw:%d, ru:%d\n",
> +                    rate->bw, rate->he_ru_alloc);
>                 return 0;
> +       }
>
>         /* now scale to the appropriate MCS */
>         tmp = result;
> --
> 2.21.0
>


-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH] cfg80211: Change an 'else if' into an 'else' in cfg80211_calculate_bitrate_he
  2019-03-07 23:57 [PATCH] cfg80211: Change an 'else if' into an 'else' in cfg80211_calculate_bitrate_he Nathan Chancellor
  2019-03-08  0:10 ` Nick Desaulniers
@ 2019-03-20 19:10 ` Nathan Chancellor
  2019-03-22 14:16 ` Arnd Bergmann
  2 siblings, 0 replies; 5+ messages in thread
From: Nathan Chancellor @ 2019-03-20 19:10 UTC (permalink / raw)
  To: Johannes Berg
  Cc: linux-wireless, David S. Miller, netdev, linux-kernel,
	clang-built-linux, Nick Desaulniers

On Thu, Mar 07, 2019 at 04:57:35PM -0700, Nathan Chancellor wrote:
> When building with -Wsometimes-uninitialized, Clang warns:
> 
> net/wireless/util.c:1223:11: warning: variable 'result' is used
> uninitialized whenever 'if' condition is false
> [-Wsometimes-uninitialized]
> 
> Clang can't evaluate at this point that WARN(1, ...) always returns true
> because __ret_warn_on is defined as !!(condition), which isn't
> immediately evaluated as 1. Change this branch to else so that it's
> clear to Clang that we intend to bail out here.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/382
> Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> ---
>  net/wireless/util.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/net/wireless/util.c b/net/wireless/util.c
> index e4b8db5e81ec..75899b62bdc9 100644
> --- a/net/wireless/util.c
> +++ b/net/wireless/util.c
> @@ -1220,9 +1220,11 @@ static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate)
>  	else if (rate->bw == RATE_INFO_BW_HE_RU &&
>  		 rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_26)
>  		result = rates_26[rate->he_gi];
> -	else if (WARN(1, "invalid HE MCS: bw:%d, ru:%d\n",
> -		      rate->bw, rate->he_ru_alloc))
> +	else {
> +		WARN(1, "invalid HE MCS: bw:%d, ru:%d\n",
> +		     rate->bw, rate->he_ru_alloc);
>  		return 0;
> +	}
>  
>  	/* now scale to the appropriate MCS */
>  	tmp = result;
> -- 
> 2.21.0
> 

Gentle ping (if there was a response to this, I didn't receive it). I
know I sent it in the middle of a merge window so I get if it slipped
through the cracks.

Thanks,
Nathan

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

* Re: [PATCH] cfg80211: Change an 'else if' into an 'else' in cfg80211_calculate_bitrate_he
  2019-03-07 23:57 [PATCH] cfg80211: Change an 'else if' into an 'else' in cfg80211_calculate_bitrate_he Nathan Chancellor
  2019-03-08  0:10 ` Nick Desaulniers
  2019-03-20 19:10 ` Nathan Chancellor
@ 2019-03-22 14:16 ` Arnd Bergmann
  2019-03-26  9:36   ` Simon Horman
  2 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2019-03-22 14:16 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Johannes Berg, linux-wireless, David S. Miller, Networking,
	Linux Kernel Mailing List, clang-built-linux, Nick Desaulniers

On Fri, Mar 8, 2019 at 12:57 AM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> When building with -Wsometimes-uninitialized, Clang warns:
>
> net/wireless/util.c:1223:11: warning: variable 'result' is used
> uninitialized whenever 'if' condition is false
> [-Wsometimes-uninitialized]
>
> Clang can't evaluate at this point that WARN(1, ...) always returns true
> because __ret_warn_on is defined as !!(condition), which isn't
> immediately evaluated as 1. Change this branch to else so that it's
> clear to Clang that we intend to bail out here.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/382
> Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> ---
>  net/wireless/util.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/net/wireless/util.c b/net/wireless/util.c
> index e4b8db5e81ec..75899b62bdc9 100644
> --- a/net/wireless/util.c
> +++ b/net/wireless/util.c
> @@ -1220,9 +1220,11 @@ static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate)
>         else if (rate->bw == RATE_INFO_BW_HE_RU &&
>                  rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_26)
>                 result = rates_26[rate->he_gi];
> -       else if (WARN(1, "invalid HE MCS: bw:%d, ru:%d\n",
> -                     rate->bw, rate->he_ru_alloc))
> +       else {
> +               WARN(1, "invalid HE MCS: bw:%d, ru:%d\n",
> +                    rate->bw, rate->he_ru_alloc);
>                 return 0;
> +       }

Reviewed-by: Arnd Bergmann <arnd@arndb.de>

I independently came up with the same fix before I saw yours,
the only difference was that I avoided the extra curly braces
using

+       else
+               return !WARN(1, "invalid HE MCS: bw:%d, ru:%d\n",
+                            rate->bw, rate->he_ru_alloc);

to avoid the mix of bare if() and if() {}

      Arnd

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

* Re: [PATCH] cfg80211: Change an 'else if' into an 'else' in cfg80211_calculate_bitrate_he
  2019-03-22 14:16 ` Arnd Bergmann
@ 2019-03-26  9:36   ` Simon Horman
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Horman @ 2019-03-26  9:36 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Nathan Chancellor, Johannes Berg, linux-wireless,
	David S. Miller, Networking, Linux Kernel Mailing List,
	clang-built-linux, Nick Desaulniers

On Fri, Mar 22, 2019 at 03:16:06PM +0100, Arnd Bergmann wrote:
> On Fri, Mar 8, 2019 at 12:57 AM Nathan Chancellor
> <natechancellor@gmail.com> wrote:
> >
> > When building with -Wsometimes-uninitialized, Clang warns:
> >
> > net/wireless/util.c:1223:11: warning: variable 'result' is used
> > uninitialized whenever 'if' condition is false
> > [-Wsometimes-uninitialized]
> >
> > Clang can't evaluate at this point that WARN(1, ...) always returns true
> > because __ret_warn_on is defined as !!(condition), which isn't
> > immediately evaluated as 1. Change this branch to else so that it's
> > clear to Clang that we intend to bail out here.
> >
> > Link: https://github.com/ClangBuiltLinux/linux/issues/382
> > Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
> > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> > ---
> >  net/wireless/util.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/net/wireless/util.c b/net/wireless/util.c
> > index e4b8db5e81ec..75899b62bdc9 100644
> > --- a/net/wireless/util.c
> > +++ b/net/wireless/util.c
> > @@ -1220,9 +1220,11 @@ static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate)
> >         else if (rate->bw == RATE_INFO_BW_HE_RU &&
> >                  rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_26)
> >                 result = rates_26[rate->he_gi];
> > -       else if (WARN(1, "invalid HE MCS: bw:%d, ru:%d\n",
> > -                     rate->bw, rate->he_ru_alloc))
> > +       else {
> > +               WARN(1, "invalid HE MCS: bw:%d, ru:%d\n",
> > +                    rate->bw, rate->he_ru_alloc);
> >                 return 0;
> > +       }
> 
> Reviewed-by: Arnd Bergmann <arnd@arndb.de>
> 
> I independently came up with the same fix before I saw yours,
> the only difference was that I avoided the extra curly braces
> using
> 
> +       else
> +               return !WARN(1, "invalid HE MCS: bw:%d, ru:%d\n",
> +                            rate->bw, rate->he_ru_alloc);
> 
> to avoid the mix of bare if() and if() {}

Right, shouldn't all arms of the if/else if/else conditional have {}
if any arm has {}.

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

end of thread, other threads:[~2019-03-26  9:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-07 23:57 [PATCH] cfg80211: Change an 'else if' into an 'else' in cfg80211_calculate_bitrate_he Nathan Chancellor
2019-03-08  0:10 ` Nick Desaulniers
2019-03-20 19:10 ` Nathan Chancellor
2019-03-22 14:16 ` Arnd Bergmann
2019-03-26  9:36   ` Simon Horman

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.