From 04f17089afbc3438a7a33bc04f69e7b378000b92 Mon Sep 17 00:00:00 2001 From: Jozsef Kadlecsik Date: Thu, 19 Nov 2020 15:01:37 +0100 Subject: Compatibility: check for kvzalloc() and GFP_KERNEL_ACCOUNT Signed-off-by: Jozsef Kadlecsik --- .../linux/netfilter/ipset/ip_set_compat.h.in | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'kernel') diff --git a/kernel/include/linux/netfilter/ipset/ip_set_compat.h.in b/kernel/include/linux/netfilter/ipset/ip_set_compat.h.in index 24acc5f..8f00e6a 100644 --- a/kernel/include/linux/netfilter/ipset/ip_set_compat.h.in +++ b/kernel/include/linux/netfilter/ipset/ip_set_compat.h.in @@ -59,6 +59,8 @@ #@HAVE_LIST_FOR_EACH_ENTRY_RCU_FOUR_ARGS@ HAVE_LIST_FOR_EACH_ENTRY_RCU_FOUR_ARGS #@HAVE_SKB_PROTOCOL@ HAVE_SKB_PROTOCOL #@HAVE_NLA_POLICY_EXACT_LEN@ HAVE_NLA_POLICY_EXACT_LEN +#@HAVE_KVZALLOC@ HAVE_KVZALLOC +#@HAVE_GFP_KERNEL_ACCOUNT@ HAVE_GFP_KERNEL_ACCOUNT #ifdef HAVE_EXPORT_SYMBOL_GPL_IN_MODULE_H #include @@ -485,12 +487,39 @@ static inline u16 nfnl_msg_type(u8 subsys, u8 msg_type) #endif #ifndef HAVE_NLA_POLICY_EXACT_LEN -#define HAVE_NLA_POLICY_EXACT_LEN(_len) { \ +#define NLA_POLICY_EXACT_LEN(_len) { \ .type = NLA_UNSPEC, \ .len = _len \ } #endif +#ifndef HAVE_KVZALLOC +#include +#include +#ifndef GFP_KERNEL_ACCOUNT +#define GFP_KERNEL_ACCOUNT GFP_KERNEL +#endif +static inline void *kvzalloc(size_t size, gfp_t flags) +{ + void *members = NULL; + + if (size < KMALLOC_MAX_SIZE) + members = kzalloc(size, GFP_KERNEL | __GFP_NOWARN); + + if (members) { + pr_debug("%p: allocated with kmalloc\n", members); + return members; + } + + members = vzalloc(size); + if (!members) + return NULL; + pr_debug("%p: allocated with vmalloc\n", members); + + return members; +} +#endif + /* Compiler attributes */ #ifndef __has_attribute # define __has_attribute(x) __GCC4_has_attribute_##x -- cgit v1.2.3