mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 10/13] bitops: fix missing defintion for DIV_ROUND_UP definitions
Date: Mon, 14 Oct 2024 13:39:09 +0200	[thread overview]
Message-ID: <20241014113912.2826190-11-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20241014113912.2826190-1-a.fatoum@pengutronix.de>

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@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




  parent reply	other threads:[~2024-10-14 13:33 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-14 11:38 [PATCH master 00/13] Misc compile test fixes Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 01/13] clk: add stub definition for of_clk_get_from_provider Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 02/13] tee: add missing header for BIT macro definition Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 03/13] tee: shm: include missing header for basprintf Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 04/13] net: dsa: realtek: fix CONFIG_SANDBOX build Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 05/13] pmdomain: imx8mp-blk-ctrl: add missing definition of ARRAY_SIZE Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 06/13] PWM: rockchip: fix compile testing with CONFIG_SANDBOX Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 07/13] watchdog: imxulp: drop unused include of asm/system.h Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 08/13] include: import uapi/linux/kernel.h header from Linux Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 09/13] usb: typec: fix compile test with CONFIG_SANDBOX Ahmad Fatoum
2024-10-14 11:39 ` Ahmad Fatoum [this message]
2024-10-14 11:39 ` [PATCH master 11/13] mci: am654-sdhci: drop dummy redefinition of MMC_CAP2_HS200/400 Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 12/13] hw_random: fix compilation with 64-bit size_t Ahmad Fatoum
2024-10-14 11:39 ` [PATCH master 13/13] optee: make OP-TEE OF fixup ARM-specific Ahmad Fatoum
2024-10-15  6:59 ` [PATCH master 00/13] Misc compile test fixes Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241014113912.2826190-11-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox