* [PATCH 0/8] include: list: remove dependency on linux/kernel.h
@ 2024-07-16 11:58 Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 1/8] regmap-mmio: don't call kfree on non kmalloc allocated buffers Ahmad Fatoum
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2024-07-16 11:58 UTC (permalink / raw)
To: barebox
<linux/kernel.h> defines a lot of things that go beyond what's needed for
<linux/list.h>. The only thing actually needed for the list
implementation is <linux/container_of.h>, so we should just include that
directly.
This is also what Linux has been doing for a while, but it breaks the
build of a number of source files, which are addressed in this series.
Ahmad Fatoum (8):
regmap-mmio: don't call kfree on non kmalloc allocated buffers
treewide: fix dependency on indirectly included linux/kernel.h
stringlist: make header self-contained
module: retire MODULE_SYMBOL_PREFIX
include: move MODULE_* macro definitions into own header
include: asm-generic/bug: break recursive dependency
include: linux/kernel.h: split off into multiple headers
include: list: replace full kernel.h inclusion with smaller
container_of.h
arch/arm/lib32/io.c | 1 +
arch/mips/include/asm/dma.h | 1 +
commands/bthread.c | 1 +
commands/mmc.c | 1 +
common/module.c | 4 +-
drivers/base/regmap/regmap-mmio.c | 5 +-
drivers/clk/at91/at91sam9260.c | 1 +
drivers/clk/at91/at91sam9g45.c | 1 +
drivers/clk/at91/at91sam9n12.c | 1 +
drivers/clk/at91/at91sam9rl.c | 1 +
drivers/clk/at91/at91sam9x5.c | 1 +
drivers/clk/at91/clk-audio-pll.c | 1 +
drivers/clk/at91/clk-generated.c | 1 +
drivers/clk/at91/clk-master.c | 1 +
drivers/clk/at91/clk-pll.c | 1 +
drivers/clk/at91/clk-usb.c | 1 +
drivers/clk/at91/sama5d2.c | 1 +
drivers/clk/at91/sama5d3.c | 1 +
drivers/clk/at91/sama5d4.c | 1 +
drivers/clk/rockchip/rst-rk3588.c | 1 +
drivers/soc/sifive/sifive_l2_cache.c | 2 +
drivers/usb/misc/onboard_usb_hub.c | 1 +
include/asm-generic/bug.h | 1 -
include/driver.h | 1 +
include/linux/array_size.h | 14 ++
include/linux/barebox-wrapper.h | 12 +-
include/linux/export.h | 4 +-
include/linux/hex.h | 34 ++++
include/linux/kernel.h | 234 +--------------------------
include/linux/kstrtox.h | 123 ++++++++++++++
include/linux/list.h | 2 +-
include/linux/math.h | 83 ++++++++++
include/linux/module.h | 17 ++
include/linux/mtd/nand.h | 1 +
include/linux/wordpart.h | 49 ++++++
include/mach/mvebu/debug_ll.h | 1 +
include/module.h | 5 +-
include/stringlist.h | 1 +
lib/idr.c | 2 +
39 files changed, 361 insertions(+), 253 deletions(-)
create mode 100644 include/linux/array_size.h
create mode 100644 include/linux/hex.h
create mode 100644 include/linux/kstrtox.h
create mode 100644 include/linux/math.h
create mode 100644 include/linux/module.h
create mode 100644 include/linux/wordpart.h
--
2.39.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/8] regmap-mmio: don't call kfree on non kmalloc allocated buffers
2024-07-16 11:58 [PATCH 0/8] include: list: remove dependency on linux/kernel.h Ahmad Fatoum
@ 2024-07-16 11:58 ` Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 2/8] treewide: fix dependency on indirectly included linux/kernel.h Ahmad Fatoum
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2024-07-16 11:58 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
If we don't use kmalloc() or friends, we shouldn't use kfree() to free
the buffer either.
Currently, kfree and free are identical, but they are defined in
different headers.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/base/regmap/regmap-mmio.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/base/regmap/regmap-mmio.c b/drivers/base/regmap/regmap-mmio.c
index 01b0a9963110..9d2ab9cb8dc7 100644
--- a/drivers/base/regmap/regmap-mmio.c
+++ b/drivers/base/regmap/regmap-mmio.c
@@ -7,6 +7,7 @@
#include <linux/clk.h>
#include <linux/err.h>
#include <io.h>
+#include <malloc.h>
#include <linux/regmap.h>
#include "internal.h"
@@ -272,7 +273,7 @@ static struct regmap_mmio_context *regmap_mmio_gen_context(struct device *dev,
return ctx;
err_free:
- kfree(ctx);
+ free(ctx);
return ERR_PTR(ret);
}
@@ -293,7 +294,7 @@ struct regmap *regmap_init_mmio_clk(struct device *dev,
clk = clk_get(dev, clk_id);
if (IS_ERR(clk)) {
- kfree(ctx);
+ free(ctx);
return ERR_CAST(clk);
}
--
2.39.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/8] treewide: fix dependency on indirectly included linux/kernel.h
2024-07-16 11:58 [PATCH 0/8] include: list: remove dependency on linux/kernel.h Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 1/8] regmap-mmio: don't call kfree on non kmalloc allocated buffers Ahmad Fatoum
@ 2024-07-16 11:58 ` Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 3/8] stringlist: make header self-contained Ahmad Fatoum
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2024-07-16 11:58 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We currently include <linux/kernel.h> in <linux/list.h>, which pulls in
definitions that many source files depend on.
Include <linux/kernel.h> directly or other more specific files if
available in preparation for removing the <linux/kernel.h> include from
<linux/list.h>.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/lib32/io.c | 1 +
arch/mips/include/asm/dma.h | 1 +
commands/bthread.c | 1 +
commands/mmc.c | 1 +
drivers/clk/at91/at91sam9260.c | 1 +
drivers/clk/at91/at91sam9g45.c | 1 +
drivers/clk/at91/at91sam9n12.c | 1 +
drivers/clk/at91/at91sam9rl.c | 1 +
drivers/clk/at91/at91sam9x5.c | 1 +
drivers/clk/at91/clk-audio-pll.c | 1 +
drivers/clk/at91/clk-generated.c | 1 +
drivers/clk/at91/clk-master.c | 1 +
drivers/clk/at91/clk-pll.c | 1 +
drivers/clk/at91/clk-usb.c | 1 +
drivers/clk/at91/sama5d2.c | 1 +
drivers/clk/at91/sama5d3.c | 1 +
drivers/clk/at91/sama5d4.c | 1 +
drivers/clk/rockchip/rst-rk3588.c | 1 +
drivers/soc/sifive/sifive_l2_cache.c | 2 ++
drivers/usb/misc/onboard_usb_hub.c | 1 +
include/linux/mtd/nand.h | 1 +
include/mach/mvebu/debug_ll.h | 1 +
lib/idr.c | 2 ++
23 files changed, 25 insertions(+)
diff --git a/arch/arm/lib32/io.c b/arch/arm/lib32/io.c
index 780b1083a641..9e3acfe02246 100644
--- a/arch/arm/lib32/io.c
+++ b/arch/arm/lib32/io.c
@@ -3,6 +3,7 @@
#include <module.h>
#include <linux/types.h>
#include <asm/unaligned.h>
+#include <linux/align.h>
#include <io.h>
/*
diff --git a/arch/mips/include/asm/dma.h b/arch/mips/include/asm/dma.h
index dbcbfa40768d..46fae14ae5aa 100644
--- a/arch/mips/include/asm/dma.h
+++ b/arch/mips/include/asm/dma.h
@@ -8,6 +8,7 @@
#include <linux/pagemap.h>
#include <linux/types.h>
+#include <linux/minmax.h>
#include <malloc.h>
#include <xfuncs.h>
#include <asm/addrspace.h>
diff --git a/commands/bthread.c b/commands/bthread.c
index aaade46e9206..00ff1837cc69 100644
--- a/commands/bthread.c
+++ b/commands/bthread.c
@@ -11,6 +11,7 @@
#include <getopt.h>
#include <clock.h>
#include <slice.h>
+#include <linux/kernel.h>
static int bthread_time(void)
{
diff --git a/commands/mmc.c b/commands/mmc.c
index 041a721d3661..718558f18ba7 100644
--- a/commands/mmc.c
+++ b/commands/mmc.c
@@ -5,6 +5,7 @@
#include <stdio.h>
#include <string.h>
#include <getopt.h>
+#include <linux/kernel.h>
#include <dma.h>
static int mmc_enh_area_setmax(struct mci *mci, u8 *ext_csd)
diff --git a/drivers/clk/at91/at91sam9260.c b/drivers/clk/at91/at91sam9260.c
index c94cd9556616..b590dc629855 100644
--- a/drivers/clk/at91/at91sam9260.c
+++ b/drivers/clk/at91/at91sam9260.c
@@ -2,6 +2,7 @@
#include <linux/clk-provider.h>
#include <mfd/syscon.h>
#include <linux/slab.h>
+#include <linux/kernel.h>
#include <stdio.h>
#include <dt-bindings/clock/at91.h>
diff --git a/drivers/clk/at91/at91sam9g45.c b/drivers/clk/at91/at91sam9g45.c
index fedf96139348..3d2197c7f288 100644
--- a/drivers/clk/at91/at91sam9g45.c
+++ b/drivers/clk/at91/at91sam9g45.c
@@ -2,6 +2,7 @@
#include <linux/clk-provider.h>
#include <mfd/syscon.h>
#include <linux/slab.h>
+#include <linux/kernel.h>
#include <stdio.h>
#include <dt-bindings/clock/at91.h>
diff --git a/drivers/clk/at91/at91sam9n12.c b/drivers/clk/at91/at91sam9n12.c
index bb075de9fde6..3899242a33de 100644
--- a/drivers/clk/at91/at91sam9n12.c
+++ b/drivers/clk/at91/at91sam9n12.c
@@ -2,6 +2,7 @@
#include <linux/clk-provider.h>
#include <mfd/syscon.h>
#include <linux/slab.h>
+#include <linux/kernel.h>
#include <stdio.h>
#include <dt-bindings/clock/at91.h>
diff --git a/drivers/clk/at91/at91sam9rl.c b/drivers/clk/at91/at91sam9rl.c
index 95b02d86d596..a671c6be541e 100644
--- a/drivers/clk/at91/at91sam9rl.c
+++ b/drivers/clk/at91/at91sam9rl.c
@@ -2,6 +2,7 @@
#include <linux/clk-provider.h>
#include <mfd/syscon.h>
#include <linux/slab.h>
+#include <linux/kernel.h>
#include <stdio.h>
#include <dt-bindings/clock/at91.h>
diff --git a/drivers/clk/at91/at91sam9x5.c b/drivers/clk/at91/at91sam9x5.c
index f4dc7ceeea9f..e351848bf7a7 100644
--- a/drivers/clk/at91/at91sam9x5.c
+++ b/drivers/clk/at91/at91sam9x5.c
@@ -2,6 +2,7 @@
#include <linux/clk-provider.h>
#include <mfd/syscon.h>
#include <linux/slab.h>
+#include <linux/kernel.h>
#include <stdio.h>
#include <dt-bindings/clock/at91.h>
diff --git a/drivers/clk/at91/clk-audio-pll.c b/drivers/clk/at91/clk-audio-pll.c
index 71976567ea7f..019d68b7b7e7 100644
--- a/drivers/clk/at91/clk-audio-pll.c
+++ b/drivers/clk/at91/clk-audio-pll.c
@@ -38,6 +38,7 @@
#include <mfd/syscon.h>
#include <linux/regmap.h>
#include <linux/slab.h>
+#include <linux/kernel.h>
#include "pmc.h"
diff --git a/drivers/clk/at91/clk-generated.c b/drivers/clk/at91/clk-generated.c
index e59cff2bdf9f..807c8179c0f1 100644
--- a/drivers/clk/at91/clk-generated.c
+++ b/drivers/clk/at91/clk-generated.c
@@ -14,6 +14,7 @@
#include <of.h>
#include <mfd/syscon.h>
#include <linux/regmap.h>
+#include <linux/kernel.h>
#include "pmc.h"
diff --git a/drivers/clk/at91/clk-master.c b/drivers/clk/at91/clk-master.c
index db5e235b6b8f..ed358257dcb6 100644
--- a/drivers/clk/at91/clk-master.c
+++ b/drivers/clk/at91/clk-master.c
@@ -11,6 +11,7 @@
#include <mfd/syscon.h>
#include <linux/regmap.h>
#include <linux/printk.h>
+#include <linux/kernel.h>
#include "pmc.h"
diff --git a/drivers/clk/at91/clk-pll.c b/drivers/clk/at91/clk-pll.c
index 027e1fc77349..917b2224fe19 100644
--- a/drivers/clk/at91/clk-pll.c
+++ b/drivers/clk/at91/clk-pll.c
@@ -9,6 +9,7 @@
#include <of.h>
#include <mfd/syscon.h>
#include <linux/regmap.h>
+#include <linux/kernel.h>
#include "pmc.h"
diff --git a/drivers/clk/at91/clk-usb.c b/drivers/clk/at91/clk-usb.c
index 4473dc7c3491..96a35b5cb09e 100644
--- a/drivers/clk/at91/clk-usb.c
+++ b/drivers/clk/at91/clk-usb.c
@@ -9,6 +9,7 @@
#include <of.h>
#include <mfd/syscon.h>
#include <linux/regmap.h>
+#include <linux/kernel.h>
#include "pmc.h"
diff --git a/drivers/clk/at91/sama5d2.c b/drivers/clk/at91/sama5d2.c
index 96c0d1f6a46d..cb4e1b78a5e3 100644
--- a/drivers/clk/at91/sama5d2.c
+++ b/drivers/clk/at91/sama5d2.c
@@ -2,6 +2,7 @@
#include <linux/clk-provider.h>
#include <mfd/syscon.h>
#include <linux/slab.h>
+#include <linux/kernel.h>
#include <stdio.h>
#include <dt-bindings/clock/at91.h>
diff --git a/drivers/clk/at91/sama5d3.c b/drivers/clk/at91/sama5d3.c
index 53a1a7413a02..4212afb21827 100644
--- a/drivers/clk/at91/sama5d3.c
+++ b/drivers/clk/at91/sama5d3.c
@@ -2,6 +2,7 @@
#include <linux/clk-provider.h>
#include <mfd/syscon.h>
#include <linux/slab.h>
+#include <linux/kernel.h>
#include <stdio.h>
#include <dt-bindings/clock/at91.h>
diff --git a/drivers/clk/at91/sama5d4.c b/drivers/clk/at91/sama5d4.c
index 8fbd81088349..bd02bdc915f5 100644
--- a/drivers/clk/at91/sama5d4.c
+++ b/drivers/clk/at91/sama5d4.c
@@ -2,6 +2,7 @@
#include <linux/clk-provider.h>
#include <mfd/syscon.h>
#include <linux/slab.h>
+#include <linux/kernel.h>
#include <stdio.h>
#include <dt-bindings/clock/at91.h>
diff --git a/drivers/clk/rockchip/rst-rk3588.c b/drivers/clk/rockchip/rst-rk3588.c
index 7501b92b45f7..fdc83cefc7ad 100644
--- a/drivers/clk/rockchip/rst-rk3588.c
+++ b/drivers/clk/rockchip/rst-rk3588.c
@@ -6,6 +6,7 @@
*/
#include <dt-bindings/reset/rockchip,rk3588-cru.h>
+#include <linux/array_size.h>
#include "clk.h"
/* 0xFD7C0000 + 0x0A00 */
diff --git a/drivers/soc/sifive/sifive_l2_cache.c b/drivers/soc/sifive/sifive_l2_cache.c
index c404143974fc..239e65292ae2 100644
--- a/drivers/soc/sifive/sifive_l2_cache.c
+++ b/drivers/soc/sifive/sifive_l2_cache.c
@@ -16,7 +16,9 @@
#include <init.h>
#include <soc/sifive/l2_cache.h>
#include <asm/barrier.h>
+#include <linux/align.h>
#include <linux/bitops.h>
+#include <linux/bug.h>
#define SIFIVE_L2_DIRECCFIX_LOW 0x100
#define SIFIVE_L2_DIRECCFIX_HIGH 0x104
diff --git a/drivers/usb/misc/onboard_usb_hub.c b/drivers/usb/misc/onboard_usb_hub.c
index 9e94caaa8456..603fd693a137 100644
--- a/drivers/usb/misc/onboard_usb_hub.c
+++ b/drivers/usb/misc/onboard_usb_hub.c
@@ -12,6 +12,7 @@
#include <linux/printk.h>
#include <of_device.h>
#include <regulator.h>
+#include <xfuncs.h>
#include <linux/usb/usb.h>
#include "onboard_usb_hub.h"
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index ef2546490d65..fda55df59a26 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -11,6 +11,7 @@
#define __LINUX_MTD_NAND_H
#include <linux/mtd/mtd.h>
+#include <linux/minmax.h>
struct nand_device;
diff --git a/include/mach/mvebu/debug_ll.h b/include/mach/mvebu/debug_ll.h
index 9197cd68eb99..cf08776d4fcc 100644
--- a/include/mach/mvebu/debug_ll.h
+++ b/include/mach/mvebu/debug_ll.h
@@ -5,6 +5,7 @@
#define __MACH_MVEBU_DEBUG_LL_H__
#include <io.h>
+#include <linux/bits.h>
#define UART_BASE 0xf1012000
#define UARTn_BASE(n) (UART_BASE + ((n) * 0x100))
diff --git a/lib/idr.c b/lib/idr.c
index 10a714ac03f0..a25e46b17b95 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -6,6 +6,8 @@
#include <errno.h>
#include <linux/idr.h>
+#include <malloc.h>
+#include <linux/minmax.h>
struct idr *__idr_find(struct idr *head, int lookup_id)
{
--
2.39.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 3/8] stringlist: make header self-contained
2024-07-16 11:58 [PATCH 0/8] include: list: remove dependency on linux/kernel.h Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 1/8] regmap-mmio: don't call kfree on non kmalloc allocated buffers Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 2/8] treewide: fix dependency on indirectly included linux/kernel.h Ahmad Fatoum
@ 2024-07-16 11:58 ` Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 4/8] module: retire MODULE_SYMBOL_PREFIX Ahmad Fatoum
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2024-07-16 11:58 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The header has static inline functions that reference free(), so include
<malloc.h> which defines its prototype.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/stringlist.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/stringlist.h b/include/stringlist.h
index 01491082ea02..60b96ecb8319 100644
--- a/include/stringlist.h
+++ b/include/stringlist.h
@@ -3,6 +3,7 @@
#define __STRINGLIST_H
#include <linux/list.h>
+#include <malloc.h>
struct string_list {
struct list_head list;
--
2.39.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 4/8] module: retire MODULE_SYMBOL_PREFIX
2024-07-16 11:58 [PATCH 0/8] include: list: remove dependency on linux/kernel.h Ahmad Fatoum
` (2 preceding siblings ...)
2024-07-16 11:58 ` [PATCH 3/8] stringlist: make header self-contained Ahmad Fatoum
@ 2024-07-16 11:58 ` Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 5/8] include: move MODULE_* macro definitions into own header Ahmad Fatoum
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2024-07-16 11:58 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We only ever set MODULE_SYMBOL_PREFIX to the empty string and Linux has
dropped the macro as well in the meantime, so just remove the
definition.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/module.c | 4 ++--
include/linux/export.h | 4 +---
include/module.h | 4 ----
3 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/common/module.c b/common/module.c
index b669ec09c99f..120fe4c88183 100644
--- a/common/module.c
+++ b/common/module.c
@@ -187,10 +187,10 @@ static void register_module_cmds(Elf32_Shdr *sechdrs, const char *strtab, unsign
sym = (void *)sechdrs[symindex].sh_addr;
for (i = 0; i < numsyms; i++) {
- if (strcmp(strtab + sym[i].st_name, MODULE_SYMBOL_PREFIX "__barebox_cmd_start") == 0)
+ if (strcmp(strtab + sym[i].st_name, "__barebox_cmd_start") == 0)
cmd_start = (struct command * const *)sym[i].st_value;
- if (strcmp(strtab + sym[i].st_name, MODULE_SYMBOL_PREFIX "__barebox_cmd_end") == 0)
+ if (strcmp(strtab + sym[i].st_name, "__barebox_cmd_end") == 0)
cmd_end = (struct command * const *)sym[i].st_value;
}
diff --git a/include/linux/export.h b/include/linux/export.h
index e8ec826366af..0856704018d2 100644
--- a/include/linux/export.h
+++ b/include/linux/export.h
@@ -4,8 +4,6 @@
#ifndef __ASSEMBLY__
-#include <module.h>
-
#define THIS_MODULE 0
#if defined(CONFIG_MODULES) && !defined(__DISABLE_EXPORTS)
@@ -21,7 +19,7 @@ struct kernel_symbol
extern typeof(sym) sym; \
static const char __ustrtab_##sym[] \
__ll_elem(__usymtab_strings) \
- = MODULE_SYMBOL_PREFIX #sym; \
+ = #sym; \
static const struct kernel_symbol __usymtab_##sym \
__ll_elem(__usymtab) \
= { (unsigned long)&sym, __ustrtab_##sym }
diff --git a/include/module.h b/include/module.h
index 9099e5aeed56..0e81033b20d0 100644
--- a/include/module.h
+++ b/include/module.h
@@ -8,10 +8,6 @@
#include <linux/export.h>
#include <linux/list.h>
-#ifndef MODULE_SYMBOL_PREFIX
-#define MODULE_SYMBOL_PREFIX
-#endif
-
#define MODULE_NAME_LEN (64 - sizeof(unsigned long))
/* These are either module local, or the kernel's dummy ones. */
--
2.39.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 5/8] include: move MODULE_* macro definitions into own header
2024-07-16 11:58 [PATCH 0/8] include: list: remove dependency on linux/kernel.h Ahmad Fatoum
` (3 preceding siblings ...)
2024-07-16 11:58 ` [PATCH 4/8] module: retire MODULE_SYMBOL_PREFIX Ahmad Fatoum
@ 2024-07-16 11:58 ` Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 6/8] include: asm-generic/bug: break recursive dependency Ahmad Fatoum
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2024-07-16 11:58 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We'll remove the <linux/kernel.h> include from <linux/list.h> in a later
commit, so prepare for that by defining the MODULE_* macros via driver.h
as well, otherwise build of some drivers will break, because the relied
on the transitive inclusion of <linux/barebox-wrapper.h> via
<linux/list.h>.
While at it we also remove a duplicate __init definition.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/driver.h | 1 +
include/linux/barebox-wrapper.h | 12 +-----------
include/linux/module.h | 17 +++++++++++++++++
include/module.h | 1 +
4 files changed, 20 insertions(+), 11 deletions(-)
create mode 100644 include/linux/module.h
diff --git a/include/driver.h b/include/driver.h
index d4687fd2c2d2..2b4db2221a6c 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -10,6 +10,7 @@
#include <linux/ioport.h>
#include <linux/uuid.h>
#include <linux/printk.h>
+#include <linux/module.h>
#include <device.h>
#include <of.h>
#include <init.h>
diff --git a/include/linux/barebox-wrapper.h b/include/linux/barebox-wrapper.h
index 5d311e1d70f4..8320a24b7bc1 100644
--- a/include/linux/barebox-wrapper.h
+++ b/include/linux/barebox-wrapper.h
@@ -4,6 +4,7 @@
#include <malloc.h>
#include <xfuncs.h>
#include <linux/slab.h>
+#include <linux/module.h>
#include <printk.h>
#define vmalloc(len) malloc(len)
@@ -14,17 +15,6 @@ static inline void vfree(const void *addr)
free((void *)addr);
}
-#define __init
-
-#define MODULE_AUTHOR(x)
-#define MODULE_DESCRIPTION(x)
-#define MODULE_LICENSE(x)
-#define MODULE_VERSION(x)
-#define MODULE_ALIAS(x)
-#define MODULE_DEVICE_TABLE(bus, table)
-#define MODULE_ALIAS_DSA_TAG_DRIVER(drv)
-#define MODULE_ALIAS_CRYPTO(alias)
-
#define __user
#define __init
#define __exit
diff --git a/include/linux/module.h b/include/linux/module.h
new file mode 100644
index 000000000000..6a8ef6d6eccc
--- /dev/null
+++ b/include/linux/module.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _LINUX_MODULE_H
+#define _LINUX_MODULE_H
+
+#include <linux/export.h>
+
+#define MODULE_AUTHOR(x)
+#define MODULE_DESCRIPTION(x)
+#define MODULE_LICENSE(x)
+#define MODULE_VERSION(x)
+#define MODULE_ALIAS(x)
+#define MODULE_DEVICE_TABLE(bus, table)
+#define MODULE_ALIAS_DSA_TAG_DRIVER(drv)
+#define MODULE_ALIAS_CRYPTO(alias)
+
+#endif
diff --git a/include/module.h b/include/module.h
index 0e81033b20d0..60ad6c3556d1 100644
--- a/include/module.h
+++ b/include/module.h
@@ -6,6 +6,7 @@
#include <elf.h>
#include <linux/compiler.h>
#include <linux/export.h>
+#include <linux/module.h>
#include <linux/list.h>
#define MODULE_NAME_LEN (64 - sizeof(unsigned long))
--
2.39.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 6/8] include: asm-generic/bug: break recursive dependency
2024-07-16 11:58 [PATCH 0/8] include: list: remove dependency on linux/kernel.h Ahmad Fatoum
` (4 preceding siblings ...)
2024-07-16 11:58 ` [PATCH 5/8] include: move MODULE_* macro definitions into own header Ahmad Fatoum
@ 2024-07-16 11:58 ` Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 7/8] include: linux/kernel.h: split off into multiple headers Ahmad Fatoum
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2024-07-16 11:58 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
<linux/kernel.h> was included because it used to define panic(). This is
no longer the case and it's now defined in <printk.h>, so it's ok to
drop this header.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/asm-generic/bug.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 18a1b419ff07..0277527491cf 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -4,7 +4,6 @@
#define _ASM_GENERIC_BUG_H
#include <linux/compiler.h>
-#include <linux/kernel.h>
#include <printk.h>
#define BUG() do { \
--
2.39.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 7/8] include: linux/kernel.h: split off into multiple headers
2024-07-16 11:58 [PATCH 0/8] include: list: remove dependency on linux/kernel.h Ahmad Fatoum
` (5 preceding siblings ...)
2024-07-16 11:58 ` [PATCH 6/8] include: asm-generic/bug: break recursive dependency Ahmad Fatoum
@ 2024-07-16 11:58 ` Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 8/8] include: list: replace full kernel.h inclusion with smaller container_of.h Ahmad Fatoum
2024-07-19 6:31 ` [PATCH 0/8] include: list: remove dependency on linux/kernel.h Sascha Hauer
8 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2024-07-16 11:58 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The upstream version in Linux has successively factored out parts into
newly created headers for specific functions. What remains in
<linux/kernel.h> is mostly ftrace and annotations like might_sleep(),
which we don't define in <linux/kernel.h>.
Let's follow suit and factor out everything into headers. The intention
is that other headers won't include <linux/kernel.h>, but one of the
more specific headers and that way we avoid recursive dependencies
and reduce parse time.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/linux/array_size.h | 14 +++
include/linux/hex.h | 34 ++++++
include/linux/kernel.h | 234 +------------------------------------
include/linux/kstrtox.h | 123 +++++++++++++++++++
include/linux/math.h | 83 +++++++++++++
include/linux/wordpart.h | 49 ++++++++
6 files changed, 308 insertions(+), 229 deletions(-)
create mode 100644 include/linux/array_size.h
create mode 100644 include/linux/hex.h
create mode 100644 include/linux/kstrtox.h
create mode 100644 include/linux/math.h
create mode 100644 include/linux/wordpart.h
diff --git a/include/linux/array_size.h b/include/linux/array_size.h
new file mode 100644
index 000000000000..5411d730c819
--- /dev/null
+++ b/include/linux/array_size.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_ARRAY_SIZE_H
+#define _LINUX_ARRAY_SIZE_H
+
+#include <linux/compiler.h>
+
+/**
+ * ARRAY_SIZE - get the number of elements in array @arr
+ * @arr: array to be sized
+ */
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
+#define ARRAY_AND_SIZE(x) (x), ARRAY_SIZE(x)
+
+#endif /* _LINUX_ARRAY_SIZE_H */
diff --git a/include/linux/hex.h b/include/linux/hex.h
new file mode 100644
index 000000000000..b77ed6d5441f
--- /dev/null
+++ b/include/linux/hex.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_HEX_H
+#define _LINUX_HEX_H
+
+#include <linux/types.h>
+#include <linux/compiler.h>
+
+extern const char hex_asc[];
+#define hex_asc_lo(x) hex_asc[((x) & 0x0f)]
+#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4]
+
+static inline char *hex_byte_pack(char *buf, u8 byte)
+{
+ *buf++ = hex_asc_hi(byte);
+ *buf++ = hex_asc_lo(byte);
+ return buf;
+}
+
+extern const char hex_asc_upper[];
+#define hex_asc_upper_lo(x) hex_asc_upper[((x) & 0x0f)]
+#define hex_asc_upper_hi(x) hex_asc_upper[((x) & 0xf0) >> 4]
+
+static inline char *hex_byte_pack_upper(char *buf, u8 byte)
+{
+ *buf++ = hex_asc_upper_hi(byte);
+ *buf++ = hex_asc_upper_lo(byte);
+ return buf;
+}
+
+extern int hex_to_bin(char ch);
+extern int __must_check hex2bin(u8 *dst, const char *src, size_t count);
+extern char *bin2hex(char *dst, const void *src, size_t count);
+
+#endif
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index dd108ba0abf7..fbb3cfe844cb 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -3,241 +3,17 @@
#define _LINUX_KERNEL_H
#include <linux/compiler.h>
+#include <linux/array_size.h>
#include <linux/bug.h>
#include <linux/barebox-wrapper.h>
#include <linux/limits.h>
-#include <linux/math64.h>
+#include <linux/math.h>
#include <linux/container_of.h>
+#include <linux/wordpart.h>
#include <linux/instruction_pointer.h>
#include <linux/minmax.h>
+#include <linux/kstrtox.h>
#include <linux/align.h>
-
-/**
- * REPEAT_BYTE - repeat the value @x multiple times as an unsigned long value
- * @x: value to repeat
- *
- * NOTE: @x is not checked for > 0xff; larger values produce odd results.
- */
-#define REPEAT_BYTE(x) ((~0ul / 0xff) * (x))
-
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
-#define ARRAY_AND_SIZE(x) (x), ARRAY_SIZE(x)
-
-/*
- * This looks more complex than it should be. But we need to
- * get the type for the ~ right in round_down (it needs to be
- * as wide as the result!), and we want to evaluate the macro
- * arguments just once each.
- *
- * NOTE these functions only round to power-of-2 arguments. Use
- * roundup/rounddown for non power-of-2-arguments.
- */
-#define __round_mask(x, y) ((__typeof__(x))((y)-1))
-#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
-#define round_down(x, y) ((x) & ~__round_mask(x, y))
-
-#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
-
-#define DIV_ROUND_DOWN_ULL(ll, d) \
- ({ unsigned long long _tmp = (ll); do_div(_tmp, d); _tmp; })
-
-#define DIV_ROUND_UP_ULL(ll, d) DIV_ROUND_DOWN_ULL((ll) + (d) - 1, (d))
-
-#define DIV_ROUND_CLOSEST(x, divisor)( \
-{ \
- typeof(divisor) __divisor = divisor; \
- (((x) + ((__divisor) / 2)) / (__divisor)); \
-} \
-)
-/*
- * Same as above but for u64 dividends. divisor must be a 32-bit
- * number.
- */
-#define DIV_ROUND_CLOSEST_ULL(x, divisor)( \
-{ \
- typeof(divisor) __d = divisor; \
- unsigned long long _tmp = (x) + (__d) / 2; \
- do_div(_tmp, __d); \
- _tmp; \
-} \
-)
-
-/**
- * upper_32_bits - return bits 32-63 of a number
- * @n: the number we're accessing
- *
- * A basic shift-right of a 64- or 32-bit quantity. Use this to suppress
- * the "right shift count >= width of type" warning when that quantity is
- * 32-bits.
- */
-#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
-
-/**
- * lower_32_bits - return bits 0-31 of a number
- * @n: the number we're accessing
- */
-#define lower_32_bits(n) ((u32)(n))
-
-#define abs(x) ({ \
- long __x = (x); \
- (__x < 0) ? -__x : __x; \
- })
-
-#define abs64(x) ({ \
- s64 __x = (x); \
- (__x < 0) ? -__x : __x; \
- })
-
-extern unsigned long simple_strtoul(const char *,char **,unsigned int);
-extern long simple_strtol(const char *,char **,unsigned int);
-extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
-extern long long simple_strtoll(const char *,char **,unsigned int);
-extern s64 simple_strtofract(const char *cp, char **endp, u32 division);
-
-/* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */
-#define roundup(x, y) ( \
-{ \
- const typeof(y) __y = y; \
- (((x) + (__y - 1)) / __y) * __y; \
-} \
-)
-#define rounddown(x, y) ( \
-{ \
- typeof(x) __x = (x); \
- __x - (__x % (y)); \
-} \
-)
-
-/* Calculate "x * n / d" without unnecessary overflow or loss of precision. */
-#define mult_frac(x, n, d) \
-({ \
- typeof(x) x_ = (x); \
- typeof(n) n_ = (n); \
- typeof(d) d_ = (d); \
- \
- typeof(x_) q = x_ / d_; \
- typeof(x_) r = x_ % d_; \
- q * n_ + r * n_ / d_; \
-})
-
-extern const char hex_asc[];
-#define hex_asc_lo(x) hex_asc[((x) & 0x0f)]
-#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4]
-
-static inline char *hex_byte_pack(char *buf, u8 byte)
-{
- *buf++ = hex_asc_hi(byte);
- *buf++ = hex_asc_lo(byte);
- return buf;
-}
-
-extern const char hex_asc_upper[];
-#define hex_asc_upper_lo(x) hex_asc_upper[((x) & 0x0f)]
-#define hex_asc_upper_hi(x) hex_asc_upper[((x) & 0xf0) >> 4]
-
-static inline char *hex_byte_pack_upper(char *buf, u8 byte)
-{
- *buf++ = hex_asc_upper_hi(byte);
- *buf++ = hex_asc_upper_lo(byte);
- return buf;
-}
-
-extern int hex_to_bin(char ch);
-extern int __must_check hex2bin(u8 *dst, const char *src, size_t count);
-extern char *bin2hex(char *dst, const void *src, size_t count);
-
-/* Internal, do not use. */
-int __must_check _kstrtoul(const char *s, unsigned int base, unsigned long *res);
-int __must_check _kstrtol(const char *s, unsigned int base, long *res);
-
-int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res);
-int __must_check kstrtoll(const char *s, unsigned int base, long long *res);
-
-/**
- * kstrtoul - convert a string to an unsigned long
- * @s: The start of the string. The string must be null-terminated, and may also
- * include a single newline before its terminating null. The first character
- * may also be a plus sign, but not a minus sign.
- * @base: The number base to use. The maximum supported base is 16. If base is
- * given as 0, then the base of the string is automatically detected with the
- * conventional semantics - If it begins with 0x the number will be parsed as a
- * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
- * parsed as an octal number. Otherwise it will be parsed as a decimal.
- * @res: Where to write the result of the conversion on success.
- *
- * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
- * Used as a replacement for the obsolete simple_strtoull. Return code must
- * be checked.
-*/
-static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res)
-{
- /*
- * We want to shortcut function call, but
- * __builtin_types_compatible_p(unsigned long, unsigned long long) = 0.
- */
- if (sizeof(unsigned long) == sizeof(unsigned long long) &&
- __alignof__(unsigned long) == __alignof__(unsigned long long))
- return kstrtoull(s, base, (unsigned long long *)res);
- else
- return _kstrtoul(s, base, res);
-}
-
-/**
- * kstrtol - convert a string to a long
- * @s: The start of the string. The string must be null-terminated, and may also
- * include a single newline before its terminating null. The first character
- * may also be a plus sign or a minus sign.
- * @base: The number base to use. The maximum supported base is 16. If base is
- * given as 0, then the base of the string is automatically detected with the
- * conventional semantics - If it begins with 0x the number will be parsed as a
- * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
- * parsed as an octal number. Otherwise it will be parsed as a decimal.
- * @res: Where to write the result of the conversion on success.
- *
- * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
- * Used as a replacement for the obsolete simple_strtoull. Return code must
- * be checked.
- */
-static inline int __must_check kstrtol(const char *s, unsigned int base, long *res)
-{
- /*
- * We want to shortcut function call, but
- * __builtin_types_compatible_p(long, long long) = 0.
- */
- if (sizeof(long) == sizeof(long long) &&
- __alignof__(long) == __alignof__(long long))
- return kstrtoll(s, base, (long long *)res);
- else
- return _kstrtol(s, base, res);
-}
-
-int __must_check kstrtouint(const char *s, unsigned int base, unsigned int *res);
-int __must_check kstrtoint(const char *s, unsigned int base, int *res);
-
-static inline int __must_check kstrtou64(const char *s, unsigned int base, u64 *res)
-{
- return kstrtoull(s, base, res);
-}
-
-static inline int __must_check kstrtos64(const char *s, unsigned int base, s64 *res)
-{
- return kstrtoll(s, base, res);
-}
-
-static inline int __must_check kstrtou32(const char *s, unsigned int base, u32 *res)
-{
- return kstrtouint(s, base, res);
-}
-
-static inline int __must_check kstrtos32(const char *s, unsigned int base, s32 *res)
-{
- return kstrtoint(s, base, res);
-}
-
-int __must_check kstrtou16(const char *s, unsigned int base, u16 *res);
-int __must_check kstrtos16(const char *s, unsigned int base, s16 *res);
-int __must_check kstrtou8(const char *s, unsigned int base, u8 *res);
-int __must_check kstrtos8(const char *s, unsigned int base, s8 *res);
-int __must_check kstrtobool(const char *s, bool *res);
+#include <linux/hex.h>
#endif /* _LINUX_KERNEL_H */
diff --git a/include/linux/kstrtox.h b/include/linux/kstrtox.h
new file mode 100644
index 000000000000..51493c71292b
--- /dev/null
+++ b/include/linux/kstrtox.h
@@ -0,0 +1,123 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_KSTRTOX_H
+#define _LINUX_KSTRTOX_H
+
+#include <linux/types.h>
+#include <linux/compiler.h>
+
+/* Internal, do not use. */
+int __must_check _kstrtoul(const char *s, unsigned int base, unsigned long *res);
+int __must_check _kstrtol(const char *s, unsigned int base, long *res);
+
+int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res);
+int __must_check kstrtoll(const char *s, unsigned int base, long long *res);
+
+/**
+ * kstrtoul - convert a string to an unsigned long
+ * @s: The start of the string. The string must be null-terminated, and may also
+ * include a single newline before its terminating null. The first character
+ * may also be a plus sign, but not a minus sign.
+ * @base: The number base to use. The maximum supported base is 16. If base is
+ * given as 0, then the base of the string is automatically detected with the
+ * conventional semantics - If it begins with 0x the number will be parsed as a
+ * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
+ * parsed as an octal number. Otherwise it will be parsed as a decimal.
+ * @res: Where to write the result of the conversion on success.
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ * Used as a replacement for the obsolete simple_strtoull. Return code must
+ * be checked.
+*/
+static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res)
+{
+ /*
+ * We want to shortcut function call, but
+ * __builtin_types_compatible_p(unsigned long, unsigned long long) = 0.
+ */
+ if (sizeof(unsigned long) == sizeof(unsigned long long) &&
+ __alignof__(unsigned long) == __alignof__(unsigned long long))
+ return kstrtoull(s, base, (unsigned long long *)res);
+ else
+ return _kstrtoul(s, base, res);
+}
+
+/**
+ * kstrtol - convert a string to a long
+ * @s: The start of the string. The string must be null-terminated, and may also
+ * include a single newline before its terminating null. The first character
+ * may also be a plus sign or a minus sign.
+ * @base: The number base to use. The maximum supported base is 16. If base is
+ * given as 0, then the base of the string is automatically detected with the
+ * conventional semantics - If it begins with 0x the number will be parsed as a
+ * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
+ * parsed as an octal number. Otherwise it will be parsed as a decimal.
+ * @res: Where to write the result of the conversion on success.
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ * Used as a replacement for the obsolete simple_strtoull. Return code must
+ * be checked.
+ */
+static inline int __must_check kstrtol(const char *s, unsigned int base, long *res)
+{
+ /*
+ * We want to shortcut function call, but
+ * __builtin_types_compatible_p(long, long long) = 0.
+ */
+ if (sizeof(long) == sizeof(long long) &&
+ __alignof__(long) == __alignof__(long long))
+ return kstrtoll(s, base, (long long *)res);
+ else
+ return _kstrtol(s, base, res);
+}
+
+int __must_check kstrtouint(const char *s, unsigned int base, unsigned int *res);
+int __must_check kstrtoint(const char *s, unsigned int base, int *res);
+
+static inline int __must_check kstrtou64(const char *s, unsigned int base, u64 *res)
+{
+ return kstrtoull(s, base, res);
+}
+
+static inline int __must_check kstrtos64(const char *s, unsigned int base, s64 *res)
+{
+ return kstrtoll(s, base, res);
+}
+
+static inline int __must_check kstrtou32(const char *s, unsigned int base, u32 *res)
+{
+ return kstrtouint(s, base, res);
+}
+
+static inline int __must_check kstrtos32(const char *s, unsigned int base, s32 *res)
+{
+ return kstrtoint(s, base, res);
+}
+
+int __must_check kstrtou16(const char *s, unsigned int base, u16 *res);
+int __must_check kstrtos16(const char *s, unsigned int base, s16 *res);
+int __must_check kstrtou8(const char *s, unsigned int base, u8 *res);
+int __must_check kstrtos8(const char *s, unsigned int base, s8 *res);
+int __must_check kstrtobool(const char *s, bool *res);
+
+
+/*
+ * Use kstrto<foo> instead.
+ *
+ * NOTE: simple_strto<foo> does not check for the range overflow and,
+ * depending on the input, may give interesting results.
+ *
+ * Use these functions if and only if you cannot use kstrto<foo>, because
+ * the conversion ends on the first non-digit character, which may be far
+ * beyond the supported range. It might be useful to parse the strings like
+ * 10x50 or 12:21 without altering original string or temporary buffer in use.
+ * Keep in mind above caveat.
+ */
+
+extern unsigned long simple_strtoul(const char *,char **,unsigned int);
+extern long simple_strtol(const char *,char **,unsigned int);
+extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
+extern long long simple_strtoll(const char *,char **,unsigned int);
+
+extern s64 simple_strtofract(const char *cp, char **endp, u32 division);
+
+#endif
diff --git a/include/linux/math.h b/include/linux/math.h
new file mode 100644
index 000000000000..acbffa96e6eb
--- /dev/null
+++ b/include/linux/math.h
@@ -0,0 +1,83 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_MATH_H
+#define _LINUX_MATH_H
+
+#include <linux/types.h>
+#include <linux/math64.h>
+
+/*
+ * This looks more complex than it should be. But we need to
+ * get the type for the ~ right in round_down (it needs to be
+ * as wide as the result!), and we want to evaluate the macro
+ * arguments just once each.
+ *
+ * NOTE these functions only round to power-of-2 arguments. Use
+ * roundup/rounddown for non power-of-2-arguments.
+ */
+#define __round_mask(x, y) ((__typeof__(x))((y)-1))
+#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
+#define round_down(x, y) ((x) & ~__round_mask(x, y))
+
+#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+
+#define DIV_ROUND_DOWN_ULL(ll, d) \
+ ({ unsigned long long _tmp = (ll); do_div(_tmp, d); _tmp; })
+
+#define DIV_ROUND_UP_ULL(ll, d) DIV_ROUND_DOWN_ULL((ll) + (d) - 1, (d))
+
+#define DIV_ROUND_CLOSEST(x, divisor)( \
+{ \
+ typeof(divisor) __divisor = divisor; \
+ (((x) + ((__divisor) / 2)) / (__divisor)); \
+} \
+)
+/*
+ * Same as above but for u64 dividends. divisor must be a 32-bit
+ * number.
+ */
+#define DIV_ROUND_CLOSEST_ULL(x, divisor)( \
+{ \
+ typeof(divisor) __d = divisor; \
+ unsigned long long _tmp = (x) + (__d) / 2; \
+ do_div(_tmp, __d); \
+ _tmp; \
+} \
+)
+
+/* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */
+#define roundup(x, y) ( \
+{ \
+ const typeof(y) __y = y; \
+ (((x) + (__y - 1)) / __y) * __y; \
+} \
+)
+#define rounddown(x, y) ( \
+{ \
+ typeof(x) __x = (x); \
+ __x - (__x % (y)); \
+} \
+)
+
+/* Calculate "x * n / d" without unnecessary overflow or loss of precision. */
+#define mult_frac(x, n, d) \
+({ \
+ typeof(x) x_ = (x); \
+ typeof(n) n_ = (n); \
+ typeof(d) d_ = (d); \
+ \
+ typeof(x_) q = x_ / d_; \
+ typeof(x_) r = x_ % d_; \
+ q * n_ + r * n_ / d_; \
+})
+
+#define abs(x) ({ \
+ long __x = (x); \
+ (__x < 0) ? -__x : __x; \
+ })
+
+#define abs64(x) ({ \
+ s64 __x = (x); \
+ (__x < 0) ? -__x : __x; \
+ })
+
+#endif
diff --git a/include/linux/wordpart.h b/include/linux/wordpart.h
new file mode 100644
index 000000000000..72a83685c95d
--- /dev/null
+++ b/include/linux/wordpart.h
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _LINUX_WORDPART_H
+#define _LINUX_WORDPART_H
+
+/**
+ * upper_32_bits - return bits 32-63 of a number
+ * @n: the number we're accessing
+ *
+ * A basic shift-right of a 64- or 32-bit quantity. Use this to suppress
+ * the "right shift count >= width of type" warning when that quantity is
+ * 32-bits.
+ */
+#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
+
+/**
+ * lower_32_bits - return bits 0-31 of a number
+ * @n: the number we're accessing
+ */
+#define lower_32_bits(n) ((u32)((n) & 0xffffffff))
+
+/**
+ * upper_16_bits - return bits 16-31 of a number
+ * @n: the number we're accessing
+ */
+#define upper_16_bits(n) ((u16)((n) >> 16))
+
+/**
+ * lower_16_bits - return bits 0-15 of a number
+ * @n: the number we're accessing
+ */
+#define lower_16_bits(n) ((u16)((n) & 0xffff))
+
+/**
+ * REPEAT_BYTE - repeat the value @x multiple times as an unsigned long value
+ * @x: value to repeat
+ *
+ * NOTE: @x is not checked for > 0xff; larger values produce odd results.
+ */
+#define REPEAT_BYTE(x) ((~0ul / 0xff) * (x))
+
+/* Set bits in the first 'n' bytes when loaded from memory */
+#ifdef __LITTLE_ENDIAN
+# define aligned_byte_mask(n) ((1UL << 8*(n))-1)
+#else
+# define aligned_byte_mask(n) (~0xffUL << (BITS_PER_LONG - 8 - 8*(n)))
+#endif
+
+#endif // _LINUX_WORDPART_H
--
2.39.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 8/8] include: list: replace full kernel.h inclusion with smaller container_of.h
2024-07-16 11:58 [PATCH 0/8] include: list: remove dependency on linux/kernel.h Ahmad Fatoum
` (6 preceding siblings ...)
2024-07-16 11:58 ` [PATCH 7/8] include: linux/kernel.h: split off into multiple headers Ahmad Fatoum
@ 2024-07-16 11:58 ` Ahmad Fatoum
2024-07-19 6:31 ` [PATCH 0/8] include: list: remove dependency on linux/kernel.h Sascha Hauer
8 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2024-07-16 11:58 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
<linux/kernel.h> defines a lot of things that go beyond what's needed for
<linux/list.h>. The only thing actually needed for the list
implementation is <linux/container_of.h>, so include that directly.
This is also what Linux has been doing for a while.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/linux/list.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/list.h b/include/linux/list.h
index e47a8188e807..e28f54a0d413 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -2,11 +2,11 @@
#ifndef _LINUX_LIST_H
#define _LINUX_LIST_H
+#include <linux/container_of.h>
#include <linux/types.h>
#include <linux/stddef.h>
#include <linux/poison.h>
#include <linux/const.h>
-#include <linux/kernel.h>
/*
* Simple doubly linked list implementation.
--
2.39.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/8] include: list: remove dependency on linux/kernel.h
2024-07-16 11:58 [PATCH 0/8] include: list: remove dependency on linux/kernel.h Ahmad Fatoum
` (7 preceding siblings ...)
2024-07-16 11:58 ` [PATCH 8/8] include: list: replace full kernel.h inclusion with smaller container_of.h Ahmad Fatoum
@ 2024-07-19 6:31 ` Sascha Hauer
8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2024-07-19 6:31 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Tue, 16 Jul 2024 13:58:26 +0200, Ahmad Fatoum wrote:
> <linux/kernel.h> defines a lot of things that go beyond what's needed for
> <linux/list.h>. The only thing actually needed for the list
> implementation is <linux/container_of.h>, so we should just include that
> directly.
>
> This is also what Linux has been doing for a while, but it breaks the
> build of a number of source files, which are addressed in this series.
>
> [...]
Applied, thanks!
[1/8] regmap-mmio: don't call kfree on non kmalloc allocated buffers
https://git.pengutronix.de/cgit/barebox/commit/?id=47b17710a6d6 (link may not be stable)
[2/8] treewide: fix dependency on indirectly included linux/kernel.h
https://git.pengutronix.de/cgit/barebox/commit/?id=460a23bb44ab (link may not be stable)
[3/8] stringlist: make header self-contained
https://git.pengutronix.de/cgit/barebox/commit/?id=517a4fae1139 (link may not be stable)
[4/8] module: retire MODULE_SYMBOL_PREFIX
https://git.pengutronix.de/cgit/barebox/commit/?id=fb39544f95ee (link may not be stable)
[5/8] include: move MODULE_* macro definitions into own header
https://git.pengutronix.de/cgit/barebox/commit/?id=2ad332d6eaf4 (link may not be stable)
[6/8] include: asm-generic/bug: break recursive dependency
https://git.pengutronix.de/cgit/barebox/commit/?id=1ea777fbff9c (link may not be stable)
[7/8] include: linux/kernel.h: split off into multiple headers
https://git.pengutronix.de/cgit/barebox/commit/?id=ce2b8d6e4b07 (link may not be stable)
[8/8] include: list: replace full kernel.h inclusion with smaller container_of.h
https://git.pengutronix.de/cgit/barebox/commit/?id=d7b6cda8fcda (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-07-19 6:32 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-16 11:58 [PATCH 0/8] include: list: remove dependency on linux/kernel.h Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 1/8] regmap-mmio: don't call kfree on non kmalloc allocated buffers Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 2/8] treewide: fix dependency on indirectly included linux/kernel.h Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 3/8] stringlist: make header self-contained Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 4/8] module: retire MODULE_SYMBOL_PREFIX Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 5/8] include: move MODULE_* macro definitions into own header Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 6/8] include: asm-generic/bug: break recursive dependency Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 7/8] include: linux/kernel.h: split off into multiple headers Ahmad Fatoum
2024-07-16 11:58 ` [PATCH 8/8] include: list: replace full kernel.h inclusion with smaller container_of.h Ahmad Fatoum
2024-07-19 6:31 ` [PATCH 0/8] include: list: remove dependency on linux/kernel.h Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox