[Concept,01/17] ext4l: Move cache alignment and pointer macros to headers

Message ID 20260120234344.495605-2-sjg@u-boot.org
State New
Headers
Series ext4l: Move compatibility stubs to standard Linux headers |

Commit Message

Simon Glass Jan. 20, 2026, 11:43 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Move several compatibility macros to their proper Linux headers:

- Create linux/cache.h with ____cacheline_aligned_in_smp stub
- Move ZERO_OR_NULL_PTR to linux/slab.h
- Add __counted_by stub to linux/compiler_attributes.h

This reduces ext4_uboot.h by moving these definitions to their canonical
locations in the Linux header hierarchy.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 fs/ext4l/ext4_uboot.h               | 10 ++++------
 include/linux/cache.h               | 22 ++++++++++++++++++++++
 include/linux/compiler_attributes.h | 10 ++++++++++
 include/linux/slab.h                |  9 +++++++++
 4 files changed, 45 insertions(+), 6 deletions(-)
 create mode 100644 include/linux/cache.h
  

Patch

diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h
index eadff92aecb..2255458a46d 100644
--- a/fs/ext4l/ext4_uboot.h
+++ b/fs/ext4l/ext4_uboot.h
@@ -118,11 +118,10 @@ 
 /* completion - use Linux header */
 #include <linux/completion.h>
 
-/* Cache alignment - stub */
-#define ____cacheline_aligned_in_smp
+/* Cache alignment - use linux/cache.h */
+#include <linux/cache.h>
 
-/* Pointer check macros */
-#define ZERO_OR_NULL_PTR(x)		((unsigned long)(x) <= PAGE_SIZE)
+/* ZERO_OR_NULL_PTR is in linux/slab.h */
 /* data_race is in linux/compiler.h */
 
 /* REQ_META, REQ_PRIO, REQ_RAHEAD are in linux/blk_types.h */
@@ -154,8 +153,7 @@ 
 /* kiocb, iov_iter - use linux/uio.h */
 #include <linux/uio.h>
 
-/* __counted_by attribute - not available in U-Boot */
-#define __counted_by(x)
+/* __counted_by is in linux/compiler_attributes.h */
 
 /* dir_context, filldir_t are in linux/fs.h */
 
diff --git a/include/linux/cache.h b/include/linux/cache.h
new file mode 100644
index 00000000000..2fb4e00faa7
--- /dev/null
+++ b/include/linux/cache.h
@@ -0,0 +1,22 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Cache alignment definitions for U-Boot
+ *
+ * Based on Linux include/linux/cache.h
+ */
+#ifndef _LINUX_CACHE_H
+#define _LINUX_CACHE_H
+
+/*
+ * U-Boot is single-threaded, so cache line alignment for SMP is not needed.
+ * These are provided for compatibility with Linux code.
+ */
+#ifndef ____cacheline_aligned_in_smp
+#define ____cacheline_aligned_in_smp
+#endif
+
+#ifndef __cacheline_aligned_in_smp
+#define __cacheline_aligned_in_smp
+#endif
+
+#endif /* _LINUX_CACHE_H */
diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h
index 44c9a08d734..097fce857c5 100644
--- a/include/linux/compiler_attributes.h
+++ b/include/linux/compiler_attributes.h
@@ -270,4 +270,14 @@ 
  */
 #define __weak                          __attribute__((__weak__))
 
+/*
+ * __counted_by(member) - flexible array bounds annotation
+ *
+ * Used to annotate flexible array members with the struct member that
+ * holds the count. Not available in all compilers, so stub it out.
+ */
+#ifndef __counted_by
+#define __counted_by(member)
+#endif
+
 #endif /* __LINUX_COMPILER_ATTRIBUTES_H */
diff --git a/include/linux/slab.h b/include/linux/slab.h
index 15d561f0527..628126e0a3b 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -56,6 +56,15 @@ 
 #define SLAB_RECLAIM_ACCOUNT	0x00020000UL	/* Track pages reclaimed */
 #define SLAB_ACCOUNT		0x00000000UL	/* Account to memcg (no-op) */
 
+/*
+ * Check if pointer is zero or in the zero page (used by SLUB allocator).
+ * PAGE_SIZE fallback for when this header is included standalone.
+ */
+#ifndef PAGE_SIZE
+#define PAGE_SIZE	4096
+#endif
+#define ZERO_OR_NULL_PTR(x)	((unsigned long)(x) <= PAGE_SIZE)
+
 void *kmalloc(size_t size, gfp_t flags);
 
 static inline void *kzalloc(size_t size, gfp_t flags)