Skip to content

Commit

Permalink
tracing: Use div64_u64() instead of do_div()
Browse files Browse the repository at this point in the history
Fixes Coccinelle/coccicheck warnings reported by do_div.cocci.

Compared to do_div(), div64_u64() does not implicitly cast the divisor and
does not unnecessarily calculate the remainder.

Link: https://lore.kernel.org/linux-trace-kernel/[email protected]

Cc: Mathieu Desnoyers <[email protected]>
Signed-off-by: Thorsten Blum <[email protected]>
Acked-by: Masami Hiramatsu (Google) <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
  • Loading branch information
toblux authored and rostedt committed Mar 18, 2024
1 parent 19f0423 commit d6cb38e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions kernel/trace/trace_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ static void trace_do_benchmark(void)
bm_total += delta;
bm_totalsq += delta * delta;


if (bm_cnt > 1) {
/*
* Apply Welford's method to calculate standard deviation:
Expand All @@ -105,7 +104,7 @@ static void trace_do_benchmark(void)
stddev = 0;

delta = bm_total;
do_div(delta, bm_cnt);
delta = div64_u64(delta, bm_cnt);
avg = delta;

if (stddev > 0) {
Expand All @@ -127,7 +126,7 @@ static void trace_do_benchmark(void)
seed = stddev;
if (!last_seed)
break;
do_div(seed, last_seed);
seed = div64_u64(seed, last_seed);
seed += last_seed;
do_div(seed, 2);
} while (i++ < 10 && last_seed != seed);
Expand Down

0 comments on commit d6cb38e

Please sign in to comment.