arm/arm64: bitops: fix find_next_zero_bit to be compat with arm64

Current implementation of find_next_zero_bit() is incompatible with arm64.
Hence fix it by using BITS_PER_LONG define instead of constants and
use generic ffz() implementation.

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
This commit is contained in:
Grygorii Strashko 2018-06-28 14:25:52 -05:00 committed by Tom Rini
parent c95848cdec
commit 960a63973b

View file

@ -15,6 +15,8 @@
#ifndef __ASM_ARM_BITOPS_H #ifndef __ASM_ARM_BITOPS_H
#define __ASM_ARM_BITOPS_H #define __ASM_ARM_BITOPS_H
#include <asm-generic/bitops/__ffs.h>
#ifdef __KERNEL__ #ifdef __KERNEL__
#include <asm/proc-armv/system.h> #include <asm/proc-armv/system.h>
@ -108,50 +110,34 @@ static inline int __ilog2(unsigned int x)
return generic_fls(x) - 1; return generic_fls(x) - 1;
} }
/* #define ffz(x) __ffs(~(x))
* ffz = Find First Zero in word. Undefined if no zero exists,
* so code should check against ~0UL first..
*/
static inline unsigned long ffz(unsigned long word)
{
int k;
word = ~word;
k = 31;
if (word & 0x0000ffff) { k -= 16; word <<= 16; }
if (word & 0x00ff0000) { k -= 8; word <<= 8; }
if (word & 0x0f000000) { k -= 4; word <<= 4; }
if (word & 0x30000000) { k -= 2; word <<= 2; }
if (word & 0x40000000) { k -= 1; }
return k;
}
static inline int find_next_zero_bit(void *addr, int size, int offset) static inline int find_next_zero_bit(void *addr, int size, int offset)
{ {
unsigned long *p = ((unsigned long *)addr) + (offset >> 5); unsigned long *p = ((unsigned long *)addr) + (offset / BITS_PER_LONG);
unsigned long result = offset & ~31UL; unsigned long result = offset & ~(BITS_PER_LONG - 1);
unsigned long tmp; unsigned long tmp;
if (offset >= size) if (offset >= size)
return size; return size;
size -= result; size -= result;
offset &= 31UL; offset &= (BITS_PER_LONG - 1);
if (offset) { if (offset) {
tmp = *(p++); tmp = *(p++);
tmp |= ~0UL >> (32-offset); tmp |= ~0UL >> (BITS_PER_LONG - offset);
if (size < 32) if (size < BITS_PER_LONG)
goto found_first; goto found_first;
if (~tmp) if (~tmp)
goto found_middle; goto found_middle;
size -= 32; size -= BITS_PER_LONG;
result += 32; result += BITS_PER_LONG;
} }
while (size & ~31UL) { while (size & ~(BITS_PER_LONG - 1)) {
tmp = *(p++); tmp = *(p++);
if (~tmp) if (~tmp)
goto found_middle; goto found_middle;
result += 32; result += BITS_PER_LONG;
size -= 32; size -= BITS_PER_LONG;
} }
if (!size) if (!size)
return result; return result;
@ -191,7 +177,6 @@ found_middle:
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
#include <asm-generic/bitops/__fls.h> #include <asm-generic/bitops/__fls.h>
#include <asm-generic/bitops/__ffs.h>
#include <asm-generic/bitops/fls.h> #include <asm-generic/bitops/fls.h>
#include <asm-generic/bitops/fls64.h> #include <asm-generic/bitops/fls64.h>