thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

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