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

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