summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Gross <jesse@nicira.com>2011-07-15 09:59:16 -0700
committerJesse Gross <jesse@nicira.com>2011-07-28 17:13:03 -0700
commit466d7efa366fddac616c537507b56e319965b63c (patch)
tree0813e72343a10e35a513494a026c005a16b4e87e
parent01308c2bb5d7970c59ea3a61554ce58736dcc2a9 (diff)
downloadopenvswitch-466d7efa366fddac616c537507b56e319965b63c.tar.gz
datapath: Don't pass __GFP_ZERO to kmalloc on older kernels.
On new kernels kzalloc() is simply a wrapper around kmalloc with the addition of the __GFP_ZERO flag. flex_arrays take advantage of this by expecting the user to just pass in this flag if they want the memory to be zeroed. However, before 2.6.23, kzalloc() was a function in its own right and kmalloc really didn't like receiving __GFP_ZERO. This overrides kmalloc() to intercept the flags and direct the call to the right function. Signed-off-by: Jesse Gross <jesse@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
-rw-r--r--datapath/linux/compat/include/linux/slab.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/datapath/linux/compat/include/linux/slab.h b/datapath/linux/compat/include/linux/slab.h
index 7e9c3f4e2..9d6ad1f99 100644
--- a/datapath/linux/compat/include/linux/slab.h
+++ b/datapath/linux/compat/include/linux/slab.h
@@ -11,4 +11,21 @@ extern void *kmemdup(const void *src, size_t len, gfp_t gfp);
#define kmem_cache_create(n, s, a, f, c) kmem_cache_create(n, s, a, f, c, NULL)
#endif
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
+static inline void *rpl_kzalloc(size_t size, gfp_t flags)
+{
+ return kzalloc(size, flags & ~__GFP_ZERO);
+}
+#define kzalloc rpl_kzalloc
+
+static inline void *rpl_kmalloc(size_t size, gfp_t flags)
+{
+ if (flags & __GFP_ZERO)
+ return kzalloc(size, flags);
+
+ return kmalloc(size, flags);
+}
+#define kmalloc rpl_kmalloc
+#endif
+
#endif