[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ea24a361-ab1f-a330-b5e6-007bb9a1013b@suse.de>
Date: Fri, 12 Feb 2021 22:22:44 +0800
From: Coly Li <colyli@...e.de>
To: "Gustavo A. R. Silva" <gustavoars@...nel.org>,
Kent Overstreet <kent.overstreet@...il.com>,
"David S. Miller" <davem@...emloft.net>,
Christina Jacob <cjacob@...vell.com>,
Hariprasad Kelam <hkelam@...vell.com>,
Sunil Goutham <sgoutham@...vell.com>,
Jesse Brandeburg <jesse.brandeburg@...el.com>
Cc: linux-bcache@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH][next] bcache: Use 64-bit arithmetic instead of 32-bit
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 <gustavoars@...nel.org>
> ---
> 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
Powered by blists - more mailing lists