Skip to content

Commit

Permalink
ring-buffer: check for divide by zero in ring-buffer-benchmark
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Steven Rostedt authored and Steven Rostedt committed May 11, 2009
1 parent 5a772b2 commit d988ff9
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions kernel/trace/ring_buffer_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d988ff9

Please sign in to comment.