WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] cpupool: Fix __cpupool_find_by_id(), clea

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] cpupool: Fix __cpupool_find_by_id(), clean up accessor functions.
From: Xen patchbot-unstable <patchbot@xxxxxxx>
Date: Thu, 10 Feb 2011 06:10:17 -0800
Delivery-date: Thu, 10 Feb 2011 06:10:40 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir@xxxxxxx>
# Date 1297241623 0
# Node ID 8ef21ac0b464f244f7d72f768436a1137ddb8aeb
# Parent  fc986c1314bc8d061aa9f0bebc0eb40624089d4b
cpupool: Fix __cpupool_find_by_id(), clean up accessor functions.

Firstly, __cpupool_find_by_id() would dereference NULL, at the end of
an exact search if the search loop exited with *q==NULL. Fix this.

Secondly, provide suitable accessor functions so that no caller needs
to use the __-prefixed versions which take a boolean flag.

Signed-off-by: Keir Fraser <keir@xxxxxxx>
---
 xen/common/cpupool.c |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)

diff -r fc986c1314bc -r 8ef21ac0b464 xen/common/cpupool.c
--- a/xen/common/cpupool.c      Wed Feb 09 08:44:38 2011 +0000
+++ b/xen/common/cpupool.c      Wed Feb 09 08:53:43 2011 +0000
@@ -53,7 +53,7 @@ static void free_cpupool_struct(struct c
  * the searched id is returned
  * returns NULL if not found.
  */
-static struct cpupool *cpupool_find_by_id(int id, int exact)
+static struct cpupool *__cpupool_find_by_id(int id, int exact)
 {
     struct cpupool **q;
 
@@ -63,14 +63,19 @@ static struct cpupool *cpupool_find_by_i
         if ( (*q)->cpupool_id >= id )
             break;
 
-    return (!exact || ((*q)->cpupool_id == id)) ? *q : NULL;
+    return (!exact || (*q == NULL) || ((*q)->cpupool_id == id)) ? *q : NULL;
+}
+
+static struct cpupool *cpupool_find_by_id(int poolid)
+{
+    return __cpupool_find_by_id(poolid, 1);
 }
 
 static struct cpupool *__cpupool_get_by_id(int poolid, int exact)
 {
     struct cpupool *c;
     spin_lock(&cpupool_lock);
-    c = cpupool_find_by_id(poolid, exact);
+    c = __cpupool_find_by_id(poolid, exact);
     if ( c != NULL )
         atomic_inc(&c->refcnt);
     spin_unlock(&cpupool_lock);
@@ -80,6 +85,11 @@ struct cpupool *cpupool_get_by_id(int po
 struct cpupool *cpupool_get_by_id(int poolid)
 {
     return __cpupool_get_by_id(poolid, 1);
+}
+
+static struct cpupool *cpupool_get_next_by_id(int poolid)
+{
+    return __cpupool_get_by_id(poolid, 0);
 }
 
 void cpupool_put(struct cpupool *pool)
@@ -351,7 +361,7 @@ int cpupool_add_domain(struct domain *d,
     if ( poolid == CPUPOOLID_NONE )
         return 0;
     spin_lock(&cpupool_lock);
-    c = cpupool_find_by_id(poolid, 1);
+    c = cpupool_find_by_id(poolid);
     if ( (c != NULL) && cpus_weight(c->cpu_valid) )
     {
         c->n_dom++;
@@ -457,7 +467,7 @@ int cpupool_do_sysctl(struct xen_sysctl_
 
     case XEN_SYSCTL_CPUPOOL_OP_INFO:
     {
-        c = __cpupool_get_by_id(op->cpupool_id, 0);
+        c = cpupool_get_next_by_id(op->cpupool_id);
         ret = -ENOENT;
         if ( c == NULL )
             break;
@@ -485,7 +495,7 @@ int cpupool_do_sysctl(struct xen_sysctl_
         ret = -EBUSY;
         if ( !cpu_isset(cpu, cpupool_free_cpus) )
             goto addcpu_out;
-        c = cpupool_find_by_id(op->cpupool_id, 1);
+        c = cpupool_find_by_id(op->cpupool_id);
         ret = -ENOENT;
         if ( c == NULL )
             goto addcpu_out;
@@ -501,7 +511,7 @@ int cpupool_do_sysctl(struct xen_sysctl_
     {
         unsigned cpu;
 
-        c = __cpupool_get_by_id(op->cpupool_id, 1);
+        c = cpupool_get_by_id(op->cpupool_id);
         ret = -ENOENT;
         if ( c == NULL )
             break;
@@ -540,7 +550,7 @@ int cpupool_do_sysctl(struct xen_sysctl_
                         d->domain_id, op->cpupool_id);
         ret = -ENOENT;
         spin_lock(&cpupool_lock);
-        c = cpupool_find_by_id(op->cpupool_id, 1);
+        c = cpupool_find_by_id(op->cpupool_id);
         if ( (c != NULL) && cpus_weight(c->cpu_valid) )
         {
             d->cpupool->n_dom--;

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] cpupool: Fix __cpupool_find_by_id(), clean up accessor functions., Xen patchbot-unstable <=