From nobody Sat Nov 1 22:28:54 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527519801092515.7698495682749; Mon, 28 May 2018 08:03:21 -0700 (PDT) Received: from localhost ([::1]:56658 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNJg8-0006D6-7r for importer@patchew.org; Mon, 28 May 2018 11:03:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54276) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNJej-0005Vq-UL for qemu-devel@nongnu.org; Mon, 28 May 2018 11:01:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fNJef-0007x6-98 for qemu-devel@nongnu.org; Mon, 28 May 2018 11:01:54 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:43139) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fNJee-0007tk-TM; Mon, 28 May 2018 11:01:49 -0400 Received: from 58.red-83-61-185.dynamicip.rima-tde.net ([83.61.185.58] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1fNJea-00017s-RL; Mon, 28 May 2018 17:01:44 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1fNJeN-0008Cn-Rr; Mon, 28 May 2018 18:01:31 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Message-Id:Date:Subject:Cc:To:From; bh=4zHsbV7OGKUEqs4DnpPkOovuT6zD/+lRpdxDUtLVq10=; b=fOQ+ibrk1NPSOav2stgdzjIQFtaF5xe37CsNX9bXh0QbTP/hd10LsFX1xpXCOPJbdcnFP+KhxKk2LCsBoMDAqduanuFZIqDwDMOADfzfM7ZWR4a4Lu4dRG/GYBXtdk+Ka6r37cOn4Zt/RARQxhugZPG30eF3ktUjXe7pM0+DCR9uScckn/L8lA+STs2177H43mefaEubS/xkoJCthJm4x1OGu8qyiK8mSgV1W203OOoBwAojZ8PcZNK845eS49Z1Y4pm8IAMHx9VEKwx4g7xVCyyGQ10BTfNktR4tXqCHVuDKwIDQRa41zZUhT8V/L/cGWsF6PZZdxxmWwuObc0LQQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 28 May 2018 17:01:28 +0200 Message-Id: <20180528150128.31500-1-berto@igalia.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH] qcow2: Fix Coverity warning when calculating the refcount cache size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , Alberto Garcia , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" MIN_REFCOUNT_CACHE_SIZE is 4 and the cluster size is guaranteed to be at most 2MB, so the minimum refcount cache size (in bytes) is always going to fit in a 32-bit integer. Coverity doesn't know that, and since we're storing the result in a uint64_t (*refcount_cache_size) it thinks that we need the 64 bits and that we probably want to do a 64-bit multiplication to prevent the result from being truncated. This is a false positive in this case, but it's a fair warning. We could do a 64-bit multiplication to get rid of it, but since we know that a 32-bit variable is enough to store this value let's simply reuse min_refcount_cache, make it a normal int and stop doing casts. Signed-off-by: Alberto Garcia Reported-by: Peter Maydell Reviewed-by: Eric Blake --- block/qcow2.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 6d532470a8..a007dc4246 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -768,6 +768,7 @@ static void read_cache_sizes(BlockDriverState *bs, Qemu= Opts *opts, BDRVQcow2State *s =3D bs->opaque; uint64_t combined_cache_size; bool l2_cache_size_set, refcount_cache_size_set, combined_cache_size_s= et; + int min_refcount_cache =3D MIN_REFCOUNT_CACHE_SIZE * s->cluster_size; =20 combined_cache_size_set =3D qemu_opt_get(opts, QCOW2_OPT_CACHE_SIZE); l2_cache_size_set =3D qemu_opt_get(opts, QCOW2_OPT_L2_CACHE_SIZE); @@ -804,8 +805,6 @@ static void read_cache_sizes(BlockDriverState *bs, Qemu= Opts *opts, } else { uint64_t virtual_disk_size =3D bs->total_sectors * BDRV_SECTOR= _SIZE; uint64_t max_l2_cache =3D virtual_disk_size / (s->cluster_size= / 8); - uint64_t min_refcount_cache =3D - (uint64_t) MIN_REFCOUNT_CACHE_SIZE * s->cluster_size; =20 /* Assign as much memory as possible to the L2 cache, and * use the remainder for the refcount cache */ @@ -825,7 +824,7 @@ static void read_cache_sizes(BlockDriverState *bs, Qemu= Opts *opts, * s->cluster_size); } if (!refcount_cache_size_set) { - *refcount_cache_size =3D MIN_REFCOUNT_CACHE_SIZE * s->cluster_= size; + *refcount_cache_size =3D min_refcount_cache; } } =20 --=20 2.11.0