Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2977639pxb; Fri, 12 Feb 2021 06:24:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJwSNQjDG1DMDGdM4JgO/QacMBt/xIQRXsZiVaJ6Y1rUL/j4yTtPKNDol+YY72UH02tEnxkq X-Received: by 2002:a1c:4b05:: with SMTP id y5mr2922036wma.37.1613139862699; Fri, 12 Feb 2021 06:24:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613139862; cv=none; d=google.com; s=arc-20160816; b=LIXlCqL6A3tv63RsHlj1/jpBCcVOp5Shb7ed0TLPfBGzk5rjwmtreMo8w7EiES4Qzr xrKAYM6k83b63wIiHpk6VMt0Ls7E8AuhIULSOlhJIvjrK+MavX3Gailr3okNIDw4u2oK HknNkmv+ZGtm4/clXZwQ9+oopJD9GqYBU0Y4hSXBxu1NKPYr6VF2HN2Wsu/yxZ6P28SP pXvhPw41a8Yy00INt/j4KSFLEu0ZJ7+MSwr+3Qr2Wcl7xBkpwll+TgRR3QyXA5kEGaU0 27FIXHeIQFHVvYzdjkUVGsoJC37LDmC7Tkjlc1m7f19pQH/7x1fADY06gZ13XuC7jIVh ZZMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=b+bPwNoXfbbzssO+4WGPd5v39slnQ1uFIi71ZzjFaUk=; b=E1ES106qHs0lQtzqHu7ehN9UQlf3acTHvRZs6W1GjC7WS9swGtmj7V3slv9OTLcqLg hf3MKxzbJabRmm/NyPGcmjULYreqe84qL0xlTeocP5FeAzImcAGmgOH/kE93WMgl5HRP 4KeZtM+RJrxUoH8NsaJ2KgnK1DNV5vBzbYC4wbABaKqsfYG53AT5dDaYEy0ePeyZ41bH SN+2cHpSlHp2ajklX3JBsDpIn6CjbDBbY+dzHo2VFHQY0qFYvvoY+4QxKMGnq3N9Zc4K J0J1f0712f+J/2j8tJDX1m1SwD2+toLDSreFn6WVkSQBTBw7VxtljaBQd/yP2KJsRkzw BKwQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jg13si7475408ejc.126.2021.02.12.06.23.59; Fri, 12 Feb 2021 06:24:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231865AbhBLOXd (ORCPT + 99 others); Fri, 12 Feb 2021 09:23:33 -0500 Received: from mx2.suse.de ([195.135.220.15]:60160 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231768AbhBLOXc (ORCPT ); Fri, 12 Feb 2021 09:23:32 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9BBE0B029; Fri, 12 Feb 2021 14:22:50 +0000 (UTC) Subject: Re: [PATCH][next] bcache: Use 64-bit arithmetic instead of 32-bit To: "Gustavo A. R. Silva" , Kent Overstreet , "David S. Miller" , Christina Jacob , Hariprasad Kelam , Sunil Goutham , Jesse Brandeburg Cc: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210212125028.GA264620@embeddedor> From: Coly Li Message-ID: Date: Fri, 12 Feb 2021 22:22:44 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <20210212125028.GA264620@embeddedor> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/12/21 8:50 PM, Gustavo A. R. Silva wrote: > Cast multiple variables to (int64_t) in order to give the compiler > complete information about the proper arithmetic to use. Notice that > these variables are being used in contexts that expect expressions of > type int64_t (64 bit, signed). And currently, such expressions are > being evaluated using 32-bit arithmetic. > > Fixes: d0cf9503e908 ("octeontx2-pf: ethtool fec mode support") > Addresses-Coverity-ID: 1501724 ("Unintentional integer overflow") > Addresses-Coverity-ID: 1501725 ("Unintentional integer overflow") > Addresses-Coverity-ID: 1501726 ("Unintentional integer overflow") > Signed-off-by: Gustavo A. R. Silva > --- > drivers/md/bcache/writeback.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c > index 82d4e0880a99..4fb635c0baa0 100644 > --- a/drivers/md/bcache/writeback.c > +++ b/drivers/md/bcache/writeback.c > @@ -110,13 +110,13 @@ static void __update_writeback_rate(struct cached_dev *dc) > int64_t fps; > > if (c->gc_stats.in_use <= BCH_WRITEBACK_FRAGMENT_THRESHOLD_MID) { > - fp_term = dc->writeback_rate_fp_term_low * > + fp_term = (int64_t)dc->writeback_rate_fp_term_low * > (c->gc_stats.in_use - BCH_WRITEBACK_FRAGMENT_THRESHOLD_LOW); > } else if (c->gc_stats.in_use <= BCH_WRITEBACK_FRAGMENT_THRESHOLD_HIGH) { > - fp_term = dc->writeback_rate_fp_term_mid * > + fp_term = (int64_t)dc->writeback_rate_fp_term_mid * > (c->gc_stats.in_use - BCH_WRITEBACK_FRAGMENT_THRESHOLD_MID); > } else { > - fp_term = dc->writeback_rate_fp_term_high * > + fp_term = (int64_t)dc->writeback_rate_fp_term_high * > (c->gc_stats.in_use - BCH_WRITEBACK_FRAGMENT_THRESHOLD_HIGH); > } > fps = div_s64(dirty, dirty_buckets) * fp_term; > Hmm, should such thing be handled by compiler ? Otherwise this kind of potential overflow issue will be endless time to time. I am not a compiler expert, should we have to do such explicit type cast all the time ? Coly Li