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=-8.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 97507C433B4 for ; Fri, 30 Apr 2021 12:53:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5BEF661449 for ; Fri, 30 Apr 2021 12:53:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232369AbhD3Myk (ORCPT ); Fri, 30 Apr 2021 08:54:40 -0400 Received: from mga09.intel.com ([134.134.136.24]:57689 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232291AbhD3Myj (ORCPT ); Fri, 30 Apr 2021 08:54:39 -0400 IronPort-SDR: os7v8CntnBKRHHHain7lDoMCaZlZNqkty7Tl5l4wJAHrRvX+fdOvIsVZ3DutDWhwuXFgNQa0pU fAPPGk0gQgKg== X-IronPort-AV: E=McAfee;i="6200,9189,9969"; a="197365380" X-IronPort-AV: E=Sophos;i="5.82,262,1613462400"; d="scan'208";a="197365380" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Apr 2021 05:53:49 -0700 IronPort-SDR: 0rB17DpXMJC5/pBfj56152hcy6UD/jSFD1qUjHHiS1PQs07xvdx7dGVPGVSA95VfQlN4NyrGuw HFpq35LkY9gQ== X-IronPort-AV: E=Sophos;i="5.82,262,1613462400"; d="scan'208";a="537754564" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Apr 2021 05:53:47 -0700 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1lcSeO-008Q0T-O4; Fri, 30 Apr 2021 15:53:44 +0300 Date: Fri, 30 Apr 2021 15:53:44 +0300 From: Andy Shevchenko To: Dan Carpenter Cc: Greg Kroah-Hartman , Jiri Slaby , Vignesh Raghavendra , Alexander Sverdlin , Johan Hovold , linux-serial@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH] serial: 8250_omap: fix a timeout loop condition Message-ID: References: <20210429130215.GE21598@kadam> <20210430114106.GF1981@kadam> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210430114106.GF1981@kadam> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: kernel-janitors@vger.kernel.org On Fri, Apr 30, 2021 at 02:41:06PM +0300, Dan Carpenter wrote: > On Fri, Apr 30, 2021 at 11:46:07AM +0300, Andy Shevchenko wrote: > > On Thu, Apr 29, 2021 at 04:02:15PM +0300, Dan Carpenter wrote: > > > On Thu, Apr 29, 2021 at 02:08:45PM +0300, Andy Shevchenko wrote: > > > > On Thu, Apr 29, 2021 at 10:19:22AM +0300, Dan Carpenter wrote: > > > > > This loop ends on -1 so the error message will never be printed. > > > > > > > > > > Fixes: 4bcf59a5dea0 ("serial: 8250: 8250_omap: Account for data in flight during DMA teardown") > > > > > Signed-off-by: Dan Carpenter > > > > > > > > ... > > > > > > > > > poll_count--) > > > > > cpu_relax(); > > > > > > > > > > - if (!poll_count) > > > > > + if (poll_count == -1) > > > > > > > > Why not to change poll_count-- to --poll_count? > > > > > > > > > > Either one is fine. I considered several different ways and wrote the > > > patch twice. The downside of --poll_count is that it's an off by one > > > in that the author clearly intended to loop 25 times. It doesn't really > > > matter if we only loop 24 but off by ones are aesthetically unpleasant. > > > > I didn't get. If you use --poll_count you get exactly 25 times and moreover, > > you may convert variable to unsigned type. > > > > Here is a small test to show that it loops 24 times. > > #include > > int main(void) > { > int i = 25; > > while (--i) > printf("%d\n", i); > > return 0; > } > > gcc test.c > ./a.out | tac > > Why would I make it unsigned? As a static analysis developer, > pointlessly unsigned variables are one of the leading causes for the > bugs I see. > > There are times where a iterator counter needs to be unsigned long, or > u64 but I have never seen a case where changing an iterator from > "int i;" to "unsigned int i;" solves a real life kernel bug. It only > introduces bugs. See my followup to that, I meant unsigned int count; do { ... } while (--count); It doesn't solve bug, but prevents the code be read incorrectly like what you are fixing can be avoided with do {} while (); along with unsigned type. -- With Best Regards, Andy Shevchenko