Skip to contentSkip to conversation

trace: osnoise: Fix u64 less than zero comparison

PATCH In review Colin King 4 participants 6 messages Jun 29, 2021 – Jun 30, 2021

Subsystems (3)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 trace: osnoise: Fix u64 less than zero comparison

From: Colin Ian King <[email protected]>

The less than zero comparison of the u64 variable 'noise' is always false because the variable is unsigned. Since the time_sub macro can potentially return an -ve vale, make the variable a s64 to fix the issue.

Addresses-Coverity: ("Unsigned compared against 0")

Fixes bce29ac9ce0b ("trace: Add osnoise tracer")
---
 kernel/trace/trace_osnoise.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace_osnoise.c +2 -2
index 38aa5e208ffd..02c984560ceb 100644
@@ -1040,11 +1040,11 @@ 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;
+	u64 sum_noise = 0, max_noise = 0;
 	struct trace_array *tr = osnoise_trace;
 	u64 start, sample, last_sample;
 	u64 last_int_count, int_count;
-	s64 total, last_total = 0;
+	s64 noise = 0, total, last_total = 0;
 	struct osnoise_sample s;
 	unsigned int threshold;
 	int hw_count = 0;
Signature · 1 line
2.31.1
#1 lore raw
Quoted 6 lines · Colin King

From: Colin Ian King <[email protected]>

The less than zero comparison of the u64 variable 'noise' is always false because the variable is unsigned. Since the time_sub macro can potentially return an -ve vale, make the variable a s64 to fix the issue.

Ops! concurrent bug fixing.

Dan Carpenter reported the same bug (and another problem), and I was working in the patches... I saw yours after sending his ones:

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

The patches do the same fix, but there it also:

- Made also max_noise s64 (it is snapshot of noise).
- Arranged the declarations in the inverted christmas tree.

Quoted 3 lines

Addresses-Coverity: ("Unsigned compared against 0")

Fixes bce29ac9ce0b ("trace: Add osnoise tracer")

Steven, can we merge the flags?

-- Daniel

Quoted 23 lines
---
 kernel/trace/trace_osnoise.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace_osnoise.c +2 -2
index 38aa5e208ffd..02c984560ceb 100644
@@ -1040,11 +1040,11 @@ 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;
+	u64 sum_noise = 0, max_noise = 0;
 	struct trace_array *tr = osnoise_trace;
 	u64 start, sample, last_sample;
 	u64 last_int_count, int_count;
-	s64 total, last_total = 0;
+	s64 noise = 0, total, last_total = 0;
 	struct osnoise_sample s;
 	unsigned int threshold;
 	int hw_count = 0;
#2 lore raw
Quoted 9 lines · Daniel Bristot de Oliveira
Quoted 6 lines · Colin King

From: Colin Ian King <[email protected]>

The less than zero comparison of the u64 variable 'noise' is always false because the variable is unsigned. Since the time_sub macro can potentially return an -ve vale, make the variable a s64 to fix the issue.

Ops! concurrent bug fixing.

Well, shows static analysis is doing it's thing and I'm not being vigilant enough by spotting that Dan found it earlier :-)

Quoted 43 lines

Dan Carpenter reported the same bug (and another problem), and I was working in the patches... I saw yours after sending his ones:

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

The patches do the same fix, but there it also:

- Made also max_noise s64 (it is snapshot of noise).
- Arranged the declarations in the inverted christmas tree.

Quoted 3 lines

Addresses-Coverity: ("Unsigned compared against 0")

Fixes bce29ac9ce0b ("trace: Add osnoise tracer")

Steven, can we merge the flags?

-- Daniel

Quoted 23 lines
---
 kernel/trace/trace_osnoise.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace_osnoise.c +2 -2
index 38aa5e208ffd..02c984560ceb 100644
@@ -1040,11 +1040,11 @@ 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;
+	u64 sum_noise = 0, max_noise = 0;
 	struct trace_array *tr = osnoise_trace;
 	u64 start, sample, last_sample;
 	u64 last_int_count, int_count;
-	s64 total, last_total = 0;
+	s64 noise = 0, total, last_total = 0;
 	struct osnoise_sample s;
 	unsigned int threshold;
 	int hw_count = 0;
#3 lore raw
Quoted 9 lines · Colin Ian King
Quoted 8 lines · Daniel Bristot de Oliveira
Quoted 6 lines · Colin King

From: Colin Ian King <[email protected]>

The less than zero comparison of the u64 variable 'noise' is always false because the variable is unsigned. Since the time_sub macro can potentially return an -ve vale, make the variable a s64 to fix the issue.

Quoted 4 lines
Quoted 1 line

Ops! concurrent bug fixing.

Well, shows static analysis is doing it's thing and I'm not being vigilant enough by spotting that Dan found it earlier :-)

Nah. I don't normally CC kernel-janitors on bug reports. I sometimes do on netdev stuff because Dave told me ten years ago that static analysis noise on the list was an annoying thing. And actually on that one I didn't CC anyone actually, Oops.

regards,
dan carpenter

maintainer
#4 lore raw
In reply to Daniel Bristot de Oliveira
Quoted 5 lines · On Tue, 29 Jun 2021 19:19:25 +0200 Daniel Bristot de Oliveira…
Quoted 3 lines

Addresses-Coverity: ("Unsigned compared against 0")

Fixes bce29ac9ce0b ("trace: Add osnoise tracer")

Steven, can we merge the flags?

I don't usually do that. I just take the first patch that I apply.

This isn't that complex of a patch, do we need to do this?

-- Steve

#5 lore raw
Quoted 8 lines · Steven Rostedt
Quoted 4 lines · On Tue, 29 Jun 2021 19:19:25 +0200 Daniel Bristot de Oliveira…
Quoted 3 lines

Addresses-Coverity: ("Unsigned compared against 0")

Fixes bce29ac9ce0b ("trace: Add osnoise tracer")

Steven, can we merge the flags?

I don't usually do that.

Ack!

-- Daniel