]> xenbits.xensource.com Git - xen.git/commitdiff
xenoprof: avoid division by 0
authorTim Deegan <tim@xen.org>
Fri, 22 Feb 2013 12:58:04 +0000 (13:58 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 22 Feb 2013 12:58:04 +0000 (13:58 +0100)
Signed-off-by: Tim Deegan <tim@xen.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
master changeset: 085f1f2d3aee1a35dfc7ca2f4423e51fa654010c
master date: 2013-02-15 09:42:02 +0100

xen/common/xenoprof.c

index ea4ebf1e1641d382e20126329f941b8a0b2312f6..6d34418bce24e775028e70a39e40289163eb4ccc 100644 (file)
@@ -192,6 +192,13 @@ static int alloc_xenoprof_struct(
     unsigned max_max_samples;
     int i;
 
+    nvcpu = 0;
+    for_each_vcpu ( d, v )
+        nvcpu++;
+
+    if ( !nvcpu )
+        return -EINVAL;
+
     d->xenoprof = xmalloc(struct xenoprof);
 
     if ( d->xenoprof == NULL )
@@ -213,10 +220,6 @@ static int alloc_xenoprof_struct(
 
     memset(d->xenoprof->vcpu, 0, d->max_vcpus * sizeof(*d->xenoprof->vcpu));
 
-    nvcpu = 0;
-    for_each_vcpu ( d, v )
-        nvcpu++;
-
     bufsize = sizeof(struct xenoprof_buf);
     i = sizeof(struct event_log);
 #ifdef CONFIG_COMPAT