cpumask: introduce zalloc_cpumask_var [Linux 2.6.30]

This Linux kernel change "cpumask: introduce zalloc_cpumask_var" is included in the Linux 2.6.30 release. This change is authored by Yinghai Lu <yinghai [at] kernel.org> on Sat Jun 6 14:50:36 2009 -0700. The commit for this change in Linux stable tree is 0281b5d (patch).

cpumask: introduce zalloc_cpumask_var

So can get cpumask_var with cpumask_clear

Signed-off-by: Yinghai Lu <[email protected]>
Signed-off-by: Rusty Russell <[email protected]>

There are 27 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 include/linux/cpumask.h | 15 +++++++++++++++
 lib/cpumask.c           | 12 ++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 9f31538..c5ac87c 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -1022,6 +1022,8 @@ static inline size_t cpumask_size(void)

 bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node);
 bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags);
+bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node);
+bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags);
 void alloc_bootmem_cpumask_var(cpumask_var_t *mask);
 void free_cpumask_var(cpumask_var_t mask);
 void free_bootmem_cpumask_var(cpumask_var_t mask);
@@ -1040,6 +1042,19 @@ static inline bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags,
    return true;
 }

+static inline bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
+{
+   cpumask_clear(*mask);
+   return true;
+}
+
+static inline bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags,
+                     int node)
+{
+   cpumask_clear(*mask);
+   return true;
+}
+
 static inline void alloc_bootmem_cpumask_var(cpumask_var_t *mask)
 {
 }
diff --git a/lib/cpumask.c b/lib/cpumask.c
index 1f71b97..eb23aaa 100644
--- a/lib/cpumask.c
+++ b/lib/cpumask.c
@@ -119,6 +119,12 @@ bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node)
 }
 EXPORT_SYMBOL(alloc_cpumask_var_node);

+bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node)
+{
+   return alloc_cpumask_var_node(mask, flags | __GFP_ZERO, node);
+}
+EXPORT_SYMBOL(zalloc_cpumask_var_node);
+
 /**
  * alloc_cpumask_var - allocate a struct cpumask
  * @mask: pointer to cpumask_var_t where the cpumask is returned
@@ -135,6 +141,12 @@ bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
 }
 EXPORT_SYMBOL(alloc_cpumask_var);

+bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
+{
+   return alloc_cpumask_var(mask, flags | __GFP_ZERO);
+}
+EXPORT_SYMBOL(zalloc_cpumask_var);
+
 /**
  * alloc_bootmem_cpumask_var - allocate a struct cpumask from the bootmem arena.
  * @mask: pointer to cpumask_var_t where the cpumask is returned

Leave a Reply

Your email address will not be published. Required fields are marked *