From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E609C11F67 for ; Tue, 29 Jun 2021 17:21:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 20DE061D8E for ; Tue, 29 Jun 2021 17:21:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234069AbhF2RYE (ORCPT ); Tue, 29 Jun 2021 13:24:04 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:45275 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234009AbhF2RYE (ORCPT ); Tue, 29 Jun 2021 13:24:04 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212]) by youngberry.canonical.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lyHQS-00034B-QX; Tue, 29 Jun 2021 17:21:32 +0000 Subject: Re: [PATCH][next] trace: osnoise: Fix u64 less than zero comparison To: Daniel Bristot de Oliveira , Steven Rostedt Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, Dan Carpenter , Ingo Molnar References: <20210629165245.42157-1-colin.king@canonical.com> From: Colin Ian King Message-ID: Date: Tue, 29 Jun 2021 18:21:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: kernel-janitors@vger.kernel.org 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 >> >> 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 > > 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; >> >