[Concept,15/19] linux: Add mempool.h header with memory pool stubs

Message ID 20260117011448.3007171-16-sjg@u-boot.org
State New
Headers
Series ext4l: Reduce ext4_uboot.h size by moving code to include/linux |

Commit Message

Simon Glass Jan. 17, 2026, 1:14 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Move memory pool type and operation stubs to a dedicated header file
that mirrors the Linux kernel organisation.

mempool.h provides:
- mempool_t type
- mempool_alloc() - allocate from pool (stub returns NULL)
- mempool_free() - free to pool (stub no-op)
- mempool_create_slab_pool() - create pool (stub returns NULL)
- mempool_destroy() - destroy pool (stub no-op)

These are stubs since U-Boot doesn't use memory pools.

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

 fs/ext4l/ext4_uboot.h   |  8 ++----
 include/linux/mempool.h | 57 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 6 deletions(-)
 create mode 100644 include/linux/mempool.h
  

Patch

diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h
index 97bcc48d922..f77891835cb 100644
--- a/fs/ext4l/ext4_uboot.h
+++ b/fs/ext4l/ext4_uboot.h
@@ -1795,12 +1795,8 @@  bool __folio_start_writeback(struct folio *folio, bool keep_write);
  * Stubs for readpage.c
  */
 
-/* mempool - memory pool stubs */
-typedef void *mempool_t;
-#define mempool_alloc(pool, gfp)	({ (void)(pool); (void)(gfp); (void *)NULL; })
-#define mempool_free(elem, pool)	do { (void)(elem); (void)(pool); } while (0)
-#define mempool_create_slab_pool(n, c)	({ (void)(n); (void)(c); (mempool_t *)NULL; })
-#define mempool_destroy(pool)		do { (void)(pool); } while (0)
+/* mempool is now in linux/mempool.h */
+#include <linux/mempool.h>
 
 /* folio read operations */
 #define folio_end_read(f, success)	do { (void)(f); (void)(success); } while (0)
diff --git a/include/linux/mempool.h b/include/linux/mempool.h
new file mode 100644
index 00000000000..feb99a1455c
--- /dev/null
+++ b/include/linux/mempool.h
@@ -0,0 +1,57 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Memory pool stubs for U-Boot
+ *
+ * U-Boot doesn't have memory pools, so these are stubs.
+ */
+#ifndef _LINUX_MEMPOOL_H
+#define _LINUX_MEMPOOL_H
+
+#include <linux/types.h>
+
+/**
+ * typedef mempool_t - memory pool handle
+ *
+ * U-Boot stub - memory pools are not used.
+ */
+typedef void *mempool_t;
+
+/**
+ * mempool_alloc() - allocate element from pool
+ * @pool: memory pool
+ * @gfp: allocation flags
+ *
+ * U-Boot stub - always returns NULL.
+ */
+#define mempool_alloc(pool, gfp) \
+	({ (void)(pool); (void)(gfp); (void *)NULL; })
+
+/**
+ * mempool_free() - free element back to pool
+ * @elem: element to free
+ * @pool: memory pool
+ *
+ * U-Boot stub - no-op.
+ */
+#define mempool_free(elem, pool) \
+	do { (void)(elem); (void)(pool); } while (0)
+
+/**
+ * mempool_create_slab_pool() - create a memory pool backed by a slab cache
+ * @min_nr: minimum number of elements
+ * @cache: slab cache
+ *
+ * U-Boot stub - always returns NULL.
+ */
+#define mempool_create_slab_pool(min_nr, cache) \
+	({ (void)(min_nr); (void)(cache); (mempool_t *)NULL; })
+
+/**
+ * mempool_destroy() - destroy a memory pool
+ * @pool: memory pool to destroy
+ *
+ * U-Boot stub - no-op.
+ */
+#define mempool_destroy(pool)	do { (void)(pool); } while (0)
+
+#endif /* _LINUX_MEMPOOL_H */