diff mbox series

[v2] mm: Move kvmalloc-related functions to slab.h

Message ID 20210622215757.3525604-1-willy@infradead.org (mailing list archive)
State New
Headers show
Series [v2] mm: Move kvmalloc-related functions to slab.h | expand

Commit Message

Matthew Wilcox (Oracle) June 22, 2021, 9:57 p.m. UTC
Not all files in the kernel should include mm.h.  Migrating callers from
kmalloc to kvmalloc is easier if the kvmalloc functions are in slab.h.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
v2: allmodconfig revealed someone calling kvmalloc without slab.h.  It
doesn't include mm.h either, but clearly it's being included through
some indirect path.
 drivers/of/kexec.c   |  1 +
 include/linux/mm.h   | 32 --------------------------------
 include/linux/slab.h | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 32 deletions(-)

Comments

Pekka Enberg June 23, 2021, 6:52 a.m. UTC | #1
On Wed, Jun 23, 2021 at 12:58 AM Matthew Wilcox (Oracle)
<willy@infradead.org> wrote:
> Not all files in the kernel should include mm.h.  Migrating callers from
> kmalloc to kvmalloc is easier if the kvmalloc functions are in slab.h.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>

Acked-by: Pekka Enberg <penberg@kernel.org>
diff mbox series

Patch

diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c
index f335d941a716..b90660c05f30 100644
--- a/drivers/of/kexec.c
+++ b/drivers/of/kexec.c
@@ -16,6 +16,7 @@ 
 #include <linux/of.h>
 #include <linux/of_fdt.h>
 #include <linux/random.h>
+#include <linux/slab.h>
 #include <linux/types.h>
 
 /* relevant device tree properties */
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8ae31622deef..750a6f227ec7 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -798,38 +798,6 @@  static inline int is_vmalloc_or_module_addr(const void *x)
 }
 #endif
 
-extern void *kvmalloc_node(size_t size, gfp_t flags, int node);
-static inline void *kvmalloc(size_t size, gfp_t flags)
-{
-	return kvmalloc_node(size, flags, NUMA_NO_NODE);
-}
-static inline void *kvzalloc_node(size_t size, gfp_t flags, int node)
-{
-	return kvmalloc_node(size, flags | __GFP_ZERO, node);
-}
-static inline void *kvzalloc(size_t size, gfp_t flags)
-{
-	return kvmalloc(size, flags | __GFP_ZERO);
-}
-
-static inline void *kvmalloc_array(size_t n, size_t size, gfp_t flags)
-{
-	size_t bytes;
-
-	if (unlikely(check_mul_overflow(n, size, &bytes)))
-		return NULL;
-
-	return kvmalloc(bytes, flags);
-}
-
-static inline void *kvcalloc(size_t n, size_t size, gfp_t flags)
-{
-	return kvmalloc_array(n, size, flags | __GFP_ZERO);
-}
-
-extern void kvfree(const void *addr);
-extern void kvfree_sensitive(const void *addr, size_t len);
-
 static inline int head_compound_mapcount(struct page *head)
 {
 	return atomic_read(compound_mapcount_ptr(head)) + 1;
diff --git a/include/linux/slab.h b/include/linux/slab.h
index 0c97d788762c..ee676de68afe 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -697,6 +697,38 @@  static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
 	return kmalloc_node(size, flags | __GFP_ZERO, node);
 }
 
+void *kvmalloc_node(size_t size, gfp_t flags, int node);
+static inline void *kvmalloc(size_t size, gfp_t flags)
+{
+	return kvmalloc_node(size, flags, NUMA_NO_NODE);
+}
+static inline void *kvzalloc_node(size_t size, gfp_t flags, int node)
+{
+	return kvmalloc_node(size, flags | __GFP_ZERO, node);
+}
+static inline void *kvzalloc(size_t size, gfp_t flags)
+{
+	return kvmalloc(size, flags | __GFP_ZERO);
+}
+
+static inline void *kvmalloc_array(size_t n, size_t size, gfp_t flags)
+{
+	size_t bytes;
+
+	if (unlikely(check_mul_overflow(n, size, &bytes)))
+		return NULL;
+
+	return kvmalloc(bytes, flags);
+}
+
+static inline void *kvcalloc(size_t n, size_t size, gfp_t flags)
+{
+	return kvmalloc_array(n, size, flags | __GFP_ZERO);
+}
+
+void kvfree(const void *addr);
+void kvfree_sensitive(const void *addr, size_t len);
+
 unsigned int kmem_cache_size(struct kmem_cache *s);
 void __init kmem_cache_init_late(void);