summaryrefslogtreecommitdiffstats
path: root/kernel/trace/ring_buffer_benchmark.c
diff options
context:
space:
mode:
authorSteven Rostedt2009-05-08 17:03:57 +0200
committerSteven Rostedt2009-05-11 19:22:26 +0200
commitd988ff94c1074c4c914235c8591bcceafb585ecf (patch)
tree46dc84aa84e04ae92cd66ed5cbf7a55452dcdb1c /kernel/trace/ring_buffer_benchmark.c
parentring-buffer: replace constants with time macros in ring-buffer-benchmark (diff)
downloadkernel-qcow2-linux-d988ff94c1074c4c914235c8591bcceafb585ecf.tar.gz
kernel-qcow2-linux-d988ff94c1074c4c914235c8591bcceafb585ecf.tar.xz
kernel-qcow2-linux-d988ff94c1074c4c914235c8591bcceafb585ecf.zip
ring-buffer: check for divide by zero in ring-buffer-benchmark
Although we check if "missed" is not zero, we divide by hit + missed, and the addition can possible overflow and become a divide by zero. This patch checks for this case, and will report it when it happens then modify "hit" to make the calculation be non zero. [ Impact: prevent possible divide by zero in ring-buffer-benchmark ] Reported-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace/ring_buffer_benchmark.c')
-rw-r--r--kernel/trace/ring_buffer_benchmark.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/kernel/trace/ring_buffer_benchmark.c b/kernel/trace/ring_buffer_benchmark.c
index 7d3aef93c49f..8d68e149a8b3 100644
--- a/kernel/trace/ring_buffer_benchmark.c
+++ b/kernel/trace/ring_buffer_benchmark.c
@@ -294,6 +294,12 @@ static void ring_buffer_producer(void)
pr_info("Total iterations per millisec: %ld\n", hit + missed);
+ /* it is possible that hit + missed will overflow and be zero */
+ if (!(hit + missed)) {
+ pr_info("hit + missed overflowed and totalled zero!\n");
+ hit--; /* make it non zero */
+ }
+
/* Caculate the average time in nanosecs */
avg = NSEC_PER_MSEC / (hit + missed);
pr_info("%ld ns per entry\n", avg);