mm: Move kvmalloc-related functions to slab.h
Subsystems (4)
PATCH v2 1/1 mm: Move kvmalloc-related functions to slab.h
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) <[email protected]>
---
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(-)
drivers/of/kexec.c +1 -0
@@ -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 */
include/linux/mm.h +0 -32
@@ -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 ;
include/linux/slab.h +32 -0
@@ -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 );
Signature · 1 line
2.30.2
Quoted 4 lines · Matthew Wilcox (Oracle)
Not all files in the kernel should include
mm.h. Migrating callers from kmalloc to kvmalloc is easier if the kvmalloc functions are inslab.h.Signed-off-by Matthew Wilcox (Oracle) <[email protected]>
Acked-by Pekka Enberg <[email protected]>