]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
target/ppc/kvm: Replace variable length array in kvmppc_read_hptes()
authorThomas Huth <thuth@redhat.com>
Wed, 21 Feb 2024 16:26:35 +0000 (17:26 +0100)
committerThomas Huth <thuth@redhat.com>
Fri, 23 Feb 2024 07:13:52 +0000 (08:13 +0100)
HPTES_PER_GROUP is 8 and HASH_PTE_SIZE_64 is 16, so we don't waste
too many bytes by always allocating the maximum amount of bytes on
the stack here to get rid of the variable length array.

Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Message-ID: <20240221162636.173136-3-thuth@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
target/ppc/kvm.c

index e7e39c309113167e9723b55a6e55f0725b442e5c..bcf30a5400a0e1b3611baccbe7b2610fa302ce8d 100644 (file)
@@ -2770,9 +2770,9 @@ void kvmppc_read_hptes(ppc_hash_pte64_t *hptes, hwaddr ptex, int n)
     while (i < n) {
         struct kvm_get_htab_header *hdr;
         int m = n < HPTES_PER_GROUP ? n : HPTES_PER_GROUP;
-        char buf[sizeof(*hdr) + m * HASH_PTE_SIZE_64];
+        char buf[sizeof(*hdr) + HPTES_PER_GROUP * HASH_PTE_SIZE_64];
 
-        rc = read(fd, buf, sizeof(buf));
+        rc = read(fd, buf, sizeof(*hdr) + m * HASH_PTE_SIZE_64);
         if (rc < 0) {
             hw_error("kvmppc_read_hptes: Unable to read HPTEs");
         }