[3/4] log2: allow use of is_power_of_2() in constant expressions
Commit Message
Even though the static inline functions are __attribute__((const)) you
can't use them in constant expressions. Make is_power_of_2() a constant
expression if possible.
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Christian König <christian.koenig@amd.com>
Cc: David Gow <davidgow@google.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
include/linux/log2.h | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
@@ -56,9 +56,11 @@ bool __is_power_of_2(unsigned long n)
* Return: true if @n is a power of 2, otherwise false.
*/
#define is_power_of_2(n) \
- __builtin_choose_expr(sizeof(n) > sizeof(unsigned long), \
- __is_power_of_2_ull(n), \
- __is_power_of_2(n))
+ __builtin_choose_expr(__is_constexpr(n), \
+ __IS_POWER_OF_2(n), \
+ __builtin_choose_expr(sizeof(n) > sizeof(unsigned long), \
+ __is_power_of_2_ull(n), \
+ __is_power_of_2(n)))
/**
* __roundup_pow_of_two() - round up to nearest power of two