summaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorJozsef Kadlecsik <kadlec@netfilter.org>2020-11-19 15:01:37 +0100
committerJozsef Kadlecsik <kadlec@netfilter.org>2020-11-19 15:50:45 +0100
commit04f17089afbc3438a7a33bc04f69e7b378000b92 (patch)
tree87e8b9f217b5b89984ddd734dd798eff59cbdc35 /kernel
parent434aa00c04428bdded30191477064ab4078e7fe8 (diff)
Compatibility: check for kvzalloc() and GFP_KERNEL_ACCOUNT
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/include/linux/netfilter/ipset/ip_set_compat.h.in31
1 files changed, 30 insertions, 1 deletions
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 <linux/module.h>
@@ -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 <linux/slab.h>
+#include <linux/vmalloc.h>
+#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