]> xenbits.xensource.com Git - xen.git/commitdiff
trace: improve check_tbuf_size()
authorKeir Fraser <keir.fraser@citrix.com>
Fri, 2 Jul 2010 17:53:10 +0000 (18:53 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Fri, 2 Jul 2010 17:53:10 +0000 (18:53 +0100)
It didn't consider the case of the incoming size not allowing for the
2*data_size range for t_buf->{prod,cons}

Signed-off-by: Jan Beulich <jbeulich@novell.com>
Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
xen/common/trace.c

index caf9b7f621d89c920093b7b6014eca4dfa7816b2..8d4f02a458220cc64918f03cf9f76f2568854cd7 100644 (file)
@@ -92,11 +92,19 @@ static void calc_tinfo_first_offset(void)
 
 /**
  * check_tbuf_size - check to make sure that the proposed size will fit
- * in the currently sized struct t_info.
+ * in the currently sized struct t_info and allows prod and cons to
+ * reach double the value without overflow.
  */
-static inline int check_tbuf_size(int size)
+static int check_tbuf_size(u32 pages)
 {
-    return (num_online_cpus() * size + t_info_first_offset) > (T_INFO_SIZE / sizeof(uint32_t));
+    struct t_buf dummy;
+    typeof(dummy.prod) size;
+    
+    size = ((typeof(dummy.prod))pages)  * PAGE_SIZE;
+    
+    return (size / PAGE_SIZE != pages)
+           || (size + size < size)
+           || (num_online_cpus() * pages + t_info_first_offset > T_INFO_SIZE / sizeof(uint32_t));
 }
 
 /**