Add kzalloc and kcalloc kernel compatibility functions.
authorIan Abbott <abbotti@mev.co.uk>
Fri, 14 Sep 2007 12:32:49 +0000 (12:32 +0000)
committerIan Abbott <abbotti@mev.co.uk>
Fri, 14 Sep 2007 12:32:49 +0000 (12:32 +0000)
include/linux/slab.h [new file with mode: 0644]

diff --git a/include/linux/slab.h b/include/linux/slab.h
new file mode 100644 (file)
index 0000000..61e5051
--- /dev/null
@@ -0,0 +1,30 @@
+
+#ifndef __COMPAT_LINUX_SLAB_H
+#define __COMPAT_LINUX_SLAB_H
+
+#include <linux/version.h>
+#include <linux/string.h>
+
+#include_next <linux/slab.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
+
+static inline void *kzalloc(size_t size, unsigned int flags)
+{
+       void *ret = kmalloc(size, flags);
+       if (ret)
+               memset(ret, 0, size);
+       return ret;
+}
+
+static inline void *kcalloc(size_t n, size_t size, unsigned int flags)
+{
+       if (n != 0 && size > INT_MAX / n)
+               return NULL;
+       return kzalloc(n * size, flags);
+}
+
+#endif
+
+#endif
+