lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sat, 16 Oct 2021 10:04:55 +0300
From:   Dan Carpenter <dan.carpenter@...cle.com>
To:     Nathan Chancellor <nathan@...nel.org>
Cc:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        linux-staging@...ts.linux.dev, linux-kernel@...r.kernel.org,
        llvm@...ts.linux.dev
Subject: Re: [PATCH] staging: wlan-ng: Avoid bitwise vs logical OR warning in
 hfa384x_usb_throttlefn()

On Fri, Oct 15, 2021 at 10:13:05AM -0700, Nathan Chancellor wrote:
> On Fri, Oct 15, 2021 at 12:43:44PM +0300, Dan Carpenter wrote:
> > On Thu, Oct 14, 2021 at 02:57:03PM -0700, Nathan Chancellor wrote:
> > > A new warning in clang points out a place in this file where a bitwise
> > > OR is being used with boolean expressions:
> > > 
> > > In file included from drivers/staging/wlan-ng/prism2usb.c:2:
> > > drivers/staging/wlan-ng/hfa384x_usb.c:3787:7: warning: use of bitwise '|' with boolean operands [-Wbitwise-instead-of-logical]
> > >             ((test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) &&
> > >             ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > > drivers/staging/wlan-ng/hfa384x_usb.c:3787:7: note: cast one or both operands to int to silence this warning
> > > 1 warning generated.
> > 
> > Both sides of this bitwise OR are bool, so | and || are equivalent
> > logically.  Clang should not warn about it.
> 
> I do not disagree. The original motivation for the warning was code like
> 
> if (a() & b())
> 
> where a '&&' was intended to short circuit the call to b() if a() was
> false but then it expanded to encompass bitwise OR as well. The clang
> developers felt that warning on bitwise OR was worthwhile because most
> of the time, '||' was intended. Feel free to comment on the Phabricator
> thread if you feel strongly, there are not too many instances of this
> warning and I think the '&' vs '&&' aspect of the warning is useful.

Of course, this was a Smatch check early on.  Bool is almost all style
debates and false positives.  I didn't see a lot of short circuiting
bugs in the kernel.

But I'm not going to tell people how to live their lifes if they want to
spend it debating coding style.  (Unless it's GCC's brain dead unsigned
comparison warnings where it tells everyone to make their iterators
unsigned int and leads to a lot bugs and ugly code).

regards,
dan carpenter

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ