Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lib: count_zeros: unify count_{leading,trailing}_zeros()

The 'leading' helper returns BITS_PER_LONG if x == 0, while 'trailing'
one returns COUNT_TRAILING_ZEROS_0, which turns to be -1.

None of the current users explicitly check the returned value for
COUNT_TRAILING_ZEROS_0, except the loongarch, which tests implicitly
for the '>= 0'.

So, align count_trailing_zeros() with the count_leading_zeros(), and
simplify the loongarch handling.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Yury Norov <ynorov@nvidia.com>

+4 -6
+2 -2
arch/loongarch/kvm/intc/eiointc.c
··· 16 16 ipnum = (s->ipmap >> (irq / 32 * 8)) & 0xff; 17 17 if (!(s->status & BIT(EIOINTC_ENABLE_INT_ENCODE))) { 18 18 ipnum = count_trailing_zeros(ipnum); 19 - ipnum = (ipnum >= 0 && ipnum < 4) ? ipnum : 0; 19 + ipnum = ipnum < 4 ? ipnum : 0; 20 20 } 21 21 22 22 cpuid = ((u8 *)s->coremap)[irq]; ··· 41 41 ipnum = (s->ipmap >> (irq / 32 * 8)) & 0xff; 42 42 if (!(s->status & BIT(EIOINTC_ENABLE_INT_ENCODE))) { 43 43 ipnum = count_trailing_zeros(ipnum); 44 - ipnum = (ipnum >= 0 && ipnum < 4) ? ipnum : 0; 44 + ipnum = ipnum < 4 ? ipnum : 0; 45 45 } 46 46 47 47 cpu = s->sw_coremap[irq];
+2 -4
include/linux/count_zeros.h
··· 10 10 11 11 #include <asm/bitops.h> 12 12 13 - #define COUNT_TRAILING_ZEROS_0 (-1) 14 - 15 13 /** 16 14 * count_leading_zeros - Count the number of zeros from the MSB back 17 15 * @x: The value ··· 36 38 * 37 39 * If the LSB of @x is set, the result is 0. 38 40 * If only the MSB of @x is set, then the result is BITS_PER_LONG-1. 39 - * If @x is 0 then the result is COUNT_TRAILING_ZEROS_0. 41 + * If @x is 0 then the result is BITS_PER_LONG. 40 42 */ 41 43 static inline int count_trailing_zeros(unsigned long x) 42 44 { 43 - return (x != 0) ? __ffs(x) : COUNT_TRAILING_ZEROS_0; 45 + return x ? __ffs(x) : BITS_PER_LONG; 44 46 } 45 47 46 48 #endif /* _LINUX_BITOPS_COUNT_ZEROS_H_ */