Re: [PATCH v2 18/20] linux/power_of_2.h: Add __IS_POWER_OF_2(n) and __IS_POWER_OF_2_OR_0(n) macros

From: Arnd Bergmann
Date: Sun Nov 21 2021 - 08:21:19 EST


On Sat, Nov 20, 2021 at 2:01 PM Alejandro Colomar
<alx.manpages@xxxxxxxxx> wrote:
> +
> +#define __IS_POWER_OF_2_OR_0(n) (((n) & ((n) - 1)) == 0)
> +#define __IS_POWER_OF_2(n) (__IS_POWER_OF_2_OR_0(n) && ((n) != 0))
> +

There is already is_power_of_2() in include/linux/log2.h, which would
be preferred
in most cases. If you need a macro version, put it in the same file
and explain why it's
needed.

Arnd