Subject: [PATCH 1/2] 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.

Cc: Steven Rostedt <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Daniel Bristot de Oliveira <[email protected]>
Cc: Dan Carpenter <[email protected]>
Cc: [email protected]
Fixes: bce29ac9ce0b ("trace: Add osnoise tracer")
Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Daniel Bristot de Oliveira <[email protected]>
---
kernel/trace/trace_osnoise.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
index 085a83de98ad..cc1faca1a620 100644
--- a/kernel/trace/trace_osnoise.c
+++ b/kernel/trace/trace_osnoise.c
@@ -1042,15 +1042,16 @@ static void osnoise_stop_tracing(void)
static int run_osnoise(void)
{
struct osnoise_variables *osn_var = this_cpu_osn_var();
- u64 noise = 0, sum_noise = 0, max_noise = 0;
struct trace_array *tr = osnoise_trace;
u64 start, sample, last_sample;
u64 last_int_count, int_count;
+ s64 noise = 0, max_noise = 0;
s64 total, last_total = 0;
struct osnoise_sample s;
unsigned int threshold;
- int hw_count = 0;
u64 runtime, stop_in;
+ u64 sum_noise = 0;
+ int hw_count = 0;
int ret = -1;

/*
--
2.31.1


Subject: [PATCH 2/2] trace/timerlat: Fix indentation on timerlat_main()

Dan Carpenter reported that:

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

kernel/trace/trace_osnoise.c:1400 timerlat_main()
warn: inconsistent indenting

here:
1389 while (!kthread_should_stop()) {
1390 now = ktime_to_ns(hrtimer_cb_get_time(&tlat->timer));
1391 diff = now - tlat->abs_period;
1392
1393 s.seqnum = tlat->count;
1394 s.timer_latency = diff;
1395 s.context = THREAD_CONTEXT;
1396
1397 trace_timerlat_sample(&s);
1398
1399 #ifdef CONFIG_STACKTRACE
1400 if (osnoise_data.print_stack)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This should be indented another tab?

1401 if (osnoise_data.print_stack <= time_to_us(diff))
1402 timerlat_dump_stack();
1403 #endif /* CONFIG_STACKTRACE */
1404
1405 tlat->tracing_thread = false;
1406 if (osnoise_data.stop_tracing_total)
1407 if (time_to_us(diff) >= osnoise_data.stop_tracing_total)
1408 osnoise_stop_tracing();
1409
1410 wait_next_period(tlat);
1411 }

And the static checker is right. Fix the indentation.

Cc: Steven Rostedt <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Daniel Bristot de Oliveira <[email protected]>
Cc: Dan Carpenter <[email protected]>
Cc: [email protected]
Fixes: a955d7eac177 ("trace: Add timerlat tracer")
Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Daniel Bristot de Oliveira <[email protected]>
---
kernel/trace/trace_osnoise.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
index cc1faca1a620..a7e3c24dee13 100644
--- a/kernel/trace/trace_osnoise.c
+++ b/kernel/trace/trace_osnoise.c
@@ -1403,9 +1403,9 @@ static int timerlat_main(void *data)
trace_timerlat_sample(&s);

#ifdef CONFIG_STACKTRACE
- if (osnoise_data.print_stack)
- if (osnoise_data.print_stack <= time_to_us(diff))
- timerlat_dump_stack();
+ if (osnoise_data.print_stack)
+ if (osnoise_data.print_stack <= time_to_us(diff))
+ timerlat_dump_stack();
#endif /* CONFIG_STACKTRACE */

tlat->tracing_thread = false;
--
2.31.1