xenoprof: avoid division by 0
authorTim Deegan <tim@xen.org>
Fri, 15 Feb 2013 08:42:02 +0000 (09:42 +0100)
committerTim Deegan <tim@xen.org>
Fri, 15 Feb 2013 08:42:02 +0000 (09:42 +0100)
Signed-off-by: Tim Deegan <tim@xen.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
Committed-by: Jan Beulich <jbeulich@suse.com>
xen/common/xenoprof.c

index 220f1c77855b46e47941870881bc75199443f97f..03ec614f58b6f16364d20ccd8b12c0120a7a6377 100644 (file)
@@ -193,6 +193,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 = xzalloc(struct xenoprof);
     if ( d->xenoprof == NULL )
     {
@@ -209,10 +216,6 @@ static int alloc_xenoprof_struct(
         return -ENOMEM;
     }
 
-    nvcpu = 0;
-    for_each_vcpu ( d, v )
-        nvcpu++;
-
     bufsize = sizeof(struct xenoprof_buf);
     i = sizeof(struct event_log);
 #ifdef CONFIG_COMPAT