cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-misc-Replace-zero-length-arrays-with-flexible-array-.patch

c687bc
From 67878e1306f9ea6ccd30437327147c46de196a36 Mon Sep 17 00:00:00 2001
c687bc
From: Thomas Huth <thuth@redhat.com>
c687bc
Date: Wed, 11 Nov 2020 12:03:13 -0500
c687bc
Subject: [PATCH 13/18] misc: Replace zero-length arrays with flexible array
c687bc
 member (manual)
c687bc
MIME-Version: 1.0
c687bc
Content-Type: text/plain; charset=UTF-8
c687bc
Content-Transfer-Encoding: 8bit
c687bc
c687bc
RH-Author: Thomas Huth <thuth@redhat.com>
c687bc
Message-id: <20201111120316.707489-10-thuth@redhat.com>
c687bc
Patchwork-id: 99506
c687bc
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH v2 09/12] misc: Replace zero-length arrays with flexible array member (manual)
c687bc
Bugzilla: 1798506
c687bc
RH-Acked-by: Jens Freimann <jfreimann@redhat.com>
c687bc
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
c687bc
RH-Acked-by: David Hildenbrand <david@redhat.com>
c687bc
c687bc
From: Philippe Mathieu-Daudé <philmd@redhat.com>
c687bc
c687bc
Description copied from Linux kernel commit from Gustavo A. R. Silva
c687bc
(see [3]):
c687bc
c687bc
--v-- description start --v--
c687bc
c687bc
  The current codebase makes use of the zero-length array language
c687bc
  extension to the C90 standard, but the preferred mechanism to
c687bc
  declare variable-length types such as these ones is a flexible
c687bc
  array member [1], introduced in C99:
c687bc
c687bc
  struct foo {
c687bc
      int stuff;
c687bc
      struct boo array[];
c687bc
  };
c687bc
c687bc
  By making use of the mechanism above, we will get a compiler
c687bc
  warning in case the flexible array does not occur last in the
c687bc
  structure, which will help us prevent some kind of undefined
c687bc
  behavior bugs from being unadvertenly introduced [2] to the
c687bc
  Linux codebase from now on.
c687bc
c687bc
--^-- description end --^--
c687bc
c687bc
Do the similar housekeeping in the QEMU codebase (which uses
c687bc
C99 since commit 7be41675f7cb).
c687bc
c687bc
All these instances of code were found with the help of the
c687bc
following command (then manual analysis, without modifying
c687bc
structures only having a single flexible array member, such
c687bc
QEDTable in block/qed.h):
c687bc
c687bc
  git grep -F '[0];'
c687bc
c687bc
[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
c687bc
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=76497732932f
c687bc
[3] https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git/commit/?id=17642a2fbd2c1
c687bc
c687bc
Inspired-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
c687bc
Reviewed-by: David Hildenbrand <david@redhat.com>
c687bc
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
c687bc
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
c687bc
(cherry picked from commit 880a7817c1a82a93d3f83dfb25dce1f0db629c66)
c687bc
Signed-off-by: Thomas Huth <thuth@redhat.com>
c687bc
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
c687bc
---
c687bc
 block/vmdk.c                      | 2 +-
c687bc
 docs/interop/vhost-user.rst       | 4 ++--
c687bc
 hw/char/sclpconsole-lm.c          | 2 +-
c687bc
 hw/char/sclpconsole.c             | 2 +-
c687bc
 hw/s390x/virtio-ccw.c             | 2 +-
c687bc
 include/hw/acpi/acpi-defs.h       | 4 ++--
c687bc
 include/hw/boards.h               | 2 +-
c687bc
 include/hw/s390x/event-facility.h | 2 +-
c687bc
 include/hw/s390x/sclp.h           | 8 ++++----
c687bc
 target/s390x/ioinst.c             | 2 +-
c687bc
 10 files changed, 15 insertions(+), 15 deletions(-)
c687bc
c687bc
diff --git a/block/vmdk.c b/block/vmdk.c
c687bc
index 1bd39917290..8ec18f35a53 100644
c687bc
--- a/block/vmdk.c
c687bc
+++ b/block/vmdk.c
c687bc
@@ -187,7 +187,7 @@ typedef struct VmdkMetaData {
c687bc
 typedef struct VmdkGrainMarker {
c687bc
     uint64_t lba;
c687bc
     uint32_t size;
c687bc
-    uint8_t  data[0];
c687bc
+    uint8_t  data[];
c687bc
 } QEMU_PACKED VmdkGrainMarker;
c687bc
 
c687bc
 enum {
c687bc
diff --git a/docs/interop/vhost-user.rst b/docs/interop/vhost-user.rst
c687bc
index 7827b710aa0..71b20ce83dd 100644
c687bc
--- a/docs/interop/vhost-user.rst
c687bc
+++ b/docs/interop/vhost-user.rst
c687bc
@@ -563,7 +563,7 @@ For split virtqueue, queue region can be implemented as:
c687bc
       uint16_t used_idx;
c687bc
 
c687bc
       /* Used to track the state of each descriptor in descriptor table */
c687bc
-      DescStateSplit desc[0];
c687bc
+      DescStateSplit desc[];
c687bc
   } QueueRegionSplit;
c687bc
 
c687bc
 To track inflight I/O, the queue region should be processed as follows:
c687bc
@@ -685,7 +685,7 @@ For packed virtqueue, queue region can be implemented as:
c687bc
       uint8_t padding[7];
c687bc
 
c687bc
       /* Used to track the state of each descriptor fetched from descriptor ring */
c687bc
-      DescStatePacked desc[0];
c687bc
+      DescStatePacked desc[];
c687bc
   } QueueRegionPacked;
c687bc
 
c687bc
 To track inflight I/O, the queue region should be processed as follows:
c687bc
diff --git a/hw/char/sclpconsole-lm.c b/hw/char/sclpconsole-lm.c
c687bc
index 392606259d5..a9a6f2b204c 100644
c687bc
--- a/hw/char/sclpconsole-lm.c
c687bc
+++ b/hw/char/sclpconsole-lm.c
c687bc
@@ -31,7 +31,7 @@
c687bc
 typedef struct OprtnsCommand {
c687bc
     EventBufferHeader header;
c687bc
     MDMSU message_unit;
c687bc
-    char data[0];
c687bc
+    char data[];
c687bc
 } QEMU_PACKED OprtnsCommand;
c687bc
 
c687bc
 /* max size for line-mode data in 4K SCCB page */
c687bc
diff --git a/hw/char/sclpconsole.c b/hw/char/sclpconsole.c
c687bc
index da126f0133f..55697130a0a 100644
c687bc
--- a/hw/char/sclpconsole.c
c687bc
+++ b/hw/char/sclpconsole.c
c687bc
@@ -25,7 +25,7 @@
c687bc
 
c687bc
 typedef struct ASCIIConsoleData {
c687bc
     EventBufferHeader ebh;
c687bc
-    char data[0];
c687bc
+    char data[];
c687bc
 } QEMU_PACKED ASCIIConsoleData;
c687bc
 
c687bc
 /* max size for ASCII data in 4K SCCB page */
c687bc
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
c687bc
index 6580ce5907d..aa2c75a49c6 100644
c687bc
--- a/hw/s390x/virtio-ccw.c
c687bc
+++ b/hw/s390x/virtio-ccw.c
c687bc
@@ -193,7 +193,7 @@ typedef struct VirtioThinintInfo {
c687bc
 typedef struct VirtioRevInfo {
c687bc
     uint16_t revision;
c687bc
     uint16_t length;
c687bc
-    uint8_t data[0];
c687bc
+    uint8_t data[];
c687bc
 } QEMU_PACKED VirtioRevInfo;
c687bc
 
c687bc
 /* Specify where the virtqueues for the subchannel are in guest memory. */
c687bc
diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
c687bc
index 57a3f58b0c9..b80188b430f 100644
c687bc
--- a/include/hw/acpi/acpi-defs.h
c687bc
+++ b/include/hw/acpi/acpi-defs.h
c687bc
@@ -152,7 +152,7 @@ typedef struct AcpiSerialPortConsoleRedirection
c687bc
  */
c687bc
 struct AcpiRsdtDescriptorRev1 {
c687bc
     ACPI_TABLE_HEADER_DEF       /* ACPI common table header */
c687bc
-    uint32_t table_offset_entry[0];  /* Array of pointers to other */
c687bc
+    uint32_t table_offset_entry[];  /* Array of pointers to other */
c687bc
     /* ACPI tables */
c687bc
 } QEMU_PACKED;
c687bc
 typedef struct AcpiRsdtDescriptorRev1 AcpiRsdtDescriptorRev1;
c687bc
@@ -162,7 +162,7 @@ typedef struct AcpiRsdtDescriptorRev1 AcpiRsdtDescriptorRev1;
c687bc
  */
c687bc
 struct AcpiXsdtDescriptorRev2 {
c687bc
     ACPI_TABLE_HEADER_DEF       /* ACPI common table header */
c687bc
-    uint64_t table_offset_entry[0];  /* Array of pointers to other */
c687bc
+    uint64_t table_offset_entry[];  /* Array of pointers to other */
c687bc
     /* ACPI tables */
c687bc
 } QEMU_PACKED;
c687bc
 typedef struct AcpiXsdtDescriptorRev2 AcpiXsdtDescriptorRev2;
c687bc
diff --git a/include/hw/boards.h b/include/hw/boards.h
c687bc
index 2920bdef5b4..a5e92f6c373 100644
c687bc
--- a/include/hw/boards.h
c687bc
+++ b/include/hw/boards.h
c687bc
@@ -101,7 +101,7 @@ typedef struct CPUArchId {
c687bc
  */
c687bc
 typedef struct {
c687bc
     int len;
c687bc
-    CPUArchId cpus[0];
c687bc
+    CPUArchId cpus[];
c687bc
 } CPUArchIdList;
c687bc
 
c687bc
 /**
c687bc
diff --git a/include/hw/s390x/event-facility.h b/include/hw/s390x/event-facility.h
c687bc
index bdc32a3c091..700a610f33c 100644
c687bc
--- a/include/hw/s390x/event-facility.h
c687bc
+++ b/include/hw/s390x/event-facility.h
c687bc
@@ -122,7 +122,7 @@ typedef struct MDBO {
c687bc
 
c687bc
 typedef struct MDB {
c687bc
     MdbHeader header;
c687bc
-    MDBO mdbo[0];
c687bc
+    MDBO mdbo[];
c687bc
 } QEMU_PACKED MDB;
c687bc
 
c687bc
 typedef struct SclpMsg {
c687bc
diff --git a/include/hw/s390x/sclp.h b/include/hw/s390x/sclp.h
c687bc
index df2fa4169b0..62e2aa1d9f1 100644
c687bc
--- a/include/hw/s390x/sclp.h
c687bc
+++ b/include/hw/s390x/sclp.h
c687bc
@@ -133,7 +133,7 @@ typedef struct ReadInfo {
c687bc
     uint16_t highest_cpu;
c687bc
     uint8_t  _reserved5[124 - 122];     /* 122-123 */
c687bc
     uint32_t hmfai;
c687bc
-    struct CPUEntry entries[0];
c687bc
+    struct CPUEntry entries[];
c687bc
 } QEMU_PACKED ReadInfo;
c687bc
 
c687bc
 typedef struct ReadCpuInfo {
c687bc
@@ -143,7 +143,7 @@ typedef struct ReadCpuInfo {
c687bc
     uint16_t nr_standby;            /* 12-13 */
c687bc
     uint16_t offset_standby;        /* 14-15 */
c687bc
     uint8_t reserved0[24-16];       /* 16-23 */
c687bc
-    struct CPUEntry entries[0];
c687bc
+    struct CPUEntry entries[];
c687bc
 } QEMU_PACKED ReadCpuInfo;
c687bc
 
c687bc
 typedef struct ReadStorageElementInfo {
c687bc
@@ -152,7 +152,7 @@ typedef struct ReadStorageElementInfo {
c687bc
     uint16_t assigned;
c687bc
     uint16_t standby;
c687bc
     uint8_t _reserved0[16 - 14]; /* 14-15 */
c687bc
-    uint32_t entries[0];
c687bc
+    uint32_t entries[];
c687bc
 } QEMU_PACKED ReadStorageElementInfo;
c687bc
 
c687bc
 typedef struct AttachStorageElement {
c687bc
@@ -160,7 +160,7 @@ typedef struct AttachStorageElement {
c687bc
     uint8_t _reserved0[10 - 8];  /* 8-9 */
c687bc
     uint16_t assigned;
c687bc
     uint8_t _reserved1[16 - 12]; /* 12-15 */
c687bc
-    uint32_t entries[0];
c687bc
+    uint32_t entries[];
c687bc
 } QEMU_PACKED AttachStorageElement;
c687bc
 
c687bc
 typedef struct AssignStorage {
c687bc
diff --git a/target/s390x/ioinst.c b/target/s390x/ioinst.c
c687bc
index b6be300cc48..a412926d278 100644
c687bc
--- a/target/s390x/ioinst.c
c687bc
+++ b/target/s390x/ioinst.c
c687bc
@@ -387,7 +387,7 @@ typedef struct ChscResp {
c687bc
     uint16_t len;
c687bc
     uint16_t code;
c687bc
     uint32_t param;
c687bc
-    char data[0];
c687bc
+    char data[];
c687bc
 } QEMU_PACKED ChscResp;
c687bc
 
c687bc
 #define CHSC_MIN_RESP_LEN 0x0008
c687bc
-- 
c687bc
2.27.0
c687bc