diff options
author | Felix Fietkau <nbd@nbd.name> | 2018-09-06 08:57:46 +0200 |
---|---|---|
committer | Johannes Berg <johannes.berg@intel.com> | 2018-09-10 08:54:43 +0200 |
commit | dafacea0f6aa74998c69f0da7a2d53e56a8c0e1b (patch) | |
tree | 26ea456efebccd853dcf94ab75d371bd7ce89eb5 /backport | |
parent | 9008c30b2e9cd8ab501ab94c871d7cb855a1ad22 (diff) |
backport-include: backport kvmalloc and kvmalloc_array
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'backport')
-rw-r--r-- | backport/backport-include/linux/mm.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/backport/backport-include/linux/mm.h b/backport/backport-include/linux/mm.h index 3234b37d..6ee5c7d8 100644 --- a/backport/backport-include/linux/mm.h +++ b/backport/backport-include/linux/mm.h @@ -3,6 +3,9 @@ #include_next <linux/mm.h> #include <linux/page_ref.h> #include <linux/sched.h> +#include <linux/overflow.h> +#include <linux/vmalloc.h> +#include <linux/slab.h> #ifndef VM_NODUMP /* @@ -123,4 +126,36 @@ static inline bool page_is_pfmemalloc(struct page *page) } #endif /* < 4.2 */ +#if LINUX_VERSION_IS_LESS(4,12,0) +#define kvmalloc LINUX_BACKPORT(kvmalloc) +static inline void *kvmalloc(size_t size, gfp_t flags) +{ + gfp_t kmalloc_flags = flags; + void *ret; + + if ((flags & GFP_KERNEL) != GFP_KERNEL) + return kmalloc(size, flags); + + if (size > PAGE_SIZE) + kmalloc_flags |= __GFP_NOWARN | __GFP_NORETRY; + + ret = kmalloc(size, flags); + if (ret || size < PAGE_SIZE) + return ret; + + return vmalloc(size); +} + +#define kvmalloc_array LINUX_BACKPORT(kvmalloc_array) +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); +} +#endif + #endif /* __BACKPORT_MM_H */ |