yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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