Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

trace/osnoise: Make 'noise' variable s64 in run_osnoise()

Dab Carpenter reported that:

The patch bce29ac9ce0b: "trace: Add osnoise tracer" from Jun 22,
2021, leads to the following static checker warning:

kernel/trace/trace_osnoise.c:1103 run_osnoise()
warn: unsigned 'noise' is never less than zero.

In this part of the code:

1100 /*
1101 * This shouldn't happen.
1102 */
1103 if (noise < 0) {
^^^^^^^^^
1104 osnoise_taint("negative noise!");
1105 goto out;
1106 }
1107

And the static checker is right because 'noise' is u64.

Make noise s64 and keep the check. It is important to check if
the time read is behaving correctly - so we can trust the results.

I also re-arranged some variable declarations.

Link: https://lkml.kernel.org/r/acd7cd6e7d56b798a298c3bc8139a390b3c4ab52.1624986368.git.bristot@redhat.com

Cc: Ingo Molnar <mingo@redhat.com>
Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: linux-kernel@vger.kernel.org
Fixes: bce29ac9ce0b ("trace: Add osnoise tracer")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Daniel Bristot de Oliveira <bristot@redhat.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

authored by

Daniel Bristot de Oliveira and committed by
Steven Rostedt (VMware)
19c3eaa7 9913d574

+3 -2
+3 -2
kernel/trace/trace_osnoise.c
··· 1042 1042 static int run_osnoise(void) 1043 1043 { 1044 1044 struct osnoise_variables *osn_var = this_cpu_osn_var(); 1045 - u64 noise = 0, sum_noise = 0, max_noise = 0; 1046 1045 struct trace_array *tr = osnoise_trace; 1047 1046 u64 start, sample, last_sample; 1048 1047 u64 last_int_count, int_count; 1048 + s64 noise = 0, max_noise = 0; 1049 1049 s64 total, last_total = 0; 1050 1050 struct osnoise_sample s; 1051 1051 unsigned int threshold; 1052 - int hw_count = 0; 1053 1052 u64 runtime, stop_in; 1053 + u64 sum_noise = 0; 1054 + int hw_count = 0; 1054 1055 int ret = -1; 1055 1056 1056 1057 /*