[ofa-general] Re: [PATCH ofed-1.2.c] ehca: backport kmem_cache_zalloc() for 2.6.10/sles10/sles10_sp1

Michael S. Tsirkin mst at dev.mellanox.co.il
Tue Aug 7 06:13:29 PDT 2007


I'm happy with stuff as it is: the ifdefs make it easy to figure
which version does the backport apply.

BTW, I think the same backport will be needed for older kernels as well, no?


Quoting Hoang-Nam Nguyen <hnguyen at linux.vnet.ibm.com>:
Subject: Re: [PATCH ofed-1.2.c] ehca: backport kmem_cache_zalloc() for 2.6.10/sles10/sles10_sp1

Hello Michael!
Below is the patch to backport kmem_cache_zalloc() for 2.6.16/sles10/sles10_sp1
as we've discussed previously. Thereby I realized current backport code
in slab.h looks weird to me (sort of copy&paste mixture) - actually no build
error, only coding "issue". 
Therefore this patch also includes some cleanup. If it's ok, please apply.
PS: The mentioned issue in backport slab.h exists also in other versions.
If you want me to fix them as well, let me know.
Regards
Nam


backport kmem_cache_zalloc() in slab.h to 2.6.10, 2.6.10_sles10 and 2.6.10_sles10_sp1

Signed-off-by: Hoang-Nam Nguyen <hnguyen at de.ibm.com>
---

 2.6.16/include/linux/slab.h            |   22 +++++++---------------
 2.6.16_sles10/include/linux/slab.h     |   22 +++++++---------------
 2.6.16_sles10_sp1/include/linux/slab.h |   22 +++++++---------------
 3 files changed, 21 insertions(+), 45 deletions(-)

diff -Nurp ofa_1_2_c_kernel-20070804-0200_orig/kernel_addons/backport/2.6.16/include/linux/slab.h ofa_1_2_c_kernel-20070804-0200/kernel_addons/backport/2.6.16/include/linux/slab.h
--- ofa_1_2_c_kernel-20070804-0200_orig/kernel_addons/backport/2.6.16/include/linux/slab.h	2007-08-04 11:00:08.000000000 +0200
+++ ofa_1_2_c_kernel-20070804-0200/kernel_addons/backport/2.6.16/include/linux/slab.h	2007-08-06 18:29:17.000000000 +0200
@@ -1,10 +1,8 @@
-#include_next <linux/slab.h>
+#ifndef _LINUX_SLAB_BACKPORT_TO_2_6_16
+#define _LINUX_SLAB_BACKPORT_TO_2_6_16
 
 #include_next <linux/slab.h>
 
-#ifndef BACKPORT_LINUX_STRING_TO_2_6_18
-#define BACKPORT_LINUX_STRING_TO_2_6_18
-
 static inline
 void *kmemdup(const void *src, size_t len, gfp_t gfp)
 {
@@ -16,19 +14,13 @@ void *kmemdup(const void *src, size_t le
        return p;
 }
 
-#endif
-#ifndef BACKPORT_LINUX_STRING_TO_2_6_18
-#define BACKPORT_LINUX_STRING_TO_2_6_18
-
 static inline
-void *kmemdup(const void *src, size_t len, gfp_t gfp)
+void *kmem_cache_zalloc(struct kmem_cache *cache, gfp_t flags)
 {
-       void *p;
-
-       p = kmalloc(len, gfp);
-       if (p)
-               memcpy(p, src, len);
-       return p;
+	void *ret = kmem_cache_alloc(cache, flags);
+	if (ret)
+		memset(ret, 0, kmem_cache_size(cache));
+	return ret;
 }
 
 #endif
diff -Nurp ofa_1_2_c_kernel-20070804-0200_orig/kernel_addons/backport/2.6.16_sles10/include/linux/slab.h ofa_1_2_c_kernel-20070804-0200/kernel_addons/backport/2.6.16_sles10/include/linux/slab.h
--- ofa_1_2_c_kernel-20070804-0200_orig/kernel_addons/backport/2.6.16_sles10/include/linux/slab.h	2007-08-04 11:00:08.000000000 +0200
+++ ofa_1_2_c_kernel-20070804-0200/kernel_addons/backport/2.6.16_sles10/include/linux/slab.h	2007-08-06 18:30:33.000000000 +0200
@@ -1,10 +1,8 @@
-#include_next <linux/slab.h>
+#ifndef _LINUX_SLAB_BACKPORT_TO_2_6_16
+#define _LINUX_SLAB_BACKPORT_TO_2_6_16
 
 #include_next <linux/slab.h>
 
-#ifndef BACKPORT_LINUX_STRING_TO_2_6_18
-#define BACKPORT_LINUX_STRING_TO_2_6_18
-
 static inline
 void *kmemdup(const void *src, size_t len, gfp_t gfp)
 {
@@ -16,19 +14,13 @@ void *kmemdup(const void *src, size_t le
        return p;
 }
 
-#endif
-#ifndef BACKPORT_LINUX_STRING_TO_2_6_18
-#define BACKPORT_LINUX_STRING_TO_2_6_18
-
 static inline
-void *kmemdup(const void *src, size_t len, gfp_t gfp)
+void *kmem_cache_zalloc(struct kmem_cache *cache, gfp_t flags)
 {
-       void *p;
-
-       p = kmalloc(len, gfp);
-       if (p)
-               memcpy(p, src, len);
-       return p;
+	void *ret = kmem_cache_alloc(cache, flags);
+	if (ret)
+		memset(ret, 0, kmem_cache_size(cache));
+	return ret;
 }
 
 #endif
diff -Nurp ofa_1_2_c_kernel-20070804-0200_orig/kernel_addons/backport/2.6.16_sles10_sp1/include/linux/slab.h ofa_1_2_c_kernel-20070804-0200/kernel_addons/backport/2.6.16_sles10_sp1/include/linux/slab.h
--- ofa_1_2_c_kernel-20070804-0200_orig/kernel_addons/backport/2.6.16_sles10_sp1/include/linux/slab.h	2007-08-04 11:00:08.000000000 +0200
+++ ofa_1_2_c_kernel-20070804-0200/kernel_addons/backport/2.6.16_sles10_sp1/include/linux/slab.h	2007-08-06 18:30:40.000000000 +0200
@@ -1,10 +1,8 @@
-#include_next <linux/slab.h>
+#ifndef _LINUX_SLAB_BACKPORT_TO_2_6_16
+#define _LINUX_SLAB_BACKPORT_TO_2_6_16
 
 #include_next <linux/slab.h>
 
-#ifndef BACKPORT_LINUX_STRING_TO_2_6_18
-#define BACKPORT_LINUX_STRING_TO_2_6_18
-
 static inline
 void *kmemdup(const void *src, size_t len, gfp_t gfp)
 {
@@ -16,19 +14,13 @@ void *kmemdup(const void *src, size_t le
        return p;
 }
 
-#endif
-#ifndef BACKPORT_LINUX_STRING_TO_2_6_18
-#define BACKPORT_LINUX_STRING_TO_2_6_18
-
 static inline
-void *kmemdup(const void *src, size_t len, gfp_t gfp)
+void *kmem_cache_zalloc(struct kmem_cache *cache, gfp_t flags)
 {
-       void *p;
-
-       p = kmalloc(len, gfp);
-       if (p)
-               memcpy(p, src, len);
-       return p;
+	void *ret = kmem_cache_alloc(cache, flags);
+	if (ret)
+		memset(ret, 0, kmem_cache_size(cache));
+	return ret;
 }
 
 #endif

-- 
MST



More information about the general mailing list