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>
ipnum = (s->ipmap >> (irq / 32 * 8)) & 0xff;
if (!(s->status & BIT(EIOINTC_ENABLE_INT_ENCODE))) {
ipnum = count_trailing_zeros(ipnum);
- ipnum = (ipnum >= 0 && ipnum < 4) ? ipnum : 0;
+ ipnum = ipnum < 4 ? ipnum : 0;
}
cpuid = ((u8 *)s->coremap)[irq];
ipnum = (s->ipmap >> (irq / 32 * 8)) & 0xff;
if (!(s->status & BIT(EIOINTC_ENABLE_INT_ENCODE))) {
ipnum = count_trailing_zeros(ipnum);
- ipnum = (ipnum >= 0 && ipnum < 4) ? ipnum : 0;
+ ipnum = ipnum < 4 ? ipnum : 0;
}
cpu = s->sw_coremap[irq];
#include <asm/bitops.h>
-#define COUNT_TRAILING_ZEROS_0 (-1)
-
/**
* count_leading_zeros - Count the number of zeros from the MSB back
* @x: The value
*
* If the LSB of @x is set, the result is 0.
* If only the MSB of @x is set, then the result is BITS_PER_LONG-1.
- * If @x is 0 then the result is COUNT_TRAILING_ZEROS_0.
+ * If @x is 0 then the result is BITS_PER_LONG.
*/
static inline int count_trailing_zeros(unsigned long x)
{
- return (x != 0) ? __ffs(x) : COUNT_TRAILING_ZEROS_0;
+ return x ? __ffs(x) : BITS_PER_LONG;
}
#endif /* _LINUX_BITOPS_COUNT_ZEROS_H_ */