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]
Message-ID: <3be064fe804845e4aeaca8b1d45ddf0a@AcuMS.aculab.com>
Date:   Tue, 10 May 2022 17:54:13 +0000
From:   David Laight <David.Laight@...LAB.COM>
To:     'Alexei Starovoitov' <alexei.starovoitov@...il.com>,
        Yury Norov <yury.norov@...il.com>
CC:     Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Joe Perches <joe@...ches.com>,
        Julia Lawall <Julia.Lawall@...ia.fr>,
        Michał Mirosław <mirq-linux@...e.qmqm.pl>,
        Nicholas Piggin <npiggin@...il.com>,
        Nicolas Palix <nicolas.palix@...g.fr>,
        Peter Zijlstra <peterz@...radead.org>,
        "Rasmus Villemoes" <linux@...musvillemoes.dk>,
        Matti Vaittinen <Matti.Vaittinen@...rohmeurope.com>,
        LKML <linux-kernel@...r.kernel.org>,
        Alexei Starovoitov <ast@...nel.org>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Chris Zankel <chris@...kel.net>,
        "Christophe Leroy" <christophe.leroy@...roup.eu>,
        "Eric W . Biederman" <ebiederm@...ssion.com>,
        Kumar Kartikeya Dwivedi <memxor@...il.com>,
        "Max Filippov" <jcmvbkbc@...il.com>,
        Toke Høiland-Jørgensen <toke@...hat.com>,
        "linux-xtensa@...ux-xtensa.org" <linux-xtensa@...ux-xtensa.org>
Subject: RE: [PATCH 08/22] bitops: introduce MANY_BITS() macro

From: Alexei Starovoitov
> Sent: 10 May 2022 17:51
...
> +/* Return: nonzero if 2 or more bits are set */
> +#define MANY_BITS(n)           ((n) & ((n) - 1))

You can't have a macro that expands its argument twice.

...
> >  static inline __attribute__((const))
> >  bool is_power_of_2(unsigned long n)
> >  {
> > -       return (n != 0 && ((n & (n - 1)) == 0));
> > +       return n != 0 && !MANY_BITS(n);
> >  }
> 
> Please don't. Open coded version is much easier to read.

Especially if you remove all the spare parenthesis.
	return n && !(n & (n - 1));

I bet a lot of callers know the value is non-zero.

I suspect you'll find at least one caller that uses
is_power_of_2() assuming it is !(n & (n - 1)) and
so is wrong for zero.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ