From e70c77ca171ebd95270003131f27304f2b57ffb4 Mon Sep 17 00:00:00 2001 From: Kristof Provost Date: Sun, 7 Jan 2018 13:39:12 +0000 Subject: [PATCH] linuxkpi: Implement kcalloc() based on mallocarray() This means we now get integer overflow protection, which Linux code might expect as it is also provided by kcalloc() in Linux. --- sys/compat/linuxkpi/common/include/linux/slab.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sys/compat/linuxkpi/common/include/linux/slab.h b/sys/compat/linuxkpi/common/include/linux/slab.h index 541441df25d8..1f8ec82db985 100644 --- a/sys/compat/linuxkpi/common/include/linux/slab.h +++ b/sys/compat/linuxkpi/common/include/linux/slab.h @@ -46,7 +46,6 @@ MALLOC_DECLARE(M_KMALLOC); #define kzalloc(size, flags) kmalloc(size, (flags) | __GFP_ZERO) #define kzalloc_node(size, flags, node) kmalloc(size, (flags) | __GFP_ZERO) #define kfree_const(ptr) kfree(ptr) -#define kcalloc(n, size, flags) kmalloc((n) * (size), (flags) | __GFP_ZERO) #define vzalloc(size) __vmalloc(size, GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO, 0) #define vfree(arg) kfree(arg) #define kvfree(arg) kfree(arg) @@ -100,6 +99,13 @@ kmalloc(size_t size, gfp_t flags) return (malloc(size, M_KMALLOC, linux_check_m_flags(flags))); } +static inline void * +kcalloc(size_t n, size_t size, gfp_t flags) +{ + flags |= __GFP_ZERO; + return (mallocarray(n, size, M_KMALLOC, linux_check_m_flags(flags))); +} + static inline void * __vmalloc(size_t size, gfp_t flags, int other) {