LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] staging: rtl8192u: Remove an unnecessary NULL check
@ 2019-05-21 17:42 Nathan Chancellor
  2019-05-21 22:53 ` Nick Desaulniers
  2019-05-22  7:04 ` Dan Carpenter
  0 siblings, 2 replies; 6+ messages in thread
From: Nathan Chancellor @ 2019-05-21 17:42 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: John Whitmore, devel, linux-kernel, clang-built-linux,
	Nick Desaulniers, Nathan Chancellor

Clang warns:

drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c:2663:47: warning:
address of array 'param->u.wpa_ie.data' will always evaluate to 'true'
[-Wpointer-bool-conversion]
            (param->u.wpa_ie.len && !param->u.wpa_ie.data))
                                    ~~~~~~~~~~~~~~~~~^~~~

This was exposed by commit deabe03523a7 ("Staging: rtl8192u: ieee80211:
Use !x in place of NULL comparisons") because we disable the warning
that would have pointed out the comparison against NULL is also false:

drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c:2663:46: warning:
comparison of array 'param->u.wpa_ie.data' equal to a null pointer is
always false [-Wtautological-pointer-compare]
            (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
                                    ~~~~~~~~~~~~~~~~^~~~    ~~~~

Remove it so clang no longer warns.

Link: https://github.com/ClangBuiltLinux/linux/issues/487
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
 drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
index f38f9d8b78bb..e0da0900a4f7 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
@@ -2659,8 +2659,7 @@ static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device *ieee,
 {
 	u8 *buf;
 
-	if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
-	    (param->u.wpa_ie.len && !param->u.wpa_ie.data))
+	if (param->u.wpa_ie.len > MAX_WPA_IE_LEN)
 		return -EINVAL;
 
 	if (param->u.wpa_ie.len) {
-- 
2.22.0.rc1


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

* Re: [PATCH] staging: rtl8192u: Remove an unnecessary NULL check
  2019-05-21 17:42 [PATCH] staging: rtl8192u: Remove an unnecessary NULL check Nathan Chancellor
@ 2019-05-21 22:53 ` Nick Desaulniers
  2019-05-21 22:57   ` Nick Desaulniers
  2019-05-22  7:04 ` Dan Carpenter
  1 sibling, 1 reply; 6+ messages in thread
From: Nick Desaulniers @ 2019-05-21 22:53 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Greg Kroah-Hartman, John Whitmore, devel, LKML,
	clang-built-linux, rsmith

On Tue, May 21, 2019 at 10:42 AM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> Clang warns:
>
> drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c:2663:47: warning:
> address of array 'param->u.wpa_ie.data' will always evaluate to 'true'
> [-Wpointer-bool-conversion]
>             (param->u.wpa_ie.len && !param->u.wpa_ie.data))
>                                     ~~~~~~~~~~~~~~~~~^~~~
>
> This was exposed by commit deabe03523a7 ("Staging: rtl8192u: ieee80211:
> Use !x in place of NULL comparisons") because we disable the warning
> that would have pointed out the comparison against NULL is also false:
>
> drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c:2663:46: warning:
> comparison of array 'param->u.wpa_ie.data' equal to a null pointer is
> always false [-Wtautological-pointer-compare]
>             (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
>                                     ~~~~~~~~~~~~~~~~^~~~    ~~~~
>
> Remove it so clang no longer warns.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/487
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> ---
>  drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
> index f38f9d8b78bb..e0da0900a4f7 100644
> --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
> +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
> @@ -2659,8 +2659,7 @@ static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device *ieee,
>  {
>         u8 *buf;
>
> -       if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
> -           (param->u.wpa_ie.len && !param->u.wpa_ie.data))

Right so, the types in this expression:

param: struct ieee_param*
param->u: *anonymous union*
param->u.wpa_ie: *anonymous struct*
param->u.wpa_ie.len: u32
param->u.wpa_ie.data: u8 [0]
as defined in drivers/staging/rtl8192u/ieee80211/ieee80211.h#L295
https://github.com/ClangBuiltLinux/linux/blob/9c7db5004280767566e91a33445bf93aa479ef02/drivers/staging/rtl8192u/ieee80211/ieee80211.h#L295-L322

so this is a tricky case, because in general array members can never
themselves be NULL, and usually I trust -Wpointer-bool-conversion, but
this is a special case because of the flexible array member:
https://en.wikipedia.org/wiki/Flexible_array_member. (It seems that
having the 0 in the length explicitly was pre-c99 GNU extension:
https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html). I wonder if
-Wtautological-pointer-compare applies to Flexible Array Members or
not (Richard, do you know)?  In general, you'd be setting
param->u.wpa_ie to the return value of a dynamic memory allocation,
not param->u.wpa_ie.data, so this check is fishy to me.

> +       if (param->u.wpa_ie.len > MAX_WPA_IE_LEN)
>                 return -EINVAL;
>
>         if (param->u.wpa_ie.len) {
> --
> 2.22.0.rc1
>


-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH] staging: rtl8192u: Remove an unnecessary NULL check
  2019-05-21 22:53 ` Nick Desaulniers
@ 2019-05-21 22:57   ` Nick Desaulniers
  2019-05-22  9:24     ` Dan Carpenter
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Desaulniers @ 2019-05-21 22:57 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Greg Kroah-Hartman, John Whitmore, devel, LKML,
	clang-built-linux, Richard Smith

+ Richard for real this time.

On Tue, May 21, 2019 at 3:53 PM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> On Tue, May 21, 2019 at 10:42 AM Nathan Chancellor
> <natechancellor@gmail.com> wrote:
> >
> > Clang warns:
> >
> > drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c:2663:47: warning:
> > address of array 'param->u.wpa_ie.data' will always evaluate to 'true'
> > [-Wpointer-bool-conversion]
> >             (param->u.wpa_ie.len && !param->u.wpa_ie.data))
> >                                     ~~~~~~~~~~~~~~~~~^~~~
> >
> > This was exposed by commit deabe03523a7 ("Staging: rtl8192u: ieee80211:
> > Use !x in place of NULL comparisons") because we disable the warning
> > that would have pointed out the comparison against NULL is also false:
> >
> > drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c:2663:46: warning:
> > comparison of array 'param->u.wpa_ie.data' equal to a null pointer is
> > always false [-Wtautological-pointer-compare]
> >             (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
> >                                     ~~~~~~~~~~~~~~~~^~~~    ~~~~
> >
> > Remove it so clang no longer warns.
> >
> > Link: https://github.com/ClangBuiltLinux/linux/issues/487
> > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> > ---
> >  drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
> > index f38f9d8b78bb..e0da0900a4f7 100644
> > --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
> > +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
> > @@ -2659,8 +2659,7 @@ static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device *ieee,
> >  {
> >         u8 *buf;
> >
> > -       if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
> > -           (param->u.wpa_ie.len && !param->u.wpa_ie.data))
>
> Right so, the types in this expression:
>
> param: struct ieee_param*
> param->u: *anonymous union*
> param->u.wpa_ie: *anonymous struct*
> param->u.wpa_ie.len: u32
> param->u.wpa_ie.data: u8 [0]
> as defined in drivers/staging/rtl8192u/ieee80211/ieee80211.h#L295
> https://github.com/ClangBuiltLinux/linux/blob/9c7db5004280767566e91a33445bf93aa479ef02/drivers/staging/rtl8192u/ieee80211/ieee80211.h#L295-L322
>
> so this is a tricky case, because in general array members can never
> themselves be NULL, and usually I trust -Wpointer-bool-conversion, but
> this is a special case because of the flexible array member:
> https://en.wikipedia.org/wiki/Flexible_array_member. (It seems that
> having the 0 in the length explicitly was pre-c99 GNU extension:
> https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html). I wonder if
> -Wtautological-pointer-compare applies to Flexible Array Members or
> not (Richard, do you know)?  In general, you'd be setting
> param->u.wpa_ie to the return value of a dynamic memory allocation,
> not param->u.wpa_ie.data, so this check is fishy to me.
>
> > +       if (param->u.wpa_ie.len > MAX_WPA_IE_LEN)
> >                 return -EINVAL;
> >
> >         if (param->u.wpa_ie.len) {
> > --
> > 2.22.0.rc1
> >
>
>
> --
> Thanks,
> ~Nick Desaulniers



-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH] staging: rtl8192u: Remove an unnecessary NULL check
  2019-05-21 17:42 [PATCH] staging: rtl8192u: Remove an unnecessary NULL check Nathan Chancellor
  2019-05-21 22:53 ` Nick Desaulniers
@ 2019-05-22  7:04 ` Dan Carpenter
  2019-05-22 20:39   ` Nathan Chancellor
  1 sibling, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2019-05-22  7:04 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Greg Kroah-Hartman, devel, Nick Desaulniers, linux-kernel,
	John Whitmore, clang-built-linux

On Tue, May 21, 2019 at 10:42:21AM -0700, Nathan Chancellor wrote:
> Clang warns:
> 
> drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c:2663:47: warning:
> address of array 'param->u.wpa_ie.data' will always evaluate to 'true'
> [-Wpointer-bool-conversion]
>             (param->u.wpa_ie.len && !param->u.wpa_ie.data))
>                                     ~~~~~~~~~~~~~~~~~^~~~
> 
> This was exposed by commit deabe03523a7 ("Staging: rtl8192u: ieee80211:
> Use !x in place of NULL comparisons") because we disable the warning
> that would have pointed out the comparison against NULL is also false:
> 

Heh.  Weird.  Why would people disable one and not the other?

regards,
dan carpenter


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

* Re: [PATCH] staging: rtl8192u: Remove an unnecessary NULL check
  2019-05-21 22:57   ` Nick Desaulniers
@ 2019-05-22  9:24     ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2019-05-22  9:24 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Nathan Chancellor, devel, Greg Kroah-Hartman, LKML,
	John Whitmore, clang-built-linux, Richard Smith

On Tue, May 21, 2019 at 03:57:46PM -0700, Nick Desaulniers wrote:
> > > -       if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
> > > -           (param->u.wpa_ie.len && !param->u.wpa_ie.data))
> >
> > Right so, the types in this expression:
> >
> > param: struct ieee_param*
> > param->u: *anonymous union*
> > param->u.wpa_ie: *anonymous struct*
> > param->u.wpa_ie.len: u32
> > param->u.wpa_ie.data: u8 [0]
> > as defined in drivers/staging/rtl8192u/ieee80211/ieee80211.h#L295
> > https://github.com/ClangBuiltLinux/linux/blob/9c7db5004280767566e91a33445bf93aa479ef02/drivers/staging/rtl8192u/ieee80211/ieee80211.h#L295-L322
> >
> > so this is a tricky case, because in general array members can never
> > themselves be NULL,


Unless they array was the first struct member, obviously.


> >  and usually I trust -Wpointer-bool-conversion, but
> > this is a special case because of the flexible array member:

Nah.  It's the same thing.  That patch is fine.

regards,
dan carpenter


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

* Re: [PATCH] staging: rtl8192u: Remove an unnecessary NULL check
  2019-05-22  7:04 ` Dan Carpenter
@ 2019-05-22 20:39   ` Nathan Chancellor
  0 siblings, 0 replies; 6+ messages in thread
From: Nathan Chancellor @ 2019-05-22 20:39 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Greg Kroah-Hartman, devel, Nick Desaulniers, linux-kernel,
	John Whitmore, clang-built-linux

On Wed, May 22, 2019 at 10:04:18AM +0300, Dan Carpenter wrote:
> On Tue, May 21, 2019 at 10:42:21AM -0700, Nathan Chancellor wrote:
> > Clang warns:
> > 
> > drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c:2663:47: warning:
> > address of array 'param->u.wpa_ie.data' will always evaluate to 'true'
> > [-Wpointer-bool-conversion]
> >             (param->u.wpa_ie.len && !param->u.wpa_ie.data))
> >                                     ~~~~~~~~~~~~~~~~~^~~~
> > 
> > This was exposed by commit deabe03523a7 ("Staging: rtl8192u: ieee80211:
> > Use !x in place of NULL comparisons") because we disable the warning
> > that would have pointed out the comparison against NULL is also false:
> > 
> 
> Heh.  Weird.  Why would people disable one and not the other?
> 
> regards,
> dan carpenter
> 

-Wtautological-compare has a lot of different sub-warnings under it,
one of which is the one shown. -Wno-tautological-compare turns off all
of those other sub-warnings. The reason that was done is there are quite
a few of them:

https://gist.github.com/nathanchance/3336adc6e796b57eadd53b106b96c569

https://clang.llvm.org/docs/DiagnosticsReference.html#wtautological-compare

It is probably worth looking into turning that on, I'm going to try to
do that as I have time.

Cheers,
Nathan

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

end of thread, other threads:[~2019-05-22 20:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-21 17:42 [PATCH] staging: rtl8192u: Remove an unnecessary NULL check Nathan Chancellor
2019-05-21 22:53 ` Nick Desaulniers
2019-05-21 22:57   ` Nick Desaulniers
2019-05-22  9:24     ` Dan Carpenter
2019-05-22  7:04 ` Dan Carpenter
2019-05-22 20:39   ` Nathan Chancellor

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