[PATCH master 10/13] bitops: fix missing defintion for DIV_ROUND_UP definitions

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Oct 14 04:39:09 PDT 2024


Macros like BITS_TO_LONGS defined in <linux/bitops.h> expand to
DIV_ROUND_UP, which isn't defined in the same file.

We can't easily include <linux/math.h> however as this leads to a
recursive file inclusion:

In file included from ./include/asm-generic/div64.h:53,
                 from ./include/linux/math64.h:7,
                 from ./include/linux/math.h:6,
                 from ./include/linux/bitops.h:9,
                 from ./include/clock.h:7,
                 from ./include/console.h:15,
                 from ./include/stdio.h:6,
                 from ./include/common.h:10,
                 from ./common/partitions/dos.c:15:
 ./include/linux/log2.h: In function '__ilog2_u32':
 ./include/linux/log2.h:28:16: error: implicit declaration of function 'fls'
		[-Wimplicit-function-declaration]
    28 |         return fls(n) - 1;

Fix this by doing it like Linux does and use the UAPI
__KERNEL_DIV_ROUND_UP definition instead.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 include/linux/bitops.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 7646e1563478..44602ad5af84 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -7,12 +7,14 @@
 #include <linux/const.h>
 #include <linux/bits.h>
 
+#include <uapi/linux/kernel.h>
+
 #ifdef	__KERNEL__
 #define BITS_PER_TYPE(type)	(sizeof(type) * BITS_PER_BYTE)
-#define BITS_TO_LONGS(nr)	DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
-#define BITS_TO_U64(nr)		DIV_ROUND_UP(nr, BITS_PER_TYPE(u64))
-#define BITS_TO_U32(nr)		DIV_ROUND_UP(nr, BITS_PER_TYPE(u32))
-#define BITS_TO_BYTES(nr)	DIV_ROUND_UP(nr, BITS_PER_TYPE(char))
+#define BITS_TO_LONGS(nr)	__KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
+#define BITS_TO_U64(nr)		__KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u64))
+#define BITS_TO_U32(nr)		__KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u32))
+#define BITS_TO_BYTES(nr)	__KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(char))
 #define BYTES_TO_BITS(nb)	(((BITS_PER_LONG * (nb)) / sizeof(long)))
 #endif
 
-- 
2.39.5




More information about the barebox mailing list