Blame SOURCES/kvm-qcow2-Fix-Coverity-warning-when-calculating-the-refc.patch

7711c0
From 5a43aa56f4a0435e9e36884088673513444b8129 Mon Sep 17 00:00:00 2001
7711c0
From: Kevin Wolf <kwolf@redhat.com>
7711c0
Date: Tue, 19 Feb 2019 17:00:13 +0100
7711c0
Subject: [PATCH 12/23] qcow2: Fix Coverity warning when calculating the
7711c0
 refcount cache size
7711c0
7711c0
RH-Author: Kevin Wolf <kwolf@redhat.com>
7711c0
Message-id: <20190219170023.27826-4-kwolf@redhat.com>
7711c0
Patchwork-id: 84543
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 03/13] qcow2: Fix Coverity warning when calculating the refcount cache size
7711c0
Bugzilla: 1656913
7711c0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
7711c0
RH-Acked-by: Max Reitz <mreitz@redhat.com>
7711c0
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
7711c0
From: Alberto Garcia <berto@igalia.com>
7711c0
7711c0
MIN_REFCOUNT_CACHE_SIZE is 4 and the cluster size is guaranteed to be
7711c0
at most 2MB, so the minimum refcount cache size (in bytes) is always
7711c0
going to fit in a 32-bit integer.
7711c0
7711c0
Coverity doesn't know that, and since we're storing the result in a
7711c0
uint64_t (*refcount_cache_size) it thinks that we need the 64 bits and
7711c0
that we probably want to do a 64-bit multiplication to prevent the
7711c0
result from being truncated.
7711c0
7711c0
This is a false positive in this case, but it's a fair warning.
7711c0
We could do a 64-bit multiplication to get rid of it, but since we
7711c0
know that a 32-bit variable is enough to store this value let's simply
7711c0
reuse min_refcount_cache, make it a normal int and stop doing casts.
7711c0
7711c0
Reported-by: Peter Maydell <peter.maydell@linaro.org>
7711c0
Signed-off-by: Alberto Garcia <berto@igalia.com>
7711c0
Reviewed-by: Eric Blake <eblake@redhat.com>
7711c0
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7711c0
(cherry picked from commit 7af5eea9b34ffb7a9a9fc25ba71998a02b76e159)
7711c0
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 block/qcow2.c | 5 ++---
7711c0
 1 file changed, 2 insertions(+), 3 deletions(-)
7711c0
7711c0
diff --git a/block/qcow2.c b/block/qcow2.c
7711c0
index 4b65e4c..a0f7234 100644
7711c0
--- a/block/qcow2.c
7711c0
+++ b/block/qcow2.c
7711c0
@@ -775,6 +775,7 @@ static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts,
7711c0
     BDRVQcow2State *s = bs->opaque;
7711c0
     uint64_t combined_cache_size;
7711c0
     bool l2_cache_size_set, refcount_cache_size_set, combined_cache_size_set;
7711c0
+    int min_refcount_cache = MIN_REFCOUNT_CACHE_SIZE * s->cluster_size;
7711c0
 
7711c0
     combined_cache_size_set = qemu_opt_get(opts, QCOW2_OPT_CACHE_SIZE);
7711c0
     l2_cache_size_set = qemu_opt_get(opts, QCOW2_OPT_L2_CACHE_SIZE);
7711c0
@@ -811,8 +812,6 @@ static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts,
7711c0
         } else {
7711c0
             uint64_t virtual_disk_size = bs->total_sectors * BDRV_SECTOR_SIZE;
7711c0
             uint64_t max_l2_cache = virtual_disk_size / (s->cluster_size / 8);
7711c0
-            uint64_t min_refcount_cache =
7711c0
-                (uint64_t) MIN_REFCOUNT_CACHE_SIZE * s->cluster_size;
7711c0
 
7711c0
             /* Assign as much memory as possible to the L2 cache, and
7711c0
              * use the remainder for the refcount cache */
7711c0
@@ -832,7 +831,7 @@ static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts,
7711c0
                                  * s->cluster_size);
7711c0
         }
7711c0
         if (!refcount_cache_size_set) {
7711c0
-            *refcount_cache_size = MIN_REFCOUNT_CACHE_SIZE * s->cluster_size;
7711c0
+            *refcount_cache_size = min_refcount_cache;
7711c0
         }
7711c0
     }
7711c0
 
7711c0
-- 
7711c0
1.8.3.1
7711c0