kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] trace: osnoise: Fix u64 less than zero comparison
@ 2021-06-29 16:52 Colin King
  2021-06-29 17:19 ` Daniel Bristot de Oliveira
  0 siblings, 1 reply; 6+ messages in thread
From: Colin King @ 2021-06-29 16:52 UTC (permalink / raw)
  To: Steven Rostedt, Ingo Molnar, Daniel Bristot de Oliveira
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

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")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 kernel/trace/trace_osnoise.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
index 38aa5e208ffd..02c984560ceb 100644
--- a/kernel/trace/trace_osnoise.c
+++ b/kernel/trace/trace_osnoise.c
@@ -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.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH][next] trace: osnoise: Fix u64 less than zero comparison
  2021-06-29 16:52 [PATCH][next] trace: osnoise: Fix u64 less than zero comparison Colin King
@ 2021-06-29 17:19 ` Daniel Bristot de Oliveira
  2021-06-29 17:21   ` Colin Ian King
  2021-06-30 13:05   ` Steven Rostedt
  0 siblings, 2 replies; 6+ messages in thread
From: Daniel Bristot de Oliveira @ 2021-06-29 17:19 UTC (permalink / raw)
  To: Colin King, Steven Rostedt
  Cc: kernel-janitors, linux-kernel, Dan Carpenter, Ingo Molnar

On 6/29/21 6:52 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> 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.

> Addresses-Coverity: ("Unsigned compared against 0")
> Fixes: bce29ac9ce0b ("trace: Add osnoise tracer")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Steven, can we merge the flags?

-- Daniel

> ---
>  kernel/trace/trace_osnoise.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
> index 38aa5e208ffd..02c984560ceb 100644
> --- a/kernel/trace/trace_osnoise.c
> +++ b/kernel/trace/trace_osnoise.c
> @@ -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;
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][next] trace: osnoise: Fix u64 less than zero comparison
  2021-06-29 17:19 ` Daniel Bristot de Oliveira
@ 2021-06-29 17:21   ` Colin Ian King
  2021-06-29 18:55     ` Dan Carpenter
  2021-06-30 13:05   ` Steven Rostedt
  1 sibling, 1 reply; 6+ messages in thread
From: Colin Ian King @ 2021-06-29 17:21 UTC (permalink / raw)
  To: Daniel Bristot de Oliveira, Steven Rostedt
  Cc: kernel-janitors, linux-kernel, Dan Carpenter, Ingo Molnar

On 29/06/2021 18:19, Daniel Bristot de Oliveira wrote:
> On 6/29/21 6:52 PM, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> 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 :-)

> 
> 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.
> 
>> Addresses-Coverity: ("Unsigned compared against 0")
>> Fixes: bce29ac9ce0b ("trace: Add osnoise tracer")
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> 
> Steven, can we merge the flags?
> 
> -- Daniel
> 
>> ---
>>  kernel/trace/trace_osnoise.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
>> index 38aa5e208ffd..02c984560ceb 100644
>> --- a/kernel/trace/trace_osnoise.c
>> +++ b/kernel/trace/trace_osnoise.c
>> @@ -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;
>>
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][next] trace: osnoise: Fix u64 less than zero comparison
  2021-06-29 17:21   ` Colin Ian King
@ 2021-06-29 18:55     ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2021-06-29 18:55 UTC (permalink / raw)
  To: Colin Ian King
  Cc: Daniel Bristot de Oliveira, Steven Rostedt, kernel-janitors,
	linux-kernel, Ingo Molnar

On Tue, Jun 29, 2021 at 06:21:32PM +0100, Colin Ian King wrote:
> On 29/06/2021 18:19, Daniel Bristot de Oliveira wrote:
> > On 6/29/21 6:52 PM, Colin King wrote:
> >> From: Colin Ian King <colin.king@canonical.com>
> >>
> >> 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 :-)

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][next] trace: osnoise: Fix u64 less than zero comparison
  2021-06-29 17:19 ` Daniel Bristot de Oliveira
  2021-06-29 17:21   ` Colin Ian King
@ 2021-06-30 13:05   ` Steven Rostedt
  2021-06-30 13:32     ` Daniel Bristot de Oliveira
  1 sibling, 1 reply; 6+ messages in thread
From: Steven Rostedt @ 2021-06-30 13:05 UTC (permalink / raw)
  To: Daniel Bristot de Oliveira
  Cc: Colin King, kernel-janitors, linux-kernel, Dan Carpenter, Ingo Molnar

On Tue, 29 Jun 2021 19:19:25 +0200
Daniel Bristot de Oliveira <bristot@redhat.com> wrote:

> > Addresses-Coverity: ("Unsigned compared against 0")
> > Fixes: bce29ac9ce0b ("trace: Add osnoise tracer")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>  
> 
> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][next] trace: osnoise: Fix u64 less than zero comparison
  2021-06-30 13:05   ` Steven Rostedt
@ 2021-06-30 13:32     ` Daniel Bristot de Oliveira
  0 siblings, 0 replies; 6+ messages in thread
From: Daniel Bristot de Oliveira @ 2021-06-30 13:32 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Colin King, kernel-janitors, linux-kernel, Dan Carpenter, Ingo Molnar

On 6/30/21 3:05 PM, Steven Rostedt wrote:
> On Tue, 29 Jun 2021 19:19:25 +0200
> Daniel Bristot de Oliveira <bristot@redhat.com> wrote:
> 
>>> Addresses-Coverity: ("Unsigned compared against 0")
>>> Fixes: bce29ac9ce0b ("trace: Add osnoise tracer")
>>> Signed-off-by: Colin Ian King <colin.king@canonical.com>  
>> Steven, can we merge the flags?
> I don't usually do that. 

Ack!

-- Daniel


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-06-30 13:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-29 16:52 [PATCH][next] trace: osnoise: Fix u64 less than zero comparison Colin King
2021-06-29 17:19 ` Daniel Bristot de Oliveira
2021-06-29 17:21   ` Colin Ian King
2021-06-29 18:55     ` Dan Carpenter
2021-06-30 13:05   ` Steven Rostedt
2021-06-30 13:32     ` Daniel Bristot de Oliveira

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).