Re: [PATCH v2 1/2] ppc/pnv: Add an I2C controller model

2023-10-13 Thread Cédric Le Goater

On 10/12/23 22:08, Glenn Miles wrote:

From: Cédric Le Goater 

The more recent IBM power processors have an embedded I2C
controller that is accessible by software via the XSCOM
address space.

Each instance of the I2C controller is capable of controlling
multiple I2C buses (one at a time).  Prior to beginning a
transaction on an I2C bus, the bus must be selected by writing
the port number associated with the bus into the PORT_NUM
field of the MODE register.  Once an I2C bus is selected,
the status of the bus can be determined by reading the
Status and Extended Status registers.

I2C bus transactions can be started by writing a command to
the Command register and reading/writing data from/to the
FIFO register.

Not supported :

  . 10 bit I2C addresses
  . Multimaster
  . Slave

Signed-off-by: Cédric Le Goater 
[milesg: Split wiring to powernv9 into its own commit]
[milesg: Added more detail to commit message]
[milesg: Added SPDX Licensed Identifier to new files]
[milesg: updated copyright dates]
[milesg: Added use of g_autofree]
Signed-off-by: Glenn Miles 
---

Changes in v2:
 - Updated copyright dates
 - Removed copyright paragraph (replaced by SPDX-License-Identifier)
 - Added use of g_autofree

  hw/ppc/meson.build |   1 +
  hw/ppc/pnv_i2c.c   | 673 +
  include/hw/ppc/pnv_i2c.h   |  38 +++
  include/hw/ppc/pnv_xscom.h |   3 +
  4 files changed, 715 insertions(+)
  create mode 100644 hw/ppc/pnv_i2c.c
  create mode 100644 include/hw/ppc/pnv_i2c.h

diff --git a/hw/ppc/meson.build b/hw/ppc/meson.build
index 7c2c52434a..87b756a701 100644
--- a/hw/ppc/meson.build
+++ b/hw/ppc/meson.build
@@ -43,6 +43,7 @@ ppc_ss.add(when: 'CONFIG_POWERNV', if_true: files(
'pnv.c',
'pnv_xscom.c',
'pnv_core.c',
+  'pnv_i2c.c',
'pnv_lpc.c',
'pnv_psi.c',
'pnv_occ.c',
diff --git a/hw/ppc/pnv_i2c.c b/hw/ppc/pnv_i2c.c
new file mode 100644
index 00..9c431bf1ee
--- /dev/null
+++ b/hw/ppc/pnv_i2c.c
@@ -0,0 +1,673 @@
+/*
+ * QEMU PowerPC PowerNV Processor I2C model
+ *
+ * Copyright (c) 2019-2023, IBM Corporation.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/module.h"
+#include "qemu/log.h"
+#include "sysemu/reset.h"
+
+#include "hw/irq.h"
+#include "hw/qdev-properties.h"
+
+#include "hw/ppc/pnv.h"
+#include "hw/ppc/pnv_chip.h"
+#include "hw/ppc/pnv_i2c.h"
+#include "hw/ppc/pnv_xscom.h"
+#include "hw/ppc/fdt.h"
+
+#include 
+
+/* I2C FIFO register */
+#define I2C_FIFO_REG0x4
+#define I2C_FIFOPPC_BITMASK(0, 7)
+
+/* I2C command register */
+#define I2C_CMD_REG 0x5
+#define I2C_CMD_WITH_START  PPC_BIT(0)
+#define I2C_CMD_WITH_ADDR   PPC_BIT(1)
+#define I2C_CMD_READ_CONT   PPC_BIT(2)
+#define I2C_CMD_WITH_STOP   PPC_BIT(3)
+#define I2C_CMD_INTR_STEERING   PPC_BITMASK(6, 7) /* P9 */
+#define   I2C_CMD_INTR_STEER_HOST   1
+#define   I2C_CMD_INTR_STEER_OCC2
+#define I2C_CMD_DEV_ADDRPPC_BITMASK(8, 14)
+#define I2C_CMD_READ_NOT_WRITE  PPC_BIT(15)
+#define I2C_CMD_LEN_BYTES   PPC_BITMASK(16, 31)
+#define I2C_MAX_TFR_LEN 0xfff0ull
+
+/* I2C mode register */
+#define I2C_MODE_REG0x6
+#define I2C_MODE_BIT_RATE_DIV   PPC_BITMASK(0, 15)
+#define I2C_MODE_PORT_NUM   PPC_BITMASK(16, 21)
+#define I2C_MODE_ENHANCED   PPC_BIT(28)
+#define I2C_MODE_DIAGNOSTIC PPC_BIT(29)
+#define I2C_MODE_PACING_ALLOW   PPC_BIT(30)
+#define I2C_MODE_WRAP   PPC_BIT(31)
+
+/* I2C watermark register */
+#define I2C_WATERMARK_REG   0x7
+#define I2C_WATERMARK_HIGH  PPC_BITMASK(16, 19)
+#define I2C_WATERMARK_LOW   PPC_BITMASK(24, 27)
+
+/*
+ * I2C interrupt mask and condition registers
+ *
+ * NB: The function of 0x9 and 0xa changes depending on whether you're reading
+ * or writing to them. When read they return the interrupt condition bits
+ * and on writes they update the interrupt mask register.
+ *
+ *  The bit definitions are the same for all the interrupt registers.
+ */
+#define I2C_INTR_MASK_REG   0x8
+
+#define I2C_INTR_RAW_COND_REG   0x9 /* read */
+#define I2C_INTR_MASK_OR_REG0x9 /* write*/
+
+#define I2C_INTR_COND_REG   0xa /* read */
+#define I2C_INTR_MASK_AND_REG   0xa /* write */
+
+#define I2C_INTR_ALLPPC_BITMASK(16, 31)
+#define I2C_INTR_INVALID_CMDPPC_BIT(16)
+#define I2C_INTR_LBUS_PARITY_ERRPPC_BIT(17)
+#define I2C_INTR_BKEND_OVERRUN_ERR  PPC_BIT(18)
+#define I2C_INTR_BKEND_ACCESS_ERR   PPC_BIT(19)
+#define I2C_INTR_ARBT_LOST_ERR  PPC_BIT(20)
+#define I2C_INTR_NACK_RCVD_ERR  PPC_BIT(21)
+#define I2C_INTR_DATA_REQ   PPC_BIT(22)
+#define I2C_INTR_CMD_COMP   PPC_BIT(

Re: [PATCH v2 2/2] ppc/pnv: Connect I2C controller model to powernv9 chip

2023-10-13 Thread Cédric Le Goater

On 10/12/23 22:08, Glenn Miles wrote:

From: Cédric Le Goater 

Wires up three I2C controller instances to the powernv9 chip
XSCOM address space.

Each controller instance is wired up to a single I2C bus of
its own.  No other I2C devices are connected to the buses
at this time.

Signed-off-by: Cédric Le Goater 
[milesg: Split wiring from addition of model itself]
[milesg: Added new commit message]
[milesg: Moved hardcoded attributes into PnvChipClass]
Signed-off-by: Glenn Miles 
---

Changes in v2:
 - Moved some hardcoded attributes into PnvChipClass

  hw/ppc/pnv.c  | 29 +
  include/hw/ppc/pnv_chip.h |  8 
  2 files changed, 37 insertions(+)

diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
index eb54f93986..7db6f3abe5 100644
--- a/hw/ppc/pnv.c
+++ b/hw/ppc/pnv.c
@@ -1438,6 +1438,10 @@ static void pnv_chip_power9_instance_init(Object *obj)
  object_initialize_child(obj, "pec[*]", &chip9->pecs[i],
  TYPE_PNV_PHB4_PEC);
  }
+
+for (i = 0; i < pcc->i2c_num_engines; i++) {
+object_initialize_child(obj, "i2c[*]", &chip9->i2c[i], TYPE_PNV_I2C);
+}
  }
  
  static void pnv_chip_quad_realize_one(PnvChip *chip, PnvQuad *eq,

@@ -1510,6 +1514,7 @@ static void pnv_chip_power9_realize(DeviceState *dev, 
Error **errp)
  PnvChip *chip = PNV_CHIP(dev);
  Pnv9Psi *psi9 = &chip9->psi;
  Error *local_err = NULL;
+int i;
  
  /* XSCOM bridge is first */

  pnv_xscom_realize(chip, PNV9_XSCOM_SIZE, &local_err);
@@ -1613,6 +1618,28 @@ static void pnv_chip_power9_realize(DeviceState *dev, 
Error **errp)
  error_propagate(errp, local_err);
  return;
  }
+
+/*
+ * I2C
+ * TODO: The number of busses is specific to each platform



I would remove the TODO now,

Reviewed-by: Cédric Le Goater 

Thanks,

C.



+ */
+for (i = 0; i < pcc->i2c_num_engines; i++) {
+Object *obj =  OBJECT(&chip9->i2c[i]);
+
+object_property_set_int(obj, "engine", i + 1, &error_fatal);
+object_property_set_int(obj, "num-busses", pcc->i2c_num_ports,
+&error_fatal);
+object_property_set_link(obj, "chip", OBJECT(chip), &error_abort);
+if (!qdev_realize(DEVICE(obj), NULL, errp)) {
+return;
+}
+pnv_xscom_add_subregion(chip, PNV9_XSCOM_I2CM_BASE +
+   chip9->i2c[i].engine * PNV9_XSCOM_I2CM_SIZE,
+&chip9->i2c[i].xscom_regs);
+qdev_connect_gpio_out(DEVICE(&chip9->i2c[i]), 0,
+  qdev_get_gpio_in(DEVICE(&chip9->psi),
+   PSIHB9_IRQ_SBE_I2C));
+}
  }
  
  static uint32_t pnv_chip_power9_xscom_pcba(PnvChip *chip, uint64_t addr)

@@ -1640,6 +1667,8 @@ static void pnv_chip_power9_class_init(ObjectClass 
*klass, void *data)
  k->xscom_pcba = pnv_chip_power9_xscom_pcba;
  dc->desc = "PowerNV Chip POWER9";
  k->num_pecs = PNV9_CHIP_MAX_PEC;
+k->i2c_num_engines = PNV9_CHIP_MAX_I2C;
+k->i2c_num_ports = PNV9_CHIP_MAX_I2C_PORTS;
  
  device_class_set_parent_realize(dc, pnv_chip_power9_realize,

  &k->parent_realize);
diff --git a/include/hw/ppc/pnv_chip.h b/include/hw/ppc/pnv_chip.h
index 53e1d921d7..90cfbad1a5 100644
--- a/include/hw/ppc/pnv_chip.h
+++ b/include/hw/ppc/pnv_chip.h
@@ -9,6 +9,7 @@
  #include "hw/ppc/pnv_psi.h"
  #include "hw/ppc/pnv_sbe.h"
  #include "hw/ppc/pnv_xive.h"
+#include "hw/ppc/pnv_i2c.h"
  #include "hw/sysbus.h"
  
  OBJECT_DECLARE_TYPE(PnvChip, PnvChipClass,

@@ -86,6 +87,10 @@ struct Pnv9Chip {
  
  #define PNV9_CHIP_MAX_PEC 3

  PnvPhb4PecState pecs[PNV9_CHIP_MAX_PEC];
+
+#define PNV9_CHIP_MAX_I2C 3
+#define PNV9_CHIP_MAX_I2C_PORTS 1
+PnvI2C  i2c[PNV9_CHIP_MAX_I2C];
  };
  
  /*

@@ -130,6 +135,9 @@ struct PnvChipClass {
  uint32_t num_pecs;
  uint32_t num_phbs;
  
+uint32_t i2c_num_engines;

+uint32_t i2c_num_ports;
+
  DeviceRealize parent_realize;
  
  uint32_t (*core_pir)(PnvChip *chip, uint32_t core_id);





Re: [PATCH 03/10] tests/virtio-scsi: Clean up global variable shadowing

2023-10-13 Thread Manos Pitsidianakis

On Mon, 09 Oct 2023 13:02, Philippe Mathieu-Daudé  wrote:

Rename the (unused) 'allow' argument, following the pattern


s/allow/alloc

Otherwise,

Reviewed-By: Emmanouil Pitsidianakis 


used by the other tests in this file. This fixes:

 tests/qtest/virtio-scsi-test.c:159:61: error: declaration shadows a variable 
in the global scope [-Werror,-Wshadow]
 static void hotplug(void *obj, void *data, QGuestAllocator *alloc)
 ^
 tests/qtest/virtio-scsi-test.c:37:25: note: previous declaration is here
 static QGuestAllocator *alloc;
 ^

Signed-off-by: Philippe Mathieu-Daudé 
---
tests/qtest/virtio-scsi-test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/qtest/virtio-scsi-test.c b/tests/qtest/virtio-scsi-test.c
index ceaa7f2415..db10d572d0 100644
--- a/tests/qtest/virtio-scsi-test.c
+++ b/tests/qtest/virtio-scsi-test.c
@@ -156,7 +156,7 @@ static QVirtioSCSIQueues *qvirtio_scsi_init(QVirtioDevice 
*dev)
return vs;
}

-static void hotplug(void *obj, void *data, QGuestAllocator *alloc)
+static void hotplug(void *obj, void *data, QGuestAllocator *t_alloc)
{
QTestState *qts = global_qtest;

--
2.41.0






[RFC PATCH 00/78] Strict disable implicit fallthrough

2023-10-13 Thread Emmanouil Pitsidianakis
Hello,

This RFC is inspired by the kernel's move to -Wimplicit-fallthrough=3
back in 2019.[0]
We take one step (or two) further by increasing it to 5 which rejects
fall through comments and requires an attribute statement.

[0]:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a035d552a93b

The line differences are not many, but they spread all over different
subsystems, architectures and devices. An attempt has been made to split
them in cohesive patches to aid post-RFC review. Part of the RFC is to
determine whether these patch divisions needs improvement.

Main questions this RFC poses
=

- Is this change desirable and net-positive.
- Should the `fallthrough;` pseudo-keyword be defined like in the Linux
  kernel, or use glib's G_GNUC_FALLTHROUGH, or keep the already existing
  QEMU_FALLTHROUGH macro.
- Should fallthrough comments be removed if they do not include extra
  information.

Some external resources
===

See the RFC discussion in the kernel:

https://lore.kernel.org/lkml/1d2830aadbe9d8151728a7df5b88528fc72a0095.1564549413.git@perches.com/

The `fallthrough;` pseudo-keyword in the kernel source code:

https://elixir.bootlin.com/linux/latest/C/ident/fallthrough

In summary, I quote the doc comment and definition:

/*
 * Add the pseudo keyword 'fallthrough' so case statement blocks
 * must end with any of these keywords:
 *   break;
 *   fallthrough;
 *   continue;
 *   goto ;
 *   return [expression];
 *
 *  gcc: 
https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes
 */
#if __has_attribute(__fallthrough__)
# define fallthrough__attribute__((__fallthrough__))
#else
# define fallthroughdo {} while (0)  /* fallthrough */
#endif

Background - Motivation
===

The C switch statement allows you to conditionally goto different labels
depending on a value. A break; statement conveniently goto's the end of
the switch. If a "case" does not end in a break, we say that the control
flow falls through the next case label, if any, implicitly. This can
lead to bugs and QEMU uses the GCC warning -Wimplicit-fallthrough to
prevent this.

Currently, QEMU is built with -Wimplicit-fallthrough=2. This makes GCC's
static analyzer check for a case-insensitive matches of the .*falls?[
\t-]*thr(ough|u).* regular expression. This means the following list of
comments taken from QEMU all disable the implicit fallthrough warning:

- /* FALLTHRU */
- /* fall through */
- /* Fall through.  */
- /* Fall through... */
- /* fall through if hEventTimeout is signaled */
- /* FALL THROUGH */

To keep a constistent code style, this commit adds a macro `fallthrough`
that looks like a C keyword but expands to an attribute statement in
supported compilers (GCC at the moment).

Note: there was already such a macro, QEMU_FALLTHROUGH, and it was used
only around 7 times in the code base. The first commit replaces it.

Emmanouil Pitsidianakis (78):
  include/qemu/compiler.h: replace QEMU_FALLTHROUGH with fallthrough
  block: add fallthrough pseudo-keyword
  fpu/softfloat: add fallthrough pseudo-keyword
  qapi/opts-visitor: add fallthrough pseudo-keyword
  qobject/json: add fallthrough pseudo-keyword
  tcg: add fallthrough pseudo-keyword
  hw/virtio/virtio-balloon.c: add fallthrough pseudo-keyword
  hw/block: add fallthrough pseudo-keyword
  hw/acpi/aml-build.c: add fallthrough pseudo-keyword
  hw/ide/atapi.c: add fallthrough pseudo-keyword
  hw/timer: add fallthrough pseudo-keyword
  hw/usb: add fallthrough pseudo-keyword
  hw/adc: add fallthrough pseudo-keyword
  util/error-report.c: add fallthrough pseudo-keyword
  accel/tcg: add fallthrough pseudo-keyword
  audio: add fallthrough pseudo-keyword
  ui/sdl2.c: add fallthrough pseudo-keyword
  ui/win32-kbd-hook.c: add fallthrough pseudo-keyword
  target/hppa: add fallthrough pseudo-keyword
  target/mips: add fallthrough pseudo-keyword
  target/sparc: add fallthrough pseudo-keyword
  target/ppc: add fallthrough pseudo-keyword
  target/arm: add fallthrough pseudo-keyword
  target/alpha: add fallthrough pseudo-keyword
  target/i386: add fallthrough pseudo-keyword
  target/s390x: add fallthrough pseudo-keyword
  target/riscv: add fallthrough pseudo-keyword
  target/avr: add fallthrough pseudo-keyword
  target/cris: add fallthrough pseudo-keyword
  target/nios2: add fallthrough pseudo-keyword
  target/xtensa: add fallthrough pseudo-keyword
  target/m68k: add fallthrough pseudo-keyword
  target/rx: add fallthrough pseudo-keyword
  target/tricore: add fallthrough pseudo-keyword
  target/sh4: add fallthrough pseudo-keyword
  target/openrisc: add fallthrough pseudo-keyword
  target/hexagon: add fallthrough pseudo-keyword
  system/rtc.c: add fallthrough pseudo-keyword
  hw/scsi: add fallthrough pseudo-keyword
  hw/sd/sdhci.c: add fallthrough pseudo-keyword
  linux-user: add

[RFC PATCH 07/78] hw/virtio/virtio-balloon.c: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/virtio/virtio-balloon.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index d004cf29d2..0f0d94bd94 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -636,56 +636,57 @@ static int
 virtio_balloon_free_page_hint_notify(NotifierWithReturn *n, void *data)
 {
 VirtIOBalloon *dev = container_of(n, VirtIOBalloon, free_page_hint_notify);
 VirtIODevice *vdev = VIRTIO_DEVICE(dev);
 PrecopyNotifyData *pnd = data;
 
 if (!virtio_balloon_free_page_support(dev)) {
 /*
  * This is an optimization provided to migration, so just return 0 to
  * have the normal migration process not affected when this feature is
  * not supported.
  */
 return 0;
 }
 
 /*
  * Pages hinted via qemu_guest_free_page_hint() are cleared from the dirty
  * bitmap and will not get migrated, especially also not when the postcopy
  * destination starts using them and requests migration from the source; 
the
  * faulting thread will stall until postcopy migration finishes and
  * all threads are woken up. Let's not start free page hinting if postcopy
  * is possible.
  */
 if (migrate_postcopy_ram()) {
 return 0;
 }
 
 switch (pnd->reason) {
 case PRECOPY_NOTIFY_BEFORE_BITMAP_SYNC:
 virtio_balloon_free_page_stop(dev);
 break;
 case PRECOPY_NOTIFY_AFTER_BITMAP_SYNC:
 if (vdev->vm_running) {
 virtio_balloon_free_page_start(dev);
 break;
 }
 /*
  * Set S_DONE before migrating the vmstate, so the guest will reuse
  * all hinted pages once running on the destination. Fall through.
  */
+fallthrough;
 case PRECOPY_NOTIFY_CLEANUP:
 /*
  * Especially, if something goes wrong during precopy or if migration
  * is canceled, we have to properly communicate S_DONE to the VM.
  */
 virtio_balloon_free_page_done(dev);
 break;
 case PRECOPY_NOTIFY_SETUP:
 case PRECOPY_NOTIFY_COMPLETE:
 break;
 default:
 virtio_error(vdev, "%s: %d reason unknown", __func__, pnd->reason);
 }
 
 return 0;
 }
-- 
2.39.2




[RFC PATCH 10/78] hw/ide/atapi.c: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/ide/atapi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index dcc39df9a4..85c74a5ffe 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -1189,53 +1189,54 @@ static void cmd_read_disc_information(IDEState *s, 
uint8_t* buf)
 static void cmd_read_dvd_structure(IDEState *s, uint8_t* buf)
 {
 int max_len;
 int media = buf[1];
 int format = buf[7];
 int ret;
 
 max_len = lduw_be_p(buf + 8);
 
 if (format < 0xff) {
 if (media_is_cd(s)) {
 ide_atapi_cmd_error(s, ILLEGAL_REQUEST,
 ASC_INCOMPATIBLE_FORMAT);
 return;
 } else if (!media_present(s)) {
 ide_atapi_cmd_error(s, ILLEGAL_REQUEST,
 ASC_INV_FIELD_IN_CMD_PACKET);
 return;
 }
 }
 
 memset(buf, 0, max_len > IDE_DMA_BUF_SECTORS * BDRV_SECTOR_SIZE + 4 ?
IDE_DMA_BUF_SECTORS * BDRV_SECTOR_SIZE + 4 : max_len);
 
 switch (format) {
 case 0x00 ... 0x7f:
 case 0xff:
 if (media == 0) {
 ret = ide_dvd_read_structure(s, format, buf, buf);
 
 if (ret < 0) {
 ide_atapi_cmd_error(s, ILLEGAL_REQUEST, -ret);
 } else {
 ide_atapi_cmd_reply(s, ret, max_len);
 }
 
 break;
 }
 /* TODO: BD support, fall through for now */
+fallthrough;
 
 /* Generic disk structures */
 case 0x80: /* TODO: AACS volume identifier */
 case 0x81: /* TODO: AACS media serial number */
 case 0x82: /* TODO: AACS media identifier */
 case 0x83: /* TODO: AACS media key block */
 case 0x90: /* TODO: List of recognized format layers */
 case 0xc0: /* TODO: Write protection status */
 default:
 ide_atapi_cmd_error(s, ILLEGAL_REQUEST,
 ASC_INV_FIELD_IN_CMD_PACKET);
 break;
 }
 }
-- 
2.39.2




[RFC PATCH 12/78] hw/usb: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/usb/dev-mtp.c   | 2 +-
 hw/usb/dev-wacom.c | 2 +-
 hw/usb/hcd-ehci.c  | 4 +++-
 hw/usb/hcd-xhci.c  | 4 ++--
 hw/usb/redirect.c  | 4 ++--
 hw/usb/tusb6010.c  | 2 +-
 6 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 1cac1cd435..5cbaabd2b2 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -1602,76 +1602,76 @@ static int usb_mtp_update_object(MTPObject *parent, 
char *name)
 static void usb_mtp_write_data(MTPState *s, uint32_t handle)
 {
 MTPData *d = s->data_out;
 MTPObject *parent =
 usb_mtp_object_lookup(s, s->dataset.parent_handle);
 char *path = NULL;
 uint64_t rc;
 mode_t mask = 0755;
 int ret = 0;
 
 assert(d != NULL);
 
 switch (d->write_status) {
 case WRITE_START:
 if (!parent || !s->write_pending) {
 usb_mtp_queue_result(s, RES_INVALID_OBJECTINFO, d->trans,
 0, 0, 0, 0);
 return;
 }
 
 if (s->dataset.filename) {
 path = g_strdup_printf("%s/%s", parent->path, s->dataset.filename);
 if (s->dataset.format == FMT_ASSOCIATION) {
 ret = g_mkdir(path, mask);
 if (!ret) {
 usb_mtp_queue_result(s, RES_OK, d->trans, 3,
  QEMU_STORAGE_ID,
  s->dataset.parent_handle,
  handle);
 goto close;
 }
 goto done;
 }
 
 d->fd = open(path, O_CREAT | O_WRONLY |
  O_CLOEXEC | O_NOFOLLOW, mask & 0666);
 if (d->fd == -1) {
 ret = 1;
 goto done;
 }
 
 /* Return success if initiator sent 0 sized data */
 if (!s->dataset.size) {
 goto done;
 }
 if (d->length != MTP_WRITE_BUF_SZ && !d->pending) {
 d->write_status = WRITE_END;
 }
 }
-/* fall through */
+fallthrough;
 case WRITE_CONTINUE:
 case WRITE_END:
 rc = write_retry(d->fd, d->data, d->data_offset,
  d->offset - d->data_offset);
 if (rc != d->data_offset) {
 ret = 1;
 goto done;
 }
 if (d->write_status != WRITE_END) {
 g_free(path);
 return;
 } else {
 /*
  * Return an incomplete transfer if file size doesn't match
  * for < 4G file or if lstat fails which will result in an 
incorrect
  * file size
  */
 if ((s->dataset.size != 0x &&
  d->offset != s->dataset.size) ||
 usb_mtp_update_object(parent, s->dataset.filename)) {
 usb_mtp_queue_result(s, RES_INCOMPLETE_TRANSFER, d->trans,
  0, 0, 0, 0);
 goto close;
 }
 }
 }
diff --git a/hw/usb/dev-wacom.c b/hw/usb/dev-wacom.c
index 7177c17f03..bd2a1bae50 100644
--- a/hw/usb/dev-wacom.c
+++ b/hw/usb/dev-wacom.c
@@ -371,27 +371,27 @@ static void usb_wacom_handle_control(USBDevice *dev, 
USBPacket *p,
 static void usb_wacom_handle_data(USBDevice *dev, USBPacket *p)
 {
 USBWacomState *s = (USBWacomState *) dev;
 g_autofree uint8_t *buf = g_malloc(p->iov.size);
 int len = 0;
 
 switch (p->pid) {
 case USB_TOKEN_IN:
 if (p->ep->nr == 1) {
 if (!(s->changed || s->idle)) {
 p->status = USB_RET_NAK;
 return;
 }
 s->changed = 0;
 if (s->mode == WACOM_MODE_HID)
 len = usb_mouse_poll(s, buf, p->iov.size);
 else if (s->mode == WACOM_MODE_WACOM)
 len = usb_wacom_poll(s, buf, p->iov.size);
 usb_packet_copy(p, buf, len);
 break;
 }
-/* Fall through.  */
+fallthrough;
 case USB_TOKEN_OUT:
 default:
 p->status = USB_RET_STALL;
 }
 }
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 19b4534c20..e29cc21957 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -1402,116 +1402,116 @@ static int ehci_execute(EHCIPacket *p, const char 
*action)
 static int ehci_process_itd(EHCIState *ehci,
 EHCIitd *itd,
 uint32_t addr)
 {
 USBDevice *dev;
 USBEndpoint *ep;
 uint32_t i, len, pid, dir, devaddr, endp;
 uint32_t pg, off, ptr1, ptr2, max, mult;
 
 ehci->periodic_sched_active = PERIODIC_ACTIVE;
 
 dir =(itd->bufptr[1] & ITD_BUFPTR_DIRECTION);
 devaddr = get_field(itd->bufptr[0], ITD_BUFPTR_DEVADDR);
 endp = get_field(itd-

[RFC PATCH 08/78] hw/block: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/block/dataplane/xen-block.c | 4 ++--
 hw/block/m25p80.c  | 2 +-
 hw/block/onenand.c | 2 +-
 hw/block/pflash_cfi01.c| 1 +
 hw/block/pflash_cfi02.c| 6 --
 5 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c
index 3b6f2b0aa2..1ae25a73b2 100644
--- a/hw/block/dataplane/xen-block.c
+++ b/hw/block/dataplane/xen-block.c
@@ -144,59 +144,59 @@ static void xen_block_complete_request(XenBlockRequest 
*request)
 /*
  * translate request into iovec + start offset
  * do sanity checks along the way
  */
 static int xen_block_parse_request(XenBlockRequest *request)
 {
 XenBlockDataPlane *dataplane = request->dataplane;
 size_t len;
 int i;
 
 switch (request->req.operation) {
 case BLKIF_OP_READ:
 break;
 case BLKIF_OP_FLUSH_DISKCACHE:
 request->presync = 1;
 if (!request->req.nr_segments) {
 return 0;
 }
-/* fall through */
+fallthrough;
 case BLKIF_OP_WRITE:
 break;
 case BLKIF_OP_DISCARD:
 return 0;
 default:
 error_report("error: unknown operation (%d)", request->req.operation);
 goto err;
 };
 
 if (request->req.operation != BLKIF_OP_READ &&
 !blk_is_writable(dataplane->blk)) {
 error_report("error: write req for ro device");
 goto err;
 }
 
 request->start = request->req.sector_number * dataplane->sector_size;
 for (i = 0; i < request->req.nr_segments; i++) {
 if (i == BLKIF_MAX_SEGMENTS_PER_REQUEST) {
 error_report("error: nr_segments too big");
 goto err;
 }
 if (request->req.seg[i].first_sect > request->req.seg[i].last_sect) {
 error_report("error: first > last sector");
 goto err;
 }
 if (request->req.seg[i].last_sect * dataplane->sector_size >=
 XEN_PAGE_SIZE) {
 error_report("error: page crossing");
 goto err;
 }
 
 len = (request->req.seg[i].last_sect -
request->req.seg[i].first_sect + 1) * dataplane->sector_size;
 request->size += len;
 }
 if (request->start + request->size > blk_getlength(dataplane->blk)) {
 error_report("error: access beyond end of file");
 goto err;
 }
 return 0;
@@ -257,63 +257,63 @@ static int xen_block_do_aio(XenBlockRequest *request);
 static void xen_block_complete_aio(void *opaque, int ret)
 {
 XenBlockRequest *request = opaque;
 XenBlockDataPlane *dataplane = request->dataplane;
 
 aio_context_acquire(dataplane->ctx);
 
 if (ret != 0) {
 error_report("%s I/O error",
  request->req.operation == BLKIF_OP_READ ?
  "read" : "write");
 request->aio_errors++;
 }
 
 request->aio_inflight--;
 if (request->presync) {
 request->presync = 0;
 xen_block_do_aio(request);
 goto done;
 }
 if (request->aio_inflight > 0) {
 goto done;
 }
 
 switch (request->req.operation) {
 case BLKIF_OP_READ:
 /* in case of failure request->aio_errors is increased */
 if (ret == 0) {
 xen_block_copy_request(request);
 }
 break;
 case BLKIF_OP_WRITE:
 case BLKIF_OP_FLUSH_DISKCACHE:
 default:
 break;
 }
 
 request->status = request->aio_errors ? BLKIF_RSP_ERROR : BLKIF_RSP_OKAY;
 
 switch (request->req.operation) {
 case BLKIF_OP_WRITE:
 case BLKIF_OP_FLUSH_DISKCACHE:
 if (!request->req.nr_segments) {
 break;
 }
-/* fall through */
+fallthrough;
 case BLKIF_OP_READ:
 if (request->status == BLKIF_RSP_OKAY) {
 block_acct_done(blk_get_stats(dataplane->blk), &request->acct);
 } else {
 block_acct_failed(blk_get_stats(dataplane->blk), &request->acct);
 }
 break;
 case BLKIF_OP_DISCARD:
 default:
 break;
 }
 
 xen_block_complete_request(request);
 
 if (dataplane->more_work) {
 qemu_bh_schedule(dataplane->bh);
 }
diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index afc3fdf4d6..523c34da71 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -1117,360 +1117,360 @@ static bool is_valid_aai_cmd(uint32_t cmd)
 static void decode_new_cmd(Flash *s, uint32_t value)
 {
 int i;
 
 s->cmd_in_progress = value;
 trace_m25p80_command_decoded(s, value);
 
 if (value != RESET_MEMORY) {
 s->reset_enable = false;
 }
 
 if (get_man(s) == MAN_SST && s->aai_enable && !is_valid_aai_cmd(value)) {
 qemu_log_mask(LOG_GUEST_ERROR,
   "M25P80: Invalid cmd within 

[RFC PATCH 15/78] accel/tcg: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 accel/tcg/cputlb.c | 4 ++--
 accel/tcg/ldst_atomicity.c.inc | 2 +-
 accel/tcg/plugin-gen.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c
index b8c5e345b8..92b7ab529a 100644
--- a/accel/tcg/cputlb.c
+++ b/accel/tcg/cputlb.c
@@ -2209,53 +2209,53 @@ static Int128 do_ld_whole_be16(CPUState *cpu, uintptr_t 
ra,
 /*
  * Wrapper for the above.
  */
 static uint64_t do_ld_beN(CPUState *cpu, MMULookupPageData *p,
   uint64_t ret_be, int mmu_idx, MMUAccessType type,
   MemOp mop, uintptr_t ra)
 {
 MemOp atom;
 unsigned tmp, half_size;
 
 if (unlikely(p->flags & TLB_MMIO)) {
 return do_ld_mmio_beN(cpu, p->full, ret_be, p->addr, p->size,
   mmu_idx, type, ra);
 }
 
 /*
  * It is a given that we cross a page and therefore there is no
  * atomicity for the load as a whole, but subobjects may need attention.
  */
 atom = mop & MO_ATOM_MASK;
 switch (atom) {
 case MO_ATOM_SUBALIGN:
 return do_ld_parts_beN(p, ret_be);
 
 case MO_ATOM_IFALIGN_PAIR:
 case MO_ATOM_WITHIN16_PAIR:
 tmp = mop & MO_SIZE;
 tmp = tmp ? tmp - 1 : 0;
 half_size = 1 << tmp;
 if (atom == MO_ATOM_IFALIGN_PAIR
 ? p->size == half_size
 : p->size >= half_size) {
 if (!HAVE_al8_fast && p->size < 4) {
 return do_ld_whole_be4(p, ret_be);
 } else {
 return do_ld_whole_be8(cpu, ra, p, ret_be);
 }
 }
-/* fall through */
+fallthrough;
 
 case MO_ATOM_IFALIGN:
 case MO_ATOM_WITHIN16:
 case MO_ATOM_NONE:
 return do_ld_bytes_beN(p, ret_be);
 
 default:
 g_assert_not_reached();
 }
 }
 
 /*
  * Wrapper for the above, for 8 < size < 16.
  */
@@ -2625,57 +2625,57 @@ static uint64_t do_st16_mmio_leN(CPUState *cpu, 
CPUTLBEntryFull *full,
 /*
  * Wrapper for the above.
  */
 static uint64_t do_st_leN(CPUState *cpu, MMULookupPageData *p,
   uint64_t val_le, int mmu_idx,
   MemOp mop, uintptr_t ra)
 {
 MemOp atom;
 unsigned tmp, half_size;
 
 if (unlikely(p->flags & TLB_MMIO)) {
 return do_st_mmio_leN(cpu, p->full, val_le, p->addr,
   p->size, mmu_idx, ra);
 } else if (unlikely(p->flags & TLB_DISCARD_WRITE)) {
 return val_le >> (p->size * 8);
 }
 
 /*
  * It is a given that we cross a page and therefore there is no atomicity
  * for the store as a whole, but subobjects may need attention.
  */
 atom = mop & MO_ATOM_MASK;
 switch (atom) {
 case MO_ATOM_SUBALIGN:
 return store_parts_leN(p->haddr, p->size, val_le);
 
 case MO_ATOM_IFALIGN_PAIR:
 case MO_ATOM_WITHIN16_PAIR:
 tmp = mop & MO_SIZE;
 tmp = tmp ? tmp - 1 : 0;
 half_size = 1 << tmp;
 if (atom == MO_ATOM_IFALIGN_PAIR
 ? p->size == half_size
 : p->size >= half_size) {
 if (!HAVE_al8_fast && p->size <= 4) {
 return store_whole_le4(p->haddr, p->size, val_le);
 } else if (HAVE_al8) {
 return store_whole_le8(p->haddr, p->size, val_le);
 } else {
 cpu_loop_exit_atomic(cpu, ra);
 }
 }
-/* fall through */
+fallthrough;
 
 case MO_ATOM_IFALIGN:
 case MO_ATOM_WITHIN16:
 case MO_ATOM_NONE:
 return store_bytes_leN(p->haddr, p->size, val_le);
 
 default:
 g_assert_not_reached();
 }
 }
 
 /*
  * Wrapper for the above, for 8 < size < 16.
  */
diff --git a/accel/tcg/ldst_atomicity.c.inc b/accel/tcg/ldst_atomicity.c.inc
index 1cf5b92166..3752f74214 100644
--- a/accel/tcg/ldst_atomicity.c.inc
+++ b/accel/tcg/ldst_atomicity.c.inc
@@ -22,86 +22,86 @@
 /**
  * required_atomicity:
  *
  * Return the lg2 bytes of atomicity required by @memop for @p.
  * If the operation must be split into two operations to be
  * examined separately for atomicity, return -lg2.
  */
 static int required_atomicity(CPUState *cpu, uintptr_t p, MemOp memop)
 {
 MemOp atom = memop & MO_ATOM_MASK;
 MemOp size = memop & MO_SIZE;
 MemOp half = size ? size - 1 : 0;
 unsigned tmp;
 int atmax;
 
 switch (atom) {
 case MO_ATOM_NONE:
 atmax = MO_8;
 break;
 
 case MO_ATOM_IFALIGN_PAIR:
 size = half;
-/* fall through */
+fallthrough;
 
 case MO_ATOM_IFALIGN:
 tmp = (1 << size) - 1;
 atmax = p & tmp ? MO_8 : size;
 break;
 
 case MO_ATOM_WITHIN16:
 tmp = p & 15;
 atmax = (tmp + (1 << size) <= 16 ? size : MO_8);

[RFC PATCH 11/78] hw/timer: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/timer/a9gtimer.c |  8 ++--
 hw/timer/aspeed_timer.c |  1 +
 hw/timer/pxa2xx_timer.c | 94 -
 hw/timer/renesas_tmr.c  |  2 +-
 hw/timer/sh_timer.c |  8 ++--
 5 files changed, 57 insertions(+), 56 deletions(-)

diff --git a/hw/timer/a9gtimer.c b/hw/timer/a9gtimer.c
index 5e959b6d09..b83d51da96 100644
--- a/hw/timer/a9gtimer.c
+++ b/hw/timer/a9gtimer.c
@@ -135,40 +135,40 @@ static void a9_gtimer_update_no_sync(void *opaque)
 static uint64_t a9_gtimer_read(void *opaque, hwaddr addr, unsigned size)
 {
 A9GTimerPerCPU *gtb = (A9GTimerPerCPU *)opaque;
 A9GTimerState *s = gtb->parent;
 A9GTimerUpdate update;
 uint64_t ret = 0;
 int shift = 0;
 
 switch (addr) {
 case R_COUNTER_HI:
 shift = 32;
-/* fallthrough */
+fallthrough;
 case R_COUNTER_LO:
 update = a9_gtimer_get_update(s);
 ret = extract64(update.new, shift, 32);
 break;
 case R_CONTROL:
 ret = s->control | gtb->control;
 break;
 case R_INTERRUPT_STATUS:
 ret = gtb->status;
 break;
 case R_COMPARATOR_HI:
 shift = 32;
-/* fallthrough */
+fallthrough;
 case R_COMPARATOR_LO:
 ret = extract64(gtb->compare, shift, 32);
 break;
 case R_AUTO_INCREMENT:
 ret =  gtb->inc;
 break;
 default:
 qemu_log_mask(LOG_GUEST_ERROR, "bad a9gtimer register: %x\n",
   (unsigned)addr);
 return 0;
 }
 
 DB_PRINT("addr:%#x data:%#08" PRIx64 "\n", (unsigned)addr, ret);
 return ret;
 }
@@ -176,54 +176,54 @@ static uint64_t a9_gtimer_read(void *opaque, hwaddr addr, 
unsigned size)
 static void a9_gtimer_write(void *opaque, hwaddr addr, uint64_t value,
 unsigned size)
 {
 A9GTimerPerCPU *gtb = (A9GTimerPerCPU *)opaque;
 A9GTimerState *s = gtb->parent;
 int shift = 0;
 
 DB_PRINT("addr:%#x data:%#08" PRIx64 "\n", (unsigned)addr, value);
 
 switch (addr) {
 case R_COUNTER_HI:
 shift = 32;
-/* fallthrough */
+fallthrough;
 case R_COUNTER_LO:
 /*
  * Keep it simple - ARM docco explicitly says to disable timer before
  * modding it, so don't bother trying to do all the difficult on the 
fly
  * timer modifications - (if they even work in real hardware??).
  */
 if (s->control & R_CONTROL_TIMER_ENABLE) {
 qemu_log_mask(LOG_GUEST_ERROR, "Cannot mod running ARM gtimer\n");
 return;
 }
 s->counter = deposit64(s->counter, shift, 32, value);
 return;
 case R_CONTROL:
 a9_gtimer_update(s, (value ^ s->control) & R_CONTROL_NEEDS_SYNC);
 gtb->control = value & R_CONTROL_BANKED;
 s->control = value & ~R_CONTROL_BANKED;
 break;
 case R_INTERRUPT_STATUS:
 a9_gtimer_update(s, false);
 gtb->status &= ~value;
 break;
 case R_COMPARATOR_HI:
 shift = 32;
-/* fallthrough */
+fallthrough;
 case R_COMPARATOR_LO:
 a9_gtimer_update(s, false);
 gtb->compare = deposit64(gtb->compare, shift, 32, value);
 break;
 case R_AUTO_INCREMENT:
 gtb->inc = value;
 return;
 default:
 return;
 }
 
 a9_gtimer_update(s, false);
 }
 
 /* Wrapper functions to implement the "read global timer for
  * the current CPU" memory regions.
  */
diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c
index 72161f07bb..b343b7ab2c 100644
--- a/hw/timer/aspeed_timer.c
+++ b/hw/timer/aspeed_timer.c
@@ -266,53 +266,54 @@ static uint64_t aspeed_timer_read(void *opaque, hwaddr 
offset, unsigned size)
 static void aspeed_timer_set_value(AspeedTimerCtrlState *s, int timer, int reg,
uint32_t value)
 {
 AspeedTimer *t;
 uint32_t old_reload;
 
 trace_aspeed_timer_set_value(timer, reg, value);
 t = &s->timers[timer];
 switch (reg) {
 case TIMER_REG_RELOAD:
 old_reload = t->reload;
 t->reload = calculate_min_ticks(t, value);
 
 /* If the reload value was not previously set, or zero, and
  * the current value is valid, try to start the timer if it is
  * enabled.
  */
 if (old_reload || !t->reload) {
 break;
 }
 /* fall through to re-enable */
+fallthrough;
 case TIMER_REG_STATUS:
 if (timer_enabled(t)) {
 uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
 int64_t delta = (int64_t) value - (int64_t) calculate_ticks(t, 
now);
 uint32_t rate = calculate_rate(t);
 
 if (delta >= 0) {
 t->start += muldiv64(delta, NANOSECONDS_PER_SECO

[RFC PATCH 05/78] qobject/json: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 qobject/json-lexer.c  | 4 ++--
 qobject/json-parser.c | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c
index 51341d96e4..ab74470ac6 100644
--- a/qobject/json-lexer.c
+++ b/qobject/json-lexer.c
@@ -283,61 +283,61 @@ void json_lexer_init(JSONLexer *lexer, bool 
enable_interpolation)
 static void json_lexer_feed_char(JSONLexer *lexer, char ch, bool flush)
 {
 int new_state;
 bool char_consumed = false;
 
 lexer->x++;
 if (ch == '\n') {
 lexer->x = 0;
 lexer->y++;
 }
 
 while (flush ? lexer->state != lexer->start_state : !char_consumed) {
 new_state = next_state(lexer, ch, flush, &char_consumed);
 if (char_consumed) {
 assert(!flush);
 g_string_append_c(lexer->token, ch);
 }
 
 switch (new_state) {
 case JSON_LCURLY:
 case JSON_RCURLY:
 case JSON_LSQUARE:
 case JSON_RSQUARE:
 case JSON_COLON:
 case JSON_COMMA:
 case JSON_INTERP:
 case JSON_INTEGER:
 case JSON_FLOAT:
 case JSON_KEYWORD:
 case JSON_STRING:
 json_message_process_token(lexer, lexer->token, new_state,
lexer->x, lexer->y);
-/* fall through */
+fallthrough;
 case IN_START:
 g_string_truncate(lexer->token, 0);
 new_state = lexer->start_state;
 break;
 case JSON_ERROR:
 json_message_process_token(lexer, lexer->token, JSON_ERROR,
lexer->x, lexer->y);
 new_state = IN_RECOVERY;
-/* fall through */
+fallthrough;
 case IN_RECOVERY:
 g_string_truncate(lexer->token, 0);
 break;
 default:
 break;
 }
 lexer->state = new_state;
 }
 
 /* Do not let a single token grow to an arbitrarily large size,
  * this is a security consideration.
  */
 if (lexer->token->len > MAX_TOKEN_SIZE) {
 json_message_process_token(lexer, lexer->token, lexer->state,
lexer->x, lexer->y);
 g_string_truncate(lexer->token, 0);
 lexer->state = lexer->start_state;
 }
 }
diff --git a/qobject/json-parser.c b/qobject/json-parser.c
index d498db6e70..4dc622dcc9 100644
--- a/qobject/json-parser.c
+++ b/qobject/json-parser.c
@@ -95,137 +95,137 @@ static int cvt4hex(const char *s)
 /**
  * parse_string(): Parse a JSON string
  *
  * From RFC 8259 "The JavaScript Object Notation (JSON) Data
  * Interchange Format":
  *
  *char = unescaped /
  *escape (
  *%x22 /  ; "quotation mark  U+0022
  *%x5C /  ; \reverse solidus U+005C
  *%x2F /  ; /solidus U+002F
  *%x62 /  ; bbackspace   U+0008
  *%x66 /  ; fform feed   U+000C
  *%x6E /  ; nline feed   U+000A
  *%x72 /  ; rcarriage return U+000D
  *%x74 /  ; ttab U+0009
  *%x75 4HEXDIG )  ; uU+
  *escape = %x5C  ; \
  *quotation-mark = %x22  ; "
  *unescaped = %x20-21 / %x23-5B / %x5D-10
  *
  * Extensions over RFC 8259:
  * - Extra escape sequence in strings:
  *   0x27 (apostrophe) is recognized after escape, too
  * - Single-quoted strings:
  *   Like double-quoted strings, except they're delimited by %x27
  *   (apostrophe) instead of %x22 (quotation mark), and can't contain
  *   unescaped apostrophe, but can contain unescaped quotation mark.
  *
  * Note:
  * - Encoding is modified UTF-8.
  * - Invalid Unicode characters are rejected.
  * - Control characters \x00..\x1F are rejected by the lexer.
  */
 static QString *parse_string(JSONParserContext *ctxt, JSONToken *token)
 {
 const char *ptr = token->str;
 GString *str;
 char quote;
 const char *beg;
 int cp, trailing;
 char *end;
 ssize_t len;
 char utf8_buf[5];
 
 assert(*ptr == '"' || *ptr == '\'');
 quote = *ptr++;
 str = g_string_new(NULL);
 
 while (*ptr != quote) {
 assert(*ptr);
 switch (*ptr) {
 case '\\':
 beg = ptr++;
 switch (*ptr++) {
 case '"':
 g_string_append_c(str, '"');
 break;
 case '\'':
 g_string_append_c(str, '\'');
 break;
 case '\\':
 g_string_append_c(str, '\\');
 break;
 case '/':
 g_string_append_c(str, '/');
 break;
  

[RFC PATCH 01/78] include/qemu/compiler.h: replace QEMU_FALLTHROUGH with fallthrough

2023-10-13 Thread Emmanouil Pitsidianakis
Signed-off-by: Emmanouil Pitsidianakis 
---
 audio/pwaudio.c  |  8 
 hw/arm/smmuv3.c  |  2 +-
 include/qemu/compiler.h  | 30 +++---
 include/qemu/osdep.h |  4 ++--
 target/loongarch/cpu.c   |  4 ++--
 target/loongarch/translate.c |  2 +-
 tcg/optimize.c   |  8 
 7 files changed, 37 insertions(+), 21 deletions(-)

diff --git a/audio/pwaudio.c b/audio/pwaudio.c
index 3ce5f6507b..bf26fadb06 100644
--- a/audio/pwaudio.c
+++ b/audio/pwaudio.c
@@ -1,29 +1,29 @@
 /*
  * QEMU PipeWire audio driver
  *
  * Copyright (c) 2023 Red Hat Inc.
  *
  * Author: Dorinda Bassey   
  *
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
+#include 
+#include 
+#include 
+#include 
 #include "qemu/osdep.h"
 #include "qemu/module.h"
 #include "audio.h"
 #include 
 #include "qemu/error-report.h"
 #include "qapi/error.h"
-#include 
-#include 
-#include 
-#include 
 
 #include 
 #include "trace.h"
 
 #define AUDIO_CAP "pipewire"
 #define RINGBUFFER_SIZE(1u << 22)
 #define RINGBUFFER_MASK(RINGBUFFER_SIZE - 1)
 
 #include "audio_int.h"
diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
index 6f2b2bd45f..545d82ff04 100644
--- a/hw/arm/smmuv3.c
+++ b/hw/arm/smmuv3.c
@@ -1166,210 +1166,210 @@ smmuv3_invalidate_ste(gpointer key, gpointer value, 
gpointer user_data)
 static int smmuv3_cmdq_consume(SMMUv3State *s)
 {
 SMMUState *bs = ARM_SMMU(s);
 SMMUCmdError cmd_error = SMMU_CERROR_NONE;
 SMMUQueue *q = &s->cmdq;
 SMMUCommandType type = 0;
 
 if (!smmuv3_cmdq_enabled(s)) {
 return 0;
 }
 /*
  * some commands depend on register values, typically CR0. In case those
  * register values change while handling the command, spec says it
  * is UNPREDICTABLE whether the command is interpreted under the new
  * or old value.
  */
 
 while (!smmuv3_q_empty(q)) {
 uint32_t pending = s->gerror ^ s->gerrorn;
 Cmd cmd;
 
 trace_smmuv3_cmdq_consume(Q_PROD(q), Q_CONS(q),
   Q_PROD_WRAP(q), Q_CONS_WRAP(q));
 
 if (FIELD_EX32(pending, GERROR, CMDQ_ERR)) {
 break;
 }
 
 if (queue_read(q, &cmd) != MEMTX_OK) {
 cmd_error = SMMU_CERROR_ABT;
 break;
 }
 
 type = CMD_TYPE(&cmd);
 
 trace_smmuv3_cmdq_opcode(smmu_cmd_string(type));
 
 qemu_mutex_lock(&s->mutex);
 switch (type) {
 case SMMU_CMD_SYNC:
 if (CMD_SYNC_CS(&cmd) & CMD_SYNC_SIG_IRQ) {
 smmuv3_trigger_irq(s, SMMU_IRQ_CMD_SYNC, 0);
 }
 break;
 case SMMU_CMD_PREFETCH_CONFIG:
 case SMMU_CMD_PREFETCH_ADDR:
 break;
 case SMMU_CMD_CFGI_STE:
 {
 uint32_t sid = CMD_SID(&cmd);
 IOMMUMemoryRegion *mr = smmu_iommu_mr(bs, sid);
 SMMUDevice *sdev;
 
 if (CMD_SSEC(&cmd)) {
 cmd_error = SMMU_CERROR_ILL;
 break;
 }
 
 if (!mr) {
 break;
 }
 
 trace_smmuv3_cmdq_cfgi_ste(sid);
 sdev = container_of(mr, SMMUDevice, iommu);
 smmuv3_flush_config(sdev);
 
 break;
 }
 case SMMU_CMD_CFGI_STE_RANGE: /* same as SMMU_CMD_CFGI_ALL */
 {
 uint32_t sid = CMD_SID(&cmd), mask;
 uint8_t range = CMD_STE_RANGE(&cmd);
 SMMUSIDRange sid_range;
 
 if (CMD_SSEC(&cmd)) {
 cmd_error = SMMU_CERROR_ILL;
 break;
 }
 
 mask = (1ULL << (range + 1)) - 1;
 sid_range.start = sid & ~mask;
 sid_range.end = sid_range.start + mask;
 
 trace_smmuv3_cmdq_cfgi_ste_range(sid_range.start, sid_range.end);
 g_hash_table_foreach_remove(bs->configs, smmuv3_invalidate_ste,
 &sid_range);
 break;
 }
 case SMMU_CMD_CFGI_CD:
 case SMMU_CMD_CFGI_CD_ALL:
 {
 uint32_t sid = CMD_SID(&cmd);
 IOMMUMemoryRegion *mr = smmu_iommu_mr(bs, sid);
 SMMUDevice *sdev;
 
 if (CMD_SSEC(&cmd)) {
 cmd_error = SMMU_CERROR_ILL;
 break;
 }
 
 if (!mr) {
 break;
 }
 
 trace_smmuv3_cmdq_cfgi_cd(sid);
 sdev = container_of(mr, SMMUDevice, iommu);
 smmuv3_flush_config(sdev);
 break;
 }
 case SMMU_CMD_TLBI_NH_ASID:
 {
 uint16_t asid = CMD_ASID(&cmd);
 
 if (!STAGE1_SUPPORTED(s)) {
 cmd_error = SMMU_CERROR_ILL;
 break;
 }
 
 trace_smmuv3_cmdq_tlbi_nh_asid(asid);
 smmu_inv_notifiers_all(&s->smmu_state);
 smmu_iotlb_inv_asid(bs, asid);
 break;
 

[RFC PATCH 18/78] ui/win32-kbd-hook.c: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 ui/win32-kbd-hook.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/ui/win32-kbd-hook.c b/ui/win32-kbd-hook.c
index 1ac237db9e..3c5c3fc597 100644
--- a/ui/win32-kbd-hook.c
+++ b/ui/win32-kbd-hook.c
@@ -18,59 +18,52 @@ static DWORD win32_grab;
 static LRESULT CALLBACK keyboard_hook_cb(int code, WPARAM wparam, LPARAM 
lparam)
 {
 if  (win32_window && code == HC_ACTION && win32_window == GetFocus()) {
 KBDLLHOOKSTRUCT *hooked = (KBDLLHOOKSTRUCT *)lparam;
 
 if (wparam != WM_KEYUP) {
 DWORD dwmsg = (hooked->flags << 24) |
   ((hooked->scanCode & 0xff) << 16) | 1;
 
 switch (hooked->vkCode) {
 case VK_CAPITAL:
-/* fall through */
 case VK_SCROLL:
-/* fall through */
 case VK_NUMLOCK:
-/* fall through */
 case VK_LSHIFT:
-/* fall through */
 case VK_RSHIFT:
-/* fall through */
 case VK_RCONTROL:
-/* fall through */
 case VK_LMENU:
-/* fall through */
 case VK_RMENU:
 break;
 
 case VK_LCONTROL:
 /*
  * When pressing AltGr, an extra VK_LCONTROL with a special
  * scancode with bit 9 set is sent. Let's ignore the extra
  * VK_LCONTROL, as that will make AltGr misbehave.
  */
 if (hooked->scanCode & 0x200) {
 return 1;
 }
 break;
 
 default:
 if (win32_grab) {
 SendMessage(win32_window, wparam, hooked->vkCode, dwmsg);
 return 1;
 }
 break;
 }
 
 } else {
 switch (hooked->vkCode) {
 case VK_LCONTROL:
 if (hooked->scanCode & 0x200) {
 return 1;
 }
 break;
 }
 }
 }
 
 return CallNextHookEx(NULL, code, wparam, lparam);
 }
-- 
2.39.2




[RFC PATCH 03/78] fpu/softfloat: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 fpu/softfloat-parts.c.inc | 8 
 fpu/softfloat.c   | 7 ---
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc
index a44649f4f4..df64cc7a29 100644
--- a/fpu/softfloat-parts.c.inc
+++ b/fpu/softfloat-parts.c.inc
@@ -138,166 +138,166 @@ static void partsN(canonicalize)(FloatPartsN *p, 
float_status *status,
 /*
  * Round and uncanonicalize a floating-point number by parts. There
  * are FRAC_SHIFT bits that may require rounding at the bottom of the
  * fraction; these bits will be removed. The exponent will be biased
  * by EXP_BIAS and must be bounded by [EXP_MAX-1, 0].
  */
 static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s,
const FloatFmt *fmt)
 {
 const int exp_max = fmt->exp_max;
 const int frac_shift = fmt->frac_shift;
 const uint64_t round_mask = fmt->round_mask;
 const uint64_t frac_lsb = round_mask + 1;
 const uint64_t frac_lsbm1 = round_mask ^ (round_mask >> 1);
 const uint64_t roundeven_mask = round_mask | frac_lsb;
 uint64_t inc;
 bool overflow_norm = false;
 int exp, flags = 0;
 
 switch (s->float_rounding_mode) {
 case float_round_nearest_even:
 if (N > 64 && frac_lsb == 0) {
 inc = ((p->frac_hi & 1) || (p->frac_lo & round_mask) != frac_lsbm1
? frac_lsbm1 : 0);
 } else {
 inc = ((p->frac_lo & roundeven_mask) != frac_lsbm1
? frac_lsbm1 : 0);
 }
 break;
 case float_round_ties_away:
 inc = frac_lsbm1;
 break;
 case float_round_to_zero:
 overflow_norm = true;
 inc = 0;
 break;
 case float_round_up:
 inc = p->sign ? 0 : round_mask;
 overflow_norm = p->sign;
 break;
 case float_round_down:
 inc = p->sign ? round_mask : 0;
 overflow_norm = !p->sign;
 break;
 case float_round_to_odd:
 overflow_norm = true;
-/* fall through */
+fallthrough;
 case float_round_to_odd_inf:
 if (N > 64 && frac_lsb == 0) {
 inc = p->frac_hi & 1 ? 0 : round_mask;
 } else {
 inc = p->frac_lo & frac_lsb ? 0 : round_mask;
 }
 break;
 default:
 g_assert_not_reached();
 }
 
 exp = p->exp + fmt->exp_bias;
 if (likely(exp > 0)) {
 if (p->frac_lo & round_mask) {
 flags |= float_flag_inexact;
 if (frac_addi(p, p, inc)) {
 frac_shr(p, 1);
 p->frac_hi |= DECOMPOSED_IMPLICIT_BIT;
 exp++;
 }
 p->frac_lo &= ~round_mask;
 }
 
 if (fmt->arm_althp) {
 /* ARM Alt HP eschews Inf and NaN for a wider exponent.  */
 if (unlikely(exp > exp_max)) {
 /* Overflow.  Return the maximum normal.  */
 flags = float_flag_invalid;
 exp = exp_max;
 frac_allones(p);
 p->frac_lo &= ~round_mask;
 }
 } else if (unlikely(exp >= exp_max)) {
 flags |= float_flag_overflow;
 if (s->rebias_overflow) {
 exp -= fmt->exp_re_bias;
 } else if (overflow_norm) {
 flags |= float_flag_inexact;
 exp = exp_max - 1;
 frac_allones(p);
 p->frac_lo &= ~round_mask;
 } else {
 flags |= float_flag_inexact;
 p->cls = float_class_inf;
 exp = exp_max;
 frac_clear(p);
 }
 }
 frac_shr(p, frac_shift);
 } else if (unlikely(s->rebias_underflow)) {
 flags |= float_flag_underflow;
 exp += fmt->exp_re_bias;
 if (p->frac_lo & round_mask) {
 flags |= float_flag_inexact;
 if (frac_addi(p, p, inc)) {
 frac_shr(p, 1);
 p->frac_hi |= DECOMPOSED_IMPLICIT_BIT;
 exp++;
 }
 p->frac_lo &= ~round_mask;
 }
 frac_shr(p, frac_shift);
 } else if (s->flush_to_zero) {
 flags |= float_flag_output_denormal;
 p->cls = float_class_zero;
 exp = 0;
 frac_clear(p);
 } else {
 bool is_tiny = s->tininess_before_rounding || exp < 0;
 
 if (!is_tiny) {
 FloatPartsN discard;
 is_tiny = !frac_addi(&discard, p, inc);
 }
 
 frac_shrjam(p, !fmt->m68k_denormal - exp);
 
 if (p->frac_lo & round_mask) {
 /* Need to recompute round-to-even/round-to-odd. */
 switch (s->float_rounding_mode) {
 case float_round_nearest_even:
 if 

[RFC PATCH 36/78] target/openrisc: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/openrisc/mmu.c   | 2 +-
 target/openrisc/translate.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/openrisc/mmu.c b/target/openrisc/mmu.c
index 603c26715e..7ed744e81b 100644
--- a/target/openrisc/mmu.c
+++ b/target/openrisc/mmu.c
@@ -141,38 +141,38 @@ bool openrisc_cpu_tlb_fill(CPUState *cs, vaddr addr, int 
size,
 hwaddr openrisc_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
 {
 OpenRISCCPU *cpu = OPENRISC_CPU(cs);
 int prot, excp, sr = cpu->env.sr;
 hwaddr phys_addr;
 
 switch (sr & (SR_DME | SR_IME)) {
 case SR_DME | SR_IME:
 /* The mmu is definitely enabled.  */
 excp = get_phys_mmu(cpu, &phys_addr, &prot, addr,
 PAGE_READ,
 (sr & SR_SM) != 0);
 if (!excp) {
 return phys_addr;
 }
 excp = get_phys_mmu(cpu, &phys_addr, &prot, addr,
 PAGE_EXEC,
 (sr & SR_SM) != 0);
 return excp ? -1 : phys_addr;
 
 default:
 /* The mmu is partially enabled, and we don't really have
a "real" access type.  Begin by trying the mmu, but if
that fails try again without.  */
 excp = get_phys_mmu(cpu, &phys_addr, &prot, addr,
 PAGE_EXEC | PAGE_READ | PAGE_WRITE,
 (sr & SR_SM) != 0);
 if (!excp) {
 return phys_addr;
 }
-/* fallthru */
+fallthrough;
 
 case 0:
 /* The mmu is definitely disabled; lookups never fail.  */
 get_phys_nommu(&phys_addr, &prot, addr);
 return phys_addr;
 }
 }
diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c
index ecff4412b7..de77014d60 100644
--- a/target/openrisc/translate.c
+++ b/target/openrisc/translate.c
@@ -1588,53 +1588,53 @@ static void openrisc_tr_translate_insn(DisasContextBase 
*dcbase, CPUState *cs)
 static void openrisc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
 {
 DisasContext *dc = container_of(dcbase, DisasContext, base);
 target_ulong jmp_dest;
 
 /* If we have already exited the TB, nothing following has effect.  */
 if (dc->base.is_jmp == DISAS_NORETURN) {
 return;
 }
 
 /* Adjust the delayed branch state for the next TB.  */
 if ((dc->tb_flags & TB_FLAGS_DFLAG ? 1 : 0) != (dc->delayed_branch != 0)) {
 tcg_gen_movi_i32(cpu_dflag, dc->delayed_branch != 0);
 }
 
 /* For DISAS_TOO_MANY, jump to the next insn.  */
 jmp_dest = dc->base.pc_next;
 tcg_gen_movi_tl(cpu_ppc, jmp_dest - 4);
 
 switch (dc->base.is_jmp) {
 case DISAS_JUMP:
 jmp_dest = dc->jmp_pc_imm;
 if (jmp_dest == -1) {
 /* The jump destination is indirect/computed; use jmp_pc.  */
 tcg_gen_mov_tl(cpu_pc, jmp_pc);
 tcg_gen_discard_tl(jmp_pc);
 tcg_gen_lookup_and_goto_ptr();
 break;
 }
 /* The jump destination is direct; use jmp_pc_imm.
However, we will have stored into jmp_pc as well;
we know now that it wasn't needed.  */
 tcg_gen_discard_tl(jmp_pc);
-/* fallthru */
+fallthrough;
 
 case DISAS_TOO_MANY:
 if (translator_use_goto_tb(&dc->base, jmp_dest)) {
 tcg_gen_goto_tb(0);
 tcg_gen_movi_tl(cpu_pc, jmp_dest);
 tcg_gen_exit_tb(dc->base.tb, 0);
 break;
 }
 tcg_gen_movi_tl(cpu_pc, jmp_dest);
 tcg_gen_lookup_and_goto_ptr();
 break;
 
 case DISAS_EXIT:
 tcg_gen_exit_tb(NULL, 0);
 break;
 default:
 g_assert_not_reached();
 }
 }
-- 
2.39.2




[RFC PATCH 13/78] hw/adc: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/adc/aspeed_adc.c | 12 ++--
 hw/adc/zynq-xadc.c  |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/hw/adc/aspeed_adc.c b/hw/adc/aspeed_adc.c
index 0d29663129..f9f5f7bb17 100644
--- a/hw/adc/aspeed_adc.c
+++ b/hw/adc/aspeed_adc.c
@@ -107,59 +107,59 @@ static uint32_t read_channel_sample(AspeedADCEngineState 
*s, int reg)
 static uint64_t aspeed_adc_engine_read(void *opaque, hwaddr addr,
unsigned int size)
 {
 AspeedADCEngineState *s = ASPEED_ADC_ENGINE(opaque);
 int reg = TO_REG(addr);
 uint32_t value = 0;
 
 switch (reg) {
 case BOUNDS_CHANNEL_8 ... BOUNDS_CHANNEL_15:
 if (s->nr_channels <= 8) {
 qemu_log_mask(LOG_GUEST_ERROR, "%s: engine[%u]: "
   "bounds register %u invalid, only 0...7 valid\n",
   __func__, s->engine_id, reg - BOUNDS_CHANNEL_0);
 break;
 }
-/* fallthrough */
+fallthrough;
 case HYSTERESIS_CHANNEL_8 ... HYSTERESIS_CHANNEL_15:
 if (s->nr_channels <= 8) {
 qemu_log_mask(LOG_GUEST_ERROR, "%s: engine[%u]: "
   "hysteresis register %u invalid, only 0...7 valid\n",
   __func__, s->engine_id, reg - HYSTERESIS_CHANNEL_0);
 break;
 }
-/* fallthrough */
+fallthrough;
 case BOUNDS_CHANNEL_0 ... BOUNDS_CHANNEL_7:
 case HYSTERESIS_CHANNEL_0 ... HYSTERESIS_CHANNEL_7:
 case ENGINE_CONTROL:
 case INTERRUPT_CONTROL:
 case VGA_DETECT_CONTROL:
 case CLOCK_CONTROL:
 case INTERRUPT_SOURCE:
 case COMPENSATING_AND_TRIMMING:
 value = s->regs[reg];
 break;
 case DATA_CHANNEL_9_AND_8 ... DATA_CHANNEL_15_AND_14:
 if (s->nr_channels <= 8) {
 qemu_log_mask(LOG_GUEST_ERROR, "%s: engine[%u]: "
   "data register %u invalid, only 0...3 valid\n",
   __func__, s->engine_id, reg - DATA_CHANNEL_1_AND_0);
 break;
 }
-/* fallthrough */
+fallthrough;
 case DATA_CHANNEL_1_AND_0 ... DATA_CHANNEL_7_AND_6:
 value = read_channel_sample(s, reg);
 /* Allow 16-bit reads of the data registers */
 if (addr & 0x2) {
 assert(size == 2);
 value >>= 16;
 }
 break;
 default:
 qemu_log_mask(LOG_UNIMP, "%s: engine[%u]: 0x%" HWADDR_PRIx "\n",
   __func__, s->engine_id, addr);
 break;
 }
 
 trace_aspeed_adc_engine_read(s->engine_id, addr, value);
 return value;
 }
@@ -167,69 +167,69 @@ static uint64_t aspeed_adc_engine_read(void *opaque, 
hwaddr addr,
 static void aspeed_adc_engine_write(void *opaque, hwaddr addr, uint64_t value,
 unsigned int size)
 {
 AspeedADCEngineState *s = ASPEED_ADC_ENGINE(opaque);
 int reg = TO_REG(addr);
 uint32_t init = 0;
 
 trace_aspeed_adc_engine_write(s->engine_id, addr, value);
 
 switch (reg) {
 case ENGINE_CONTROL:
 init = !!(value & ASPEED_ADC_ENGINE_EN);
 init *= ASPEED_ADC_ENGINE_INIT;
 
 value &= ~ASPEED_ADC_ENGINE_INIT;
 value |= init;
 
 value &= ~ASPEED_ADC_ENGINE_AUTO_COMP;
 break;
 case INTERRUPT_CONTROL:
 case VGA_DETECT_CONTROL:
 case CLOCK_CONTROL:
 break;
 case DATA_CHANNEL_9_AND_8 ... DATA_CHANNEL_15_AND_14:
 if (s->nr_channels <= 8) {
 qemu_log_mask(LOG_GUEST_ERROR, "%s: engine[%u]: "
   "data register %u invalid, only 0...3 valid\n",
   __func__, s->engine_id, reg - DATA_CHANNEL_1_AND_0);
 return;
 }
-/* fallthrough */
+fallthrough;
 case BOUNDS_CHANNEL_8 ... BOUNDS_CHANNEL_15:
 if (s->nr_channels <= 8) {
 qemu_log_mask(LOG_GUEST_ERROR, "%s: engine[%u]: "
   "bounds register %u invalid, only 0...7 valid\n",
   __func__, s->engine_id, reg - BOUNDS_CHANNEL_0);
 return;
 }
-/* fallthrough */
+fallthrough;
 case DATA_CHANNEL_1_AND_0 ... DATA_CHANNEL_7_AND_6:
 case BOUNDS_CHANNEL_0 ... BOUNDS_CHANNEL_7:
 value &= ASPEED_ADC_LH_MASK;
 break;
 case HYSTERESIS_CHANNEL_8 ... HYSTERESIS_CHANNEL_15:
 if (s->nr_channels <= 8) {
 qemu_log_mask(LOG_GUEST_ERROR, "%s: engine[%u]: "
   "hysteresis register %u invalid, only 0...7 valid\n",
   __func__, s->engine_id, reg - HYSTERESIS_CHANNEL_0);
 return;
 }
-/* fallthrough */
+fallthrough;
 case HYSTERESIS_CHANNEL_0 ... HYSTERESIS_CHANNEL_7:
 

[RFC PATCH 37/75] system/rtc.c: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
Signed-off-by: Emmanouil Pitsidianakis 
---
 system/rtc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/system/rtc.c b/system/rtc.c
index 4904581abe..bb406542c8 100644
--- a/system/rtc.c
+++ b/system/rtc.c
@@ -48,22 +48,22 @@ QEMUClockType rtc_clock;
 /***/
 /* RTC reference time/date access */
 static time_t qemu_ref_timedate(QEMUClockType clock)
 {
 time_t value = qemu_clock_get_ms(clock) / 1000;
 switch (clock) {
 case QEMU_CLOCK_REALTIME:
 value -= rtc_realtime_clock_offset;
-/* fall through */
+fallthrough;
 case QEMU_CLOCK_VIRTUAL:
 value += rtc_ref_start_datetime;
 break;
 case QEMU_CLOCK_HOST:
 if (rtc_base_type == RTC_BASE_DATETIME) {
 value -= rtc_host_datetime_offset;
 }
 break;
 default:
 assert(0);
 }
 return value;
 }
-- 
2.39.2




[RFC PATCH 35/78] target/sh4: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/sh4/helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/sh4/helper.c b/target/sh4/helper.c
index e02e7af607..c1cc5e82f4 100644
--- a/target/sh4/helper.c
+++ b/target/sh4/helper.c
@@ -56,131 +56,131 @@ int cpu_sh4_is_cached(CPUSH4State *env, target_ulong addr)
 void superh_cpu_do_interrupt(CPUState *cs)
 {
 SuperHCPU *cpu = SUPERH_CPU(cs);
 CPUSH4State *env = &cpu->env;
 int do_irq = cs->interrupt_request & CPU_INTERRUPT_HARD;
 int do_exp, irq_vector = cs->exception_index;
 
 /* prioritize exceptions over interrupts */
 
 do_exp = cs->exception_index != -1;
 do_irq = do_irq && (cs->exception_index == -1);
 
 if (env->sr & (1u << SR_BL)) {
 if (do_exp && cs->exception_index != 0x1e0) {
 /* In theory a masked exception generates a reset exception,
which in turn jumps to the reset vector. However this only
works when using a bootloader. When using a kernel and an
initrd, they need to be reloaded and the program counter
should be loaded with the kernel entry point.
qemu_system_reset_request takes care of that.  */
 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
 return;
 }
 if (do_irq && !env->in_sleep) {
 return; /* masked */
 }
 }
 env->in_sleep = 0;
 
 if (do_irq) {
 irq_vector = sh_intc_get_pending_vector(env->intc_handle,
(env->sr >> 4) & 0xf);
 if (irq_vector == -1) {
 return; /* masked */
}
 }
 
 if (qemu_loglevel_mask(CPU_LOG_INT)) {
const char *expname;
 switch (cs->exception_index) {
case 0x0e0:
expname = "addr_error";
break;
case 0x040:
expname = "tlb_miss";
break;
case 0x0a0:
expname = "tlb_violation";
break;
case 0x180:
expname = "illegal_instruction";
break;
case 0x1a0:
expname = "slot_illegal_instruction";
break;
case 0x800:
expname = "fpu_disable";
break;
case 0x820:
expname = "slot_fpu";
break;
case 0x100:
expname = "data_write";
break;
case 0x060:
expname = "dtlb_miss_write";
break;
case 0x0c0:
expname = "dtlb_violation_write";
break;
case 0x120:
expname = "fpu_exception";
break;
case 0x080:
expname = "initial_page_write";
break;
case 0x160:
expname = "trapa";
break;
default:
 expname = do_irq ? "interrupt" : "???";
 break;
}
qemu_log("exception 0x%03x [%s] raised\n",
  irq_vector, expname);
 log_cpu_state(cs, 0);
 }
 
 env->ssr = cpu_read_sr(env);
 env->spc = env->pc;
 env->sgr = env->gregs[15];
 env->sr |= (1u << SR_BL) | (1u << SR_MD) | (1u << SR_RB);
 env->lock_addr = -1;
 
 if (env->flags & TB_FLAG_DELAY_SLOT_MASK) {
 /* Branch instruction should be executed again before delay slot. */
env->spc -= 2;
/* Clear flags for exception/interrupt routine. */
 env->flags &= ~TB_FLAG_DELAY_SLOT_MASK;
 }
 
 if (do_exp) {
 env->expevt = cs->exception_index;
 switch (cs->exception_index) {
 case 0x000:
 case 0x020:
 case 0x140:
 env->sr &= ~(1u << SR_FD);
 env->sr |= 0xf << 4; /* IMASK */
 env->pc = 0xa000;
 break;
 case 0x040:
 case 0x060:
 env->pc = env->vbr + 0x400;
 break;
 case 0x160:
 env->spc += 2; /* special case for TRAPA */
-/* fall through */
+fallthrough;
 default:
 env->pc = env->vbr + 0x100;
 break;
 }
 return;
 }
 
 if (do_irq) {
 env->intevt = irq_vector;
 env->pc = env->vbr + 0x600;
 return;
 }
 }
-- 
2.39.2




[RFC PATCH 19/78] target/hppa: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/hppa/translate.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/target/hppa/translate.c b/target/hppa/translate.c
index 9f3ba9f42f..1df81b0fa2 100644
--- a/target/hppa/translate.c
+++ b/target/hppa/translate.c
@@ -480,14 +480,14 @@ static DisasCond cond_make(TCGCond c, TCGv_reg a0, 
TCGv_reg a1)
 static void cond_free(DisasCond *cond)
 {
 switch (cond->c) {
 default:
 cond->a0 = NULL;
 cond->a1 = NULL;
-/* fallthru */
+fallthrough;
 case TCG_COND_ALWAYS:
 cond->c = TCG_COND_NEVER;
 break;
 case TCG_COND_NEVER:
 break;
 }
 }
@@ -3831,65 +3831,65 @@ static bool trans_fcmp_d(DisasContext *ctx, arg_fclass2 
*a)
 static bool trans_ftest(DisasContext *ctx, arg_ftest *a)
 {
 TCGv_reg t;
 
 nullify_over(ctx);
 
 t = get_temp(ctx);
 tcg_gen_ld32u_reg(t, tcg_env, offsetof(CPUHPPAState, fr0_shadow));
 
 if (a->y == 1) {
 int mask;
 bool inv = false;
 
 switch (a->c) {
 case 0: /* simple */
 tcg_gen_andi_reg(t, t, 0x400);
 ctx->null_cond = cond_make_0(TCG_COND_NE, t);
 goto done;
 case 2: /* rej */
 inv = true;
-/* fallthru */
+fallthrough;
 case 1: /* acc */
 mask = 0x43ff800;
 break;
 case 6: /* rej8 */
 inv = true;
-/* fallthru */
+fallthrough;
 case 5: /* acc8 */
 mask = 0x43f8000;
 break;
 case 9: /* acc6 */
 mask = 0x43e;
 break;
 case 13: /* acc4 */
 mask = 0x438;
 break;
 case 17: /* acc2 */
 mask = 0x420;
 break;
 default:
 gen_illegal(ctx);
 return true;
 }
 if (inv) {
 TCGv_reg c = load_const(ctx, mask);
 tcg_gen_or_reg(t, t, c);
 ctx->null_cond = cond_make(TCG_COND_EQ, t, c);
 } else {
 tcg_gen_andi_reg(t, t, mask);
 ctx->null_cond = cond_make_0(TCG_COND_EQ, t);
 }
 } else {
 unsigned cbit = (a->y ^ 1) - 1;
 
 tcg_gen_extract_reg(t, t, 21 - cbit, 1);
 ctx->null_cond = cond_make_0(TCG_COND_NE, t);
 }
 
  done:
 return nullify_end(ctx);
 }
 
 /*
  * Float class 2
  */
@@ -4219,28 +4219,28 @@ static void hppa_tr_translate_insn(DisasContextBase 
*dcbase, CPUState *cs)
 static void hppa_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
 {
 DisasContext *ctx = container_of(dcbase, DisasContext, base);
 DisasJumpType is_jmp = ctx->base.is_jmp;
 
 switch (is_jmp) {
 case DISAS_NORETURN:
 break;
 case DISAS_TOO_MANY:
 case DISAS_IAQ_N_STALE:
 case DISAS_IAQ_N_STALE_EXIT:
 copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_f, cpu_iaoq_f);
 copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_b, cpu_iaoq_b);
 nullify_save(ctx);
-/* FALLTHRU */
+fallthrough;
 case DISAS_IAQ_N_UPDATED:
 if (is_jmp != DISAS_IAQ_N_STALE_EXIT) {
 tcg_gen_lookup_and_goto_ptr();
 break;
 }
-/* FALLTHRU */
+fallthrough;
 case DISAS_EXIT:
 tcg_gen_exit_tb(NULL, 0);
 break;
 default:
 g_assert_not_reached();
 }
 }
-- 
2.39.2




[RFC PATCH 40/75] linux-user: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
Signed-off-by: Emmanouil Pitsidianakis 
---
 linux-user/mips/cpu_loop.c | 8 
 linux-user/mmap.c  | 2 +-
 linux-user/syscall.c   | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/linux-user/mips/cpu_loop.c b/linux-user/mips/cpu_loop.c
index 8735e58bad..38ddcadfc6 100644
--- a/linux-user/mips/cpu_loop.c
+++ b/linux-user/mips/cpu_loop.c
@@ -63,68 +63,68 @@ static void do_tr_or_bp(CPUMIPSState *env, unsigned int 
code, bool trap)
 void cpu_loop(CPUMIPSState *env)
 {
 CPUState *cs = env_cpu(env);
 int trapnr, si_code;
 unsigned int code;
 abi_long ret;
 # ifdef TARGET_ABI_MIPSO32
 unsigned int syscall_num;
 # endif
 
 for(;;) {
 cpu_exec_start(cs);
 trapnr = cpu_exec(cs);
 cpu_exec_end(cs);
 process_queued_cpu_work(cs);
 
 switch(trapnr) {
 case EXCP_SYSCALL:
 env->active_tc.PC += 4;
 # ifdef TARGET_ABI_MIPSO32
 syscall_num = env->active_tc.gpr[2] - 4000;
 if (syscall_num >= sizeof(mips_syscall_args)) {
 /* syscall_num is larger that any defined for MIPS O32 */
 ret = -TARGET_ENOSYS;
 } else if (mips_syscall_args[syscall_num] ==
MIPS_SYSCALL_NUMBER_UNUSED) {
 /* syscall_num belongs to the range not defined for MIPS O32 */
 ret = -TARGET_ENOSYS;
 } else {
 /* syscall_num is valid */
 int nb_args;
 abi_ulong sp_reg;
 abi_ulong arg5 = 0, arg6 = 0, arg7 = 0, arg8 = 0;
 
 nb_args = mips_syscall_args[syscall_num];
 sp_reg = env->active_tc.gpr[29];
 switch (nb_args) {
 /* these arguments are taken from the stack */
 case 8:
 if ((ret = get_user_ual(arg8, sp_reg + 28)) != 0) {
 goto done_syscall;
 }
-/* fall through */
+fallthrough;
 case 7:
 if ((ret = get_user_ual(arg7, sp_reg + 24)) != 0) {
 goto done_syscall;
 }
-/* fall through */
+fallthrough;
 case 6:
 if ((ret = get_user_ual(arg6, sp_reg + 20)) != 0) {
 goto done_syscall;
 }
-/* fall through */
+fallthrough;
 case 5:
 if ((ret = get_user_ual(arg5, sp_reg + 16)) != 0) {
 goto done_syscall;
 }
-/* fall through */
+fallthrough;
 default:
 break;
 }
 ret = do_syscall(env, env->active_tc.gpr[2],
  env->active_tc.gpr[4],
  env->active_tc.gpr[5],
  env->active_tc.gpr[6],
  env->active_tc.gpr[7],
  arg5, arg6, arg7, arg8);
 }
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 8ccaab7859..ff33b4ccf6 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -960,84 +960,84 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong 
old_size,
 abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice)
 {
 abi_ulong len;
 int ret = 0;
 
 if (start & ~TARGET_PAGE_MASK) {
 return -TARGET_EINVAL;
 }
 if (len_in == 0) {
 return 0;
 }
 len = TARGET_PAGE_ALIGN(len_in);
 if (len == 0 || !guest_range_valid_untagged(start, len)) {
 return -TARGET_EINVAL;
 }
 
 /* Translate for some architectures which have different MADV_xxx values */
 switch (advice) {
 case TARGET_MADV_DONTNEED:  /* alpha */
 advice = MADV_DONTNEED;
 break;
 case TARGET_MADV_WIPEONFORK:/* parisc */
 advice = MADV_WIPEONFORK;
 break;
 case TARGET_MADV_KEEPONFORK:/* parisc */
 advice = MADV_KEEPONFORK;
 break;
 /* we do not care about the other MADV_xxx values yet */
 }
 
 /*
  * Most advice values are hints, so ignoring and returning success is ok.
  *
  * However, some advice values such as MADV_DONTNEED, MADV_WIPEONFORK and
  * MADV_KEEPONFORK are not hints and need to be emulated.
  *
  * A straight passthrough for those may not be safe because qemu sometimes
  * turns private file-backed mappings into anonymous mappings.
  * If all guest pages have PAGE_PASSTHROUGH set, mappings have the
  * same semantics for the host as for the guest.
  *
  * We pass through MADV_WIPEONFORK and MADV_KEEPONFORK if possible and
  * return failure if not.
  *
  * MADV_DONTNEED is passed through as well, if possible.
 

[RFC PATCH 34/78] target/tricore: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/tricore/translate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/tricore/translate.c b/target/tricore/translate.c
index dd812ec0f0..4e42f06ec8 100644
--- a/target/tricore/translate.c
+++ b/target/tricore/translate.c
@@ -2899,259 +2899,259 @@ static void gen_fret(DisasContext *ctx)
 static void gen_compute_branch(DisasContext *ctx, uint32_t opc, int r1,
int r2 , int32_t constant , int32_t offset)
 {
 TCGv temp, temp2;
 int n;
 
 switch (opc) {
 /* SB-format jumps */
 case OPC1_16_SB_J:
 case OPC1_32_B_J:
 gen_goto_tb(ctx, 0, ctx->base.pc_next + offset * 2);
 break;
 case OPC1_32_B_CALL:
 case OPC1_16_SB_CALL:
 gen_helper_1arg(call, ctx->pc_succ_insn);
 gen_goto_tb(ctx, 0, ctx->base.pc_next + offset * 2);
 break;
 case OPC1_16_SB_JZ:
 gen_branch_condi(ctx, TCG_COND_EQ, cpu_gpr_d[15], 0, offset);
 break;
 case OPC1_16_SB_JNZ:
 gen_branch_condi(ctx, TCG_COND_NE, cpu_gpr_d[15], 0, offset);
 break;
 /* SBC-format jumps */
 case OPC1_16_SBC_JEQ:
 gen_branch_condi(ctx, TCG_COND_EQ, cpu_gpr_d[15], constant, offset);
 break;
 case OPC1_16_SBC_JEQ2:
 gen_branch_condi(ctx, TCG_COND_EQ, cpu_gpr_d[15], constant,
  offset + 16);
 break;
 case OPC1_16_SBC_JNE:
 gen_branch_condi(ctx, TCG_COND_NE, cpu_gpr_d[15], constant, offset);
 break;
 case OPC1_16_SBC_JNE2:
 gen_branch_condi(ctx, TCG_COND_NE, cpu_gpr_d[15],
  constant, offset + 16);
 break;
 /* SBRN-format jumps */
 case OPC1_16_SBRN_JZ_T:
 temp = tcg_temp_new();
 tcg_gen_andi_tl(temp, cpu_gpr_d[15], 0x1u << constant);
 gen_branch_condi(ctx, TCG_COND_EQ, temp, 0, offset);
 break;
 case OPC1_16_SBRN_JNZ_T:
 temp = tcg_temp_new();
 tcg_gen_andi_tl(temp, cpu_gpr_d[15], 0x1u << constant);
 gen_branch_condi(ctx, TCG_COND_NE, temp, 0, offset);
 break;
 /* SBR-format jumps */
 case OPC1_16_SBR_JEQ:
 gen_branch_cond(ctx, TCG_COND_EQ, cpu_gpr_d[r1], cpu_gpr_d[15],
 offset);
 break;
 case OPC1_16_SBR_JEQ2:
 gen_branch_cond(ctx, TCG_COND_EQ, cpu_gpr_d[r1], cpu_gpr_d[15],
 offset + 16);
 break;
 case OPC1_16_SBR_JNE:
 gen_branch_cond(ctx, TCG_COND_NE, cpu_gpr_d[r1], cpu_gpr_d[15],
 offset);
 break;
 case OPC1_16_SBR_JNE2:
 gen_branch_cond(ctx, TCG_COND_NE, cpu_gpr_d[r1], cpu_gpr_d[15],
 offset + 16);
 break;
 case OPC1_16_SBR_JNZ:
 gen_branch_condi(ctx, TCG_COND_NE, cpu_gpr_d[r1], 0, offset);
 break;
 case OPC1_16_SBR_JNZ_A:
 gen_branch_condi(ctx, TCG_COND_NE, cpu_gpr_a[r1], 0, offset);
 break;
 case OPC1_16_SBR_JGEZ:
 gen_branch_condi(ctx, TCG_COND_GE, cpu_gpr_d[r1], 0, offset);
 break;
 case OPC1_16_SBR_JGTZ:
 gen_branch_condi(ctx, TCG_COND_GT, cpu_gpr_d[r1], 0, offset);
 break;
 case OPC1_16_SBR_JLEZ:
 gen_branch_condi(ctx, TCG_COND_LE, cpu_gpr_d[r1], 0, offset);
 break;
 case OPC1_16_SBR_JLTZ:
 gen_branch_condi(ctx, TCG_COND_LT, cpu_gpr_d[r1], 0, offset);
 break;
 case OPC1_16_SBR_JZ:
 gen_branch_condi(ctx, TCG_COND_EQ, cpu_gpr_d[r1], 0, offset);
 break;
 case OPC1_16_SBR_JZ_A:
 gen_branch_condi(ctx, TCG_COND_EQ, cpu_gpr_a[r1], 0, offset);
 break;
 case OPC1_16_SBR_LOOP:
 gen_loop(ctx, r1, offset * 2 - 32);
 break;
 /* SR-format jumps */
 case OPC1_16_SR_JI:
 tcg_gen_andi_tl(cpu_PC, cpu_gpr_a[r1], 0xfffe);
 ctx->base.is_jmp = DISAS_EXIT;
 break;
 case OPC2_32_SYS_RET:
 case OPC2_16_SR_RET:
 gen_helper_ret(tcg_env);
 ctx->base.is_jmp = DISAS_EXIT;
 break;
 /* B-format */
 case OPC1_32_B_CALLA:
 gen_helper_1arg(call, ctx->pc_succ_insn);
 gen_goto_tb(ctx, 0, EA_B_ABSOLUT(offset));
 break;
 case OPC1_32_B_FCALL:
 gen_fcall_save_ctx(ctx);
 gen_goto_tb(ctx, 0, ctx->base.pc_next + offset * 2);
 break;
 case OPC1_32_B_FCALLA:
 gen_fcall_save_ctx(ctx);
 gen_goto_tb(ctx, 0, EA_B_ABSOLUT(offset));
 break;
 case OPC1_32_B_JLA:
 tcg_gen_movi_tl(cpu_gpr_a[11], ctx->pc_succ_insn);
-/* fall through */
+fallthrough;
 case OPC1_32_B_JA:
 gen_goto_tb(ctx, 0, EA_B_ABSOLUT(offset));
 break;
 case OPC1_32_B_JL:
 tcg_gen_movi_tl(cpu_gpr_a[11], ctx->pc_succ_insn);
 gen_goto_tb(ctx, 0, ct

[RFC PATCH 09/78] hw/acpi/aml-build.c: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/acpi/aml-build.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index af66bde0f5..b0cf0c6073 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -292,56 +292,55 @@ static void
 build_prepend_package_length(GArray *package, unsigned length, bool incl_self)
 {
 uint8_t byte;
 unsigned length_bytes;
 
 if (length + 1 < (1 << PACKAGE_LENGTH_1BYTE_SHIFT)) {
 length_bytes = 1;
 } else if (length + 2 < (1 << PACKAGE_LENGTH_3BYTE_SHIFT)) {
 length_bytes = 2;
 } else if (length + 3 < (1 << PACKAGE_LENGTH_4BYTE_SHIFT)) {
 length_bytes = 3;
 } else {
 length_bytes = 4;
 }
 
 /*
  * NamedField uses PkgLength encoding but it doesn't include length
  * of PkgLength itself.
  */
 if (incl_self) {
 /*
  * PkgLength is the length of the inclusive length of the data
  * and PkgLength's length itself when used for terms with
  * explicit length.
  */
 length += length_bytes;
 }
 
 switch (length_bytes) {
 case 1:
 byte = length;
 build_prepend_byte(package, byte);
 return;
 case 4:
 byte = length >> PACKAGE_LENGTH_4BYTE_SHIFT;
 build_prepend_byte(package, byte);
 length &= (1 << PACKAGE_LENGTH_4BYTE_SHIFT) - 1;
-/* fall through */
+fallthrough;
 case 3:
 byte = length >> PACKAGE_LENGTH_3BYTE_SHIFT;
 build_prepend_byte(package, byte);
 length &= (1 << PACKAGE_LENGTH_3BYTE_SHIFT) - 1;
-/* fall through */
+fallthrough;
 case 2:
 byte = length >> PACKAGE_LENGTH_2BYTE_SHIFT;
 build_prepend_byte(package, byte);
 length &= (1 << PACKAGE_LENGTH_2BYTE_SHIFT) - 1;
-/* fall through */
 }
 /*
  * Most significant two bits of byte zero indicate how many following bytes
  * are in PkgLength encoding.
  */
 byte = ((length_bytes - 1) << PACKAGE_LENGTH_1BYTE_SHIFT) | length;
 build_prepend_byte(package, byte);
 }
@@ -508,37 +507,38 @@ static void build_buffer(GArray *array, uint8_t op)
 void aml_append(Aml *parent_ctx, Aml *child)
 {
 GArray *buf = build_alloc_array();
 build_append_array(buf, child->buf);
 
 switch (child->block_flags) {
 case AML_OPCODE:
 build_append_byte(parent_ctx->buf, child->op);
 break;
 case AML_EXT_PACKAGE:
 build_extop_package(buf, child->op);
 break;
 case AML_PACKAGE:
 build_package(buf, child->op);
 break;
 case AML_RES_TEMPLATE:
 build_append_byte(buf, 0x79); /* EndTag */
 /*
  * checksum operations are treated as succeeded if checksum
  * field is zero. [ACPI Spec 1.0b, 6.4.2.8 End Tag]
  */
 build_append_byte(buf, 0);
 /* fall through, to pack resources in buffer */
+fallthrough;
 case AML_BUFFER:
 build_buffer(buf, child->op);
 break;
 case AML_NO_OPCODE:
 break;
 default:
 assert(0);
 break;
 }
 build_append_array(parent_ctx->buf, buf);
 build_free_array(buf);
 }
 
 /* ACPI 1.0b: 16.2.5.1 Namespace Modifier Objects Encoding: DefScope */
-- 
2.39.2




[RFC PATCH 54/75] hw/display: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/display/cg3.c| 2 +-
 hw/display/cirrus_vga.c | 2 +-
 hw/display/tcx.c| 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/display/cg3.c b/hw/display/cg3.c
index 2e9656ae1c..53eb9831b2 100644
--- a/hw/display/cg3.c
+++ b/hw/display/cg3.c
@@ -199,65 +199,65 @@ static uint64_t cg3_reg_read(void *opaque, hwaddr addr, 
unsigned size)
 static void cg3_reg_write(void *opaque, hwaddr addr, uint64_t val,
   unsigned size)
 {
 CG3State *s = opaque;
 uint8_t regval;
 int i;
 
 trace_cg3_write(addr, val, size);
 switch (addr) {
 case CG3_REG_BT458_ADDR:
 s->dac_index = val;
 s->dac_state = 0;
 break;
 case CG3_REG_BT458_COLMAP:
 /* This register can be written to as either a long word or a byte */
 if (size == 1) {
 val <<= 24;
 }
 
 for (i = 0; i < size; i++) {
 regval = val >> 24;
 
 switch (s->dac_state) {
 case 0:
 s->r[s->dac_index] = regval;
 s->dac_state++;
 break;
 case 1:
 s->g[s->dac_index] = regval;
 s->dac_state++;
 break;
 case 2:
 s->b[s->dac_index] = regval;
 /* Index autoincrement */
 s->dac_index = (s->dac_index + 1) & 0xff;
-/* fall through */
+fallthrough;
 default:
 s->dac_state = 0;
 break;
 }
 val <<= 8;
 }
 s->full_update = 1;
 break;
 case CG3_REG_FBC_CTRL:
 s->regs[0] = val;
 break;
 case CG3_REG_FBC_STATUS:
 if (s->regs[1] & CG3_SR_PENDING_INT) {
 /* clear interrupt */
 s->regs[1] &= ~CG3_SR_PENDING_INT;
 qemu_irq_lower(s->irq);
 }
 break;
 case CG3_REG_FBC_CURSTART ... CG3_REG_SIZE - 1:
 s->regs[addr - 0x10] = val;
 break;
 default:
 qemu_log_mask(LOG_UNIMP,
   "cg3: Unimplemented register write "
   "reg 0x%" HWADDR_PRIx " size 0x%x value 0x%" PRIx64 "\n",
   addr, size, val);
 break;
 }
 }
diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c
index b80f98b6c4..f1513a084c 100644
--- a/hw/display/cirrus_vga.c
+++ b/hw/display/cirrus_vga.c
@@ -1319,97 +1319,97 @@ static int cirrus_vga_read_sr(CirrusVGAState * s)
 static void cirrus_vga_write_sr(CirrusVGAState * s, uint32_t val)
 {
 switch (s->vga.sr_index) {
 case 0x00:  // Standard VGA
 case 0x01:  // Standard VGA
 case 0x02:  // Standard VGA
 case 0x03:  // Standard VGA
 case 0x04:  // Standard VGA
 s->vga.sr[s->vga.sr_index] = val & sr_mask[s->vga.sr_index];
 if (s->vga.sr_index == 1)
 s->vga.update_retrace_info(&s->vga);
 break;
 case 0x06:  // Unlock Cirrus extensions
 val &= 0x17;
 if (val == 0x12) {
 s->vga.sr[s->vga.sr_index] = 0x12;
 } else {
 s->vga.sr[s->vga.sr_index] = 0x0f;
 }
 break;
 case 0x10:
 case 0x30:
 case 0x50:
 case 0x70:  // Graphics Cursor X
 case 0x90:
 case 0xb0:
 case 0xd0:
 case 0xf0:  // Graphics Cursor X
 s->vga.sr[0x10] = val;
 s->vga.hw_cursor_x = (val << 3) | (s->vga.sr_index >> 5);
 break;
 case 0x11:
 case 0x31:
 case 0x51:
 case 0x71:  // Graphics Cursor Y
 case 0x91:
 case 0xb1:
 case 0xd1:
 case 0xf1:  // Graphics Cursor Y
 s->vga.sr[0x11] = val;
 s->vga.hw_cursor_y = (val << 3) | (s->vga.sr_index >> 5);
 break;
 case 0x07:  // Extended Sequencer Mode
 cirrus_update_memory_access(s);
-/* fall through */
+fallthrough;
 case 0x08:  // EEPROM Control
 case 0x09:  // Scratch Register 0
 case 0x0a:  // Scratch Register 1
 case 0x0b:  // VCLK 0
 case 0x0c:  // VCLK 1
 case 0x0d:  // VCLK 2
 case 0x0e:  // VCLK 3
 case 0x0f:  // DRAM Control
 case 0x13:  // Graphics Cursor Pattern Address
 case 0x14:  // Scratch Register 2
 case 0x15:  // Scratch Register 3
 case 0x16:  // Performance Tuning Register
 case 0x18:  // Signature Generator Control
 case 0x19:  // Signature Generator Result
 case 0x1a:  // Signature Generator Result
 case 0x1b:  // VCLK 0 Denom

[RFC PATCH 54/78] hw/core: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/core/loader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/core/loader.c b/hw/core/loader.c
index 4dd5a71fb7..559d63a1e2 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -625,138 +625,138 @@ toosmall:
 /* Load a U-Boot image.  */
 static ssize_t load_uboot_image(const char *filename, hwaddr *ep,
 hwaddr *loadaddr, int *is_linux,
 uint8_t image_type,
 uint64_t (*translate_fn)(void *, uint64_t),
 void *translate_opaque, AddressSpace *as)
 {
 int fd;
 ssize_t size;
 hwaddr address;
 uboot_image_header_t h;
 uboot_image_header_t *hdr = &h;
 uint8_t *data = NULL;
 int ret = -1;
 int do_uncompress = 0;
 
 fd = open(filename, O_RDONLY | O_BINARY);
 if (fd < 0)
 return -1;
 
 size = read(fd, hdr, sizeof(uboot_image_header_t));
 if (size < sizeof(uboot_image_header_t)) {
 goto out;
 }
 
 bswap_uboot_header(hdr);
 
 if (hdr->ih_magic != IH_MAGIC)
 goto out;
 
 if (hdr->ih_type != image_type) {
 if (!(image_type == IH_TYPE_KERNEL &&
 hdr->ih_type == IH_TYPE_KERNEL_NOLOAD)) {
 fprintf(stderr, "Wrong image type %d, expected %d\n", hdr->ih_type,
 image_type);
 goto out;
 }
 }
 
 /* TODO: Implement other image types.  */
 switch (hdr->ih_type) {
 case IH_TYPE_KERNEL_NOLOAD:
 if (!loadaddr || *loadaddr == LOAD_UIMAGE_LOADADDR_INVALID) {
 fprintf(stderr, "this image format (kernel_noload) cannot be "
 "loaded on this machine type");
 goto out;
 }
 
 hdr->ih_load = *loadaddr + sizeof(*hdr);
 hdr->ih_ep += hdr->ih_load;
-/* fall through */
+fallthrough;
 case IH_TYPE_KERNEL:
 address = hdr->ih_load;
 if (translate_fn) {
 address = translate_fn(translate_opaque, address);
 }
 if (loadaddr) {
 *loadaddr = hdr->ih_load;
 }
 
 switch (hdr->ih_comp) {
 case IH_COMP_NONE:
 break;
 case IH_COMP_GZIP:
 do_uncompress = 1;
 break;
 default:
 fprintf(stderr,
 "Unable to load u-boot images with compression type %d\n",
 hdr->ih_comp);
 goto out;
 }
 
 if (ep) {
 *ep = hdr->ih_ep;
 }
 
 /* TODO: Check CPU type.  */
 if (is_linux) {
 if (hdr->ih_os == IH_OS_LINUX) {
 *is_linux = 1;
 } else if (hdr->ih_os == IH_OS_VXWORKS) {
 /*
  * VxWorks 7 uses the same boot interface as the Linux kernel
  * on Arm (64-bit only), PowerPC and RISC-V architectures.
  */
 switch (hdr->ih_arch) {
 case IH_ARCH_ARM64:
 case IH_ARCH_PPC:
 case IH_ARCH_RISCV:
 *is_linux = 1;
 break;
 default:
 *is_linux = 0;
 break;
 }
 } else {
 *is_linux = 0;
 }
 }
 
 break;
 case IH_TYPE_RAMDISK:
 address = *loadaddr;
 break;
 default:
 fprintf(stderr, "Unsupported u-boot image type %d\n", hdr->ih_type);
 goto out;
 }
 
 data = g_malloc(hdr->ih_size);
 
 if (read(fd, data, hdr->ih_size) != hdr->ih_size) {
 fprintf(stderr, "Error reading file\n");
 goto out;
 }
 
 if (do_uncompress) {
 uint8_t *compressed_data;
 size_t max_bytes;
 ssize_t bytes;
 
 compressed_data = data;
 max_bytes = UBOOT_MAX_GUNZIP_BYTES;
 data = g_malloc(max_bytes);
 
 bytes = gunzip(data, max_bytes, compressed_data, hdr->ih_size);
 g_free(compressed_data);
 if (bytes < 0) {
 fprintf(stderr, "Unable to decompress gzipped image!\n");
 goto out;
 }
 hdr->ih_size = bytes;
 }
 
 rom_add_blob_fixed_as(filename, data, hdr->ih_size, address, as);
 
 ret = hdr->ih_size;
-- 
2.39.2




[RFC PATCH 32/78] target/m68k: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/m68k/op_helper.c |  3 ++-
 target/m68k/translate.c | 10 +-
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/target/m68k/op_helper.c b/target/m68k/op_helper.c
index 1ce850bbc5..65058b9e2f 100644
--- a/target/m68k/op_helper.c
+++ b/target/m68k/op_helper.c
@@ -285,147 +285,147 @@ static inline void do_stack_frame(CPUM68KState *env, 
uint32_t *sp,
 static void m68k_interrupt_all(CPUM68KState *env, int is_hw)
 {
 CPUState *cs = env_cpu(env);
 uint32_t sp;
 uint32_t vector;
 uint16_t sr, oldsr;
 
 if (!is_hw) {
 switch (cs->exception_index) {
 case EXCP_RTE:
 /* Return from an exception.  */
 m68k_rte(env);
 return;
 }
 }
 
 vector = cs->exception_index << 2;
 
 sr = env->sr | cpu_m68k_get_ccr(env);
 if (qemu_loglevel_mask(CPU_LOG_INT)) {
 static int count;
 qemu_log("INT %6d: %s(%#x) pc=%08x sp=%08x sr=%04x\n",
  ++count, m68k_exception_name(cs->exception_index),
  vector, env->pc, env->aregs[7], sr);
 }
 
 /*
  * MC68040UM/AD,  chapter 9.3.10
  */
 
 /* "the processor first make an internal copy" */
 oldsr = sr;
 /* "set the mode to supervisor" */
 sr |= SR_S;
 /* "suppress tracing" */
 sr &= ~SR_T;
 /* "sets the processor interrupt mask" */
 if (is_hw) {
 sr |= (env->sr & ~SR_I) | (env->pending_level << SR_I_SHIFT);
 }
 cpu_m68k_set_sr(env, sr);
 sp = env->aregs[7];
 
 if (!m68k_feature(env, M68K_FEATURE_UNALIGNED_DATA)) {
 sp &= ~1;
 }
 
 switch (cs->exception_index) {
 case EXCP_ACCESS:
 if (env->mmu.fault) {
 cpu_abort(cs, "DOUBLE MMU FAULT\n");
 }
 env->mmu.fault = true;
 /* push data 3 */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* push data 2 */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* push data 1 */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* write back 1 / push data 0 */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* write back 1 address */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* write back 2 data */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* write back 2 address */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* write back 3 data */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* write back 3 address */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, env->mmu.ar, MMU_KERNEL_IDX, 0);
 /* fault address */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, env->mmu.ar, MMU_KERNEL_IDX, 0);
 /* write back 1 status */
 sp -= 2;
 cpu_stw_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* write back 2 status */
 sp -= 2;
 cpu_stw_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* write back 3 status */
 sp -= 2;
 cpu_stw_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* special status word */
 sp -= 2;
 cpu_stw_mmuidx_ra(env, sp, env->mmu.ssw, MMU_KERNEL_IDX, 0);
 /* effective address */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, env->mmu.ar, MMU_KERNEL_IDX, 0);
 
 do_stack_frame(env, &sp, 7, oldsr, 0, env->pc);
 env->mmu.fault = false;
 if (qemu_loglevel_mask(CPU_LOG_INT)) {
 qemu_log(""
  "ssw:  %08x ea:   %08x sfc:  %ddfc: %d\n",
  env->mmu.ssw, env->mmu.ar, env->sfc, env->dfc);
 }
 break;
 
 case EXCP_ILLEGAL:
 do_stack_frame(env, &sp, 0, oldsr, 0, env->pc);
 break;
 
 case EXCP_ADDRESS:
 do_stack_frame(env, &sp, 2, oldsr, 0, env->pc);
 break;
 
 case EXCP_CHK:
 case EXCP_DIV0:
 case EXCP_TRACE:
 case EXCP_TRAPCC:
 do_stack_frame(env, &sp, 2, oldsr, env->mmu.ar, env->pc);
 break;
 
 case EXCP_SPURIOUS ... EXCP_INT_LEVEL_7:
 if (is_hw && (oldsr & SR_M)) {
 do_stack_frame(env, &sp, 0, oldsr, 0, env->pc);
 oldsr = sr;
 env->aregs[7] = sp;
 cpu_m68k_set_sr(env, sr & ~SR_M);
 sp = env->aregs[7];
 if (!m68k_feature(env, M68K_FEATURE_UNALIGNED_DATA)) {
 sp &= ~1;
 }
 do_stack_frame(env, &sp, 1, oldsr, 0, env->pc);
 break;
 }
-/* fall through */
+fallthrough;
 
 default:
 do_stack_frame(env, &sp, 0, oldsr, 0, env->pc);

[RFC PATCH 48/78] contrib/vhost-user-scsi: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 contrib/vhost-user-scsi/vhost-user-scsi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c 
b/contrib/vhost-user-scsi/vhost-user-scsi.c
index 9ef61cf5a7..71076f579b 100644
--- a/contrib/vhost-user-scsi/vhost-user-scsi.c
+++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
@@ -109,14 +109,15 @@ static struct scsi_task *scsi_task_new(int cdb_len, 
uint8_t *cdb, int dir,
 static int get_cdb_len(uint8_t *cdb)
 {
 assert(cdb);
 
 switch (cdb[0] >> 5) {
 case 0: return 6;
-case 1: /* fall through */
+case 1:
+fallthrough;
 case 2: return 10;
 case 4: return 16;
 case 5: return 12;
 }
 g_warning("Unable to determine cdb len (0x%02hhX)", (uint8_t)(cdb[0] >> 
5));
 return -1;
 }
-- 
2.39.2




[RFC PATCH 39/75] hw/sd/sdhci.c: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/sd/sdhci.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 5564765a9b..5c641d24de 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -75,138 +75,138 @@ static bool sdhci_check_capab_freq_range(SDHCIState *s, 
const char *desc,
 static void sdhci_check_capareg(SDHCIState *s, Error **errp)
 {
 uint64_t msk = s->capareg;
 uint32_t val;
 bool y;
 
 switch (s->sd_spec_version) {
 case 4:
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, BUS64BIT_V4);
 trace_sdhci_capareg("64-bit system bus (v4)", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, BUS64BIT_V4, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, UHS_II);
 trace_sdhci_capareg("UHS-II", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, UHS_II, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, ADMA3);
 trace_sdhci_capareg("ADMA3", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, ADMA3, 0);
 
-/* fallthrough */
+fallthrough;
 case 3:
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, ASYNC_INT);
 trace_sdhci_capareg("async interrupt", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, ASYNC_INT, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, SLOT_TYPE);
 if (val) {
 error_setg(errp, "slot-type not supported");
 return;
 }
 trace_sdhci_capareg("slot type", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, SLOT_TYPE, 0);
 
 if (val != 2) {
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, EMBEDDED_8BIT);
 trace_sdhci_capareg("8-bit bus", val);
 }
 msk = FIELD_DP64(msk, SDHC_CAPAB, EMBEDDED_8BIT, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, BUS_SPEED);
 trace_sdhci_capareg("bus speed mask", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, BUS_SPEED, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, DRIVER_STRENGTH);
 trace_sdhci_capareg("driver strength mask", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, DRIVER_STRENGTH, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, TIMER_RETUNING);
 trace_sdhci_capareg("timer re-tuning", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, TIMER_RETUNING, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, SDR50_TUNING);
 trace_sdhci_capareg("use SDR50 tuning", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, SDR50_TUNING, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, RETUNING_MODE);
 trace_sdhci_capareg("re-tuning mode", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, RETUNING_MODE, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, CLOCK_MULT);
 trace_sdhci_capareg("clock multiplier", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, CLOCK_MULT, 0);
 
-/* fallthrough */
+fallthrough;
 case 2: /* default version */
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, ADMA2);
 trace_sdhci_capareg("ADMA2", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, ADMA2, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, ADMA1);
 trace_sdhci_capareg("ADMA1", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, ADMA1, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, BUS64BIT);
 trace_sdhci_capareg("64-bit system bus (v3)", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, BUS64BIT, 0);
 
-/* fallthrough */
+fallthrough;
 case 1:
 y = FIELD_EX64(s->capareg, SDHC_CAPAB, TOUNIT);
 msk = FIELD_DP64(msk, SDHC_CAPAB, TOUNIT, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, TOCLKFREQ);
 trace_sdhci_capareg(y ? "timeout (MHz)" : "Timeout (KHz)", val);
 if (sdhci_check_capab_freq_range(s, "timeout", val, errp)) {
 return;
 }
 msk = FIELD_DP64(msk, SDHC_CAPAB, TOCLKFREQ, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, BASECLKFREQ);
 trace_sdhci_capareg(y ? "base (MHz)" : "Base (KHz)", val);
 if (sdhci_check_capab_freq_range(s, "base", val, errp)) {
 return;
 }
 msk = FIELD_DP64(msk, SDHC_CAPAB, BASECLKFREQ, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, MAXBLOCKLENGTH);
 if (val >= 3) {
 error_setg(errp, "block size can be 512, 1024 or 2048 only");
 return;
 }
 trace_sdhci_capareg("max block length", sdhci_get_fifolen(s));
 msk = FIELD_DP64(msk, SDHC_CAPAB, MAXBLOCKLENGTH, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, HIGHSPEED);
 trace_sdhci_capareg("high speed", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, HIGHSPEED, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, SDMA);
 trace_sdhci_capareg("SDMA", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, SDMA, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, SUSPRESUME);
 trace_sdhci_capareg("suspend/resume", val);
 msk = FIELD_DP

[RFC PATCH 51/78] chardev: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 chardev/char-socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 73947da188..1562e066a4 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -549,34 +549,34 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t 
*buf, int len)
 static char *qemu_chr_compute_filename(SocketChardev *s)
 {
 struct sockaddr_storage *ss = &s->sioc->localAddr;
 struct sockaddr_storage *ps = &s->sioc->remoteAddr;
 socklen_t ss_len = s->sioc->localAddrLen;
 socklen_t ps_len = s->sioc->remoteAddrLen;
 char shost[NI_MAXHOST], sserv[NI_MAXSERV];
 char phost[NI_MAXHOST], pserv[NI_MAXSERV];
 const char *left = "", *right = "";
 
 switch (ss->ss_family) {
 case AF_UNIX:
 return g_strdup_printf("unix:%s%s",
((struct sockaddr_un *)(ss))->sun_path,
s->is_listen ? ",server=on" : "");
 case AF_INET6:
 left  = "[";
 right = "]";
-/* fall through */
+fallthrough;
 case AF_INET:
 getnameinfo((struct sockaddr *) ss, ss_len, shost, sizeof(shost),
 sserv, sizeof(sserv), NI_NUMERICHOST | NI_NUMERICSERV);
 getnameinfo((struct sockaddr *) ps, ps_len, phost, sizeof(phost),
 pserv, sizeof(pserv), NI_NUMERICHOST | NI_NUMERICSERV);
 return g_strdup_printf("%s:%s%s%s:%s%s <-> %s%s%s:%s",
qemu_chr_socket_protocol(s),
left, shost, right, sserv,
s->is_listen ? ",server=on" : "",
left, phost, right, pserv);
 
 default:
 return g_strdup_printf("unknown");
 }
 }
-- 
2.39.2




[RFC PATCH 51/75] hw/char: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/char/nrf51_uart.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/char/nrf51_uart.c b/hw/char/nrf51_uart.c
index dfe2276d71..3e2b35c7ad 100644
--- a/hw/char/nrf51_uart.c
+++ b/hw/char/nrf51_uart.c
@@ -113,79 +113,79 @@ static void uart_cancel_transmit(NRF51UARTState *s)
 static void uart_write(void *opaque, hwaddr addr,
uint64_t value, unsigned int size)
 {
 NRF51UARTState *s = NRF51_UART(opaque);
 
 trace_nrf51_uart_write(addr, value, size);
 
 if (!s->enabled && (addr != A_UART_ENABLE)) {
 return;
 }
 
 switch (addr) {
 case A_UART_TXD:
 if (!s->pending_tx_byte && s->tx_started) {
 s->reg[R_UART_TXD] = value;
 s->pending_tx_byte = true;
 uart_transmit(NULL, G_IO_OUT, s);
 }
 break;
 case A_UART_INTEN:
 s->reg[R_UART_INTEN] = value;
 break;
 case A_UART_INTENSET:
 s->reg[R_UART_INTEN] |= value;
 break;
 case A_UART_INTENCLR:
 s->reg[R_UART_INTEN] &= ~value;
 break;
 case A_UART_TXDRDY ... A_UART_RXTO:
 s->reg[addr / 4] = value;
 break;
 case A_UART_ERRORSRC:
 s->reg[addr / 4] &= ~value;
 break;
 case A_UART_RXD:
 break;
 case A_UART_RXDRDY:
 if (value == 0) {
 s->reg[R_UART_RXDRDY] = 0;
 }
 break;
 case A_UART_STARTTX:
 if (value == 1) {
 s->tx_started = true;
 }
 break;
 case A_UART_STARTRX:
 if (value == 1) {
 s->rx_started = true;
 }
 break;
 case A_UART_ENABLE:
 if (value) {
 if (value == 4) {
 s->enabled = true;
 }
 break;
 }
 s->enabled = false;
 value = 1;
-/* fall through */
+fallthrough;
 case A_UART_SUSPEND:
 case A_UART_STOPTX:
 if (value == 1) {
 s->tx_started = false;
 }
-/* fall through */
+fallthrough;
 case A_UART_STOPRX:
 if (addr != A_UART_STOPTX && value == 1) {
 s->rx_started = false;
 s->reg[R_UART_RXTO] = 1;
 }
 break;
 default:
 s->reg[addr / 4] = value;
 break;
 }
 nrf51_uart_update_irq(s);
 }
-- 
2.39.2




[RFC PATCH v2 01/78] include/qemu/compiler.h: replace QEMU_FALLTHROUGH with fallthrough

2023-10-13 Thread Emmanouil Pitsidianakis
Signed-off-by: Emmanouil Pitsidianakis 
---
 audio/pwaudio.c  |  8 
 hw/arm/smmuv3.c  |  2 +-
 include/qemu/compiler.h  | 30 +++---
 include/qemu/osdep.h |  4 ++--
 target/loongarch/cpu.c   |  4 ++--
 target/loongarch/translate.c |  2 +-
 tcg/optimize.c   |  8 
 7 files changed, 37 insertions(+), 21 deletions(-)

diff --git a/audio/pwaudio.c b/audio/pwaudio.c
index 3ce5f6507b..bf26fadb06 100644
--- a/audio/pwaudio.c
+++ b/audio/pwaudio.c
@@ -1,29 +1,29 @@
 /*
  * QEMU PipeWire audio driver
  *
  * Copyright (c) 2023 Red Hat Inc.
  *
  * Author: Dorinda Bassey   
  *
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
+#include 
+#include 
+#include 
+#include 
 #include "qemu/osdep.h"
 #include "qemu/module.h"
 #include "audio.h"
 #include 
 #include "qemu/error-report.h"
 #include "qapi/error.h"
-#include 
-#include 
-#include 
-#include 
 
 #include 
 #include "trace.h"
 
 #define AUDIO_CAP "pipewire"
 #define RINGBUFFER_SIZE(1u << 22)
 #define RINGBUFFER_MASK(RINGBUFFER_SIZE - 1)
 
 #include "audio_int.h"
diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
index 6f2b2bd45f..545d82ff04 100644
--- a/hw/arm/smmuv3.c
+++ b/hw/arm/smmuv3.c
@@ -1166,210 +1166,210 @@ smmuv3_invalidate_ste(gpointer key, gpointer value, 
gpointer user_data)
 static int smmuv3_cmdq_consume(SMMUv3State *s)
 {
 SMMUState *bs = ARM_SMMU(s);
 SMMUCmdError cmd_error = SMMU_CERROR_NONE;
 SMMUQueue *q = &s->cmdq;
 SMMUCommandType type = 0;
 
 if (!smmuv3_cmdq_enabled(s)) {
 return 0;
 }
 /*
  * some commands depend on register values, typically CR0. In case those
  * register values change while handling the command, spec says it
  * is UNPREDICTABLE whether the command is interpreted under the new
  * or old value.
  */
 
 while (!smmuv3_q_empty(q)) {
 uint32_t pending = s->gerror ^ s->gerrorn;
 Cmd cmd;
 
 trace_smmuv3_cmdq_consume(Q_PROD(q), Q_CONS(q),
   Q_PROD_WRAP(q), Q_CONS_WRAP(q));
 
 if (FIELD_EX32(pending, GERROR, CMDQ_ERR)) {
 break;
 }
 
 if (queue_read(q, &cmd) != MEMTX_OK) {
 cmd_error = SMMU_CERROR_ABT;
 break;
 }
 
 type = CMD_TYPE(&cmd);
 
 trace_smmuv3_cmdq_opcode(smmu_cmd_string(type));
 
 qemu_mutex_lock(&s->mutex);
 switch (type) {
 case SMMU_CMD_SYNC:
 if (CMD_SYNC_CS(&cmd) & CMD_SYNC_SIG_IRQ) {
 smmuv3_trigger_irq(s, SMMU_IRQ_CMD_SYNC, 0);
 }
 break;
 case SMMU_CMD_PREFETCH_CONFIG:
 case SMMU_CMD_PREFETCH_ADDR:
 break;
 case SMMU_CMD_CFGI_STE:
 {
 uint32_t sid = CMD_SID(&cmd);
 IOMMUMemoryRegion *mr = smmu_iommu_mr(bs, sid);
 SMMUDevice *sdev;
 
 if (CMD_SSEC(&cmd)) {
 cmd_error = SMMU_CERROR_ILL;
 break;
 }
 
 if (!mr) {
 break;
 }
 
 trace_smmuv3_cmdq_cfgi_ste(sid);
 sdev = container_of(mr, SMMUDevice, iommu);
 smmuv3_flush_config(sdev);
 
 break;
 }
 case SMMU_CMD_CFGI_STE_RANGE: /* same as SMMU_CMD_CFGI_ALL */
 {
 uint32_t sid = CMD_SID(&cmd), mask;
 uint8_t range = CMD_STE_RANGE(&cmd);
 SMMUSIDRange sid_range;
 
 if (CMD_SSEC(&cmd)) {
 cmd_error = SMMU_CERROR_ILL;
 break;
 }
 
 mask = (1ULL << (range + 1)) - 1;
 sid_range.start = sid & ~mask;
 sid_range.end = sid_range.start + mask;
 
 trace_smmuv3_cmdq_cfgi_ste_range(sid_range.start, sid_range.end);
 g_hash_table_foreach_remove(bs->configs, smmuv3_invalidate_ste,
 &sid_range);
 break;
 }
 case SMMU_CMD_CFGI_CD:
 case SMMU_CMD_CFGI_CD_ALL:
 {
 uint32_t sid = CMD_SID(&cmd);
 IOMMUMemoryRegion *mr = smmu_iommu_mr(bs, sid);
 SMMUDevice *sdev;
 
 if (CMD_SSEC(&cmd)) {
 cmd_error = SMMU_CERROR_ILL;
 break;
 }
 
 if (!mr) {
 break;
 }
 
 trace_smmuv3_cmdq_cfgi_cd(sid);
 sdev = container_of(mr, SMMUDevice, iommu);
 smmuv3_flush_config(sdev);
 break;
 }
 case SMMU_CMD_TLBI_NH_ASID:
 {
 uint16_t asid = CMD_ASID(&cmd);
 
 if (!STAGE1_SUPPORTED(s)) {
 cmd_error = SMMU_CERROR_ILL;
 break;
 }
 
 trace_smmuv3_cmdq_tlbi_nh_asid(asid);
 smmu_inv_notifiers_all(&s->smmu_state);
 smmu_iotlb_inv_asid(bs, asid);
 break;
 

[RFC PATCH 14/78] util/error-report.c: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 util/error-report.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/error-report.c b/util/error-report.c
index 6e44a55732..acb66420de 100644
--- a/util/error-report.c
+++ b/util/error-report.c
@@ -353,36 +353,36 @@ static char *qemu_glog_domains;
 static void qemu_log_func(const gchar *log_domain,
   GLogLevelFlags log_level,
   const gchar *message,
   gpointer user_data)
 {
 switch (log_level & G_LOG_LEVEL_MASK) {
 case G_LOG_LEVEL_DEBUG:
 case G_LOG_LEVEL_INFO:
 /*
  * Use same G_MESSAGES_DEBUG logic as glib to enable/disable debug
  * messages
  */
 if (qemu_glog_domains == NULL) {
 break;
 }
 if (strcmp(qemu_glog_domains, "all") != 0 &&
   (log_domain == NULL || !strstr(qemu_glog_domains, log_domain))) {
 break;
 }
-/* Fall through */
+fallthrough;
 case G_LOG_LEVEL_MESSAGE:
 info_report("%s%s%s",
 log_domain ?: "", log_domain ? ": " : "", message);
 
 break;
 case G_LOG_LEVEL_WARNING:
 warn_report("%s%s%s",
 log_domain ?: "", log_domain ? ": " : "", message);
 break;
 case G_LOG_LEVEL_CRITICAL:
 case G_LOG_LEVEL_ERROR:
 error_report("%s%s%s",
  log_domain ?: "", log_domain ? ": " : "", message);
 break;
 }
 }
-- 
2.39.2




[RFC PATCH 20/78] target/mips: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/mips/sysemu/physaddr.c |  2 +-
 target/mips/tcg/micromips_translate.c.inc |  4 +-
 target/mips/tcg/mips16e_translate.c.inc   | 30 -
 target/mips/tcg/mxu_translate.c   |  8 +--
 target/mips/tcg/nanomips_translate.c.inc  |  4 +-
 target/mips/tcg/op_helper.c   |  2 +-
 target/mips/tcg/translate.c   | 79 ---
 7 files changed, 66 insertions(+), 63 deletions(-)

diff --git a/target/mips/sysemu/physaddr.c b/target/mips/sysemu/physaddr.c
index 05990aa5bb..ebcaeea1bc 100644
--- a/target/mips/sysemu/physaddr.c
+++ b/target/mips/sysemu/physaddr.c
@@ -24,52 +24,52 @@
 static int is_seg_am_mapped(unsigned int am, bool eu, int mmu_idx)
 {
 /*
  * Interpret access control mode and mmu_idx.
  *   AdE? TLB?
  *  AM  K S U E  K S U E
  * UK0  0 1 1 0  0 - - 0
  * MK1  0 1 1 0  1 - - !eu
  * MSK   2  0 0 1 0  1 1 - !eu
  * MUSK  3  0 0 0 0  1 1 1 !eu
  * MUSUK 4  0 0 0 0  0 1 1 0
  * USK   5  0 0 1 0  0 0 - 0
  * - 6  - - - -  - - - -
  * UUSK  7  0 0 0 0  0 0 0 0
  */
 int32_t adetlb_mask;
 
 switch (mmu_idx) {
 case 3: /* ERL */
 /* If EU is set, always unmapped */
 if (eu) {
 return 0;
 }
-/* fall through */
+fallthrough;
 case MIPS_HFLAG_KM:
 /* Never AdE, TLB mapped if AM={1,2,3} */
 adetlb_mask = 0x7000;
 goto check_tlb;
 
 case MIPS_HFLAG_SM:
 /* AdE if AM={0,1}, TLB mapped if AM={2,3,4} */
 adetlb_mask = 0xc038;
 goto check_ade;
 
 case MIPS_HFLAG_UM:
 /* AdE if AM={0,1,2,5}, TLB mapped if AM={3,4} */
 adetlb_mask = 0xe418;
 /* fall through */
 check_ade:
 /* does this AM cause AdE in current execution mode */
 if ((adetlb_mask << am) < 0) {
 return TLBRET_BADADDR;
 }
 adetlb_mask <<= 8;
 /* fall through */
 check_tlb:
 /* is this AM mapped in current execution mode */
 return ((adetlb_mask << am) < 0);
 default:
 g_assert_not_reached();
 };
 }
diff --git a/target/mips/tcg/micromips_translate.c.inc 
b/target/mips/tcg/micromips_translate.c.inc
index 7510831701..00e96ce27a 100644
--- a/target/mips/tcg/micromips_translate.c.inc
+++ b/target/mips/tcg/micromips_translate.c.inc
@@ -1621,1353 +1621,1353 @@ static void gen_pool32fxf(DisasContext *ctx, int 
rt, int rs)
 static void decode_micromips32_opc(CPUMIPSState *env, DisasContext *ctx)
 {
 int32_t offset;
 uint16_t insn;
 int rt, rs, rd, rr;
 int16_t imm;
 uint32_t op, minor, minor2, mips32_op;
 uint32_t cond, fmt, cc;
 
 insn = translator_lduw(env, &ctx->base, ctx->base.pc_next + 2);
 ctx->opcode = (ctx->opcode << 16) | insn;
 
 rt = (ctx->opcode >> 21) & 0x1f;
 rs = (ctx->opcode >> 16) & 0x1f;
 rd = (ctx->opcode >> 11) & 0x1f;
 rr = (ctx->opcode >> 6) & 0x1f;
 imm = (int16_t) ctx->opcode;
 
 op = (ctx->opcode >> 26) & 0x3f;
 switch (op) {
 case POOL32A:
 minor = ctx->opcode & 0x3f;
 switch (minor) {
 case 0x00:
 minor = (ctx->opcode >> 6) & 0xf;
 switch (minor) {
 case SLL32:
 mips32_op = OPC_SLL;
 goto do_shifti;
 case SRA:
 mips32_op = OPC_SRA;
 goto do_shifti;
 case SRL32:
 mips32_op = OPC_SRL;
 goto do_shifti;
 case ROTR:
 mips32_op = OPC_ROTR;
 do_shifti:
 gen_shift_imm(ctx, mips32_op, rt, rs, rd);
 break;
 case SELEQZ:
 check_insn(ctx, ISA_MIPS_R6);
 gen_cond_move(ctx, OPC_SELEQZ, rd, rs, rt);
 break;
 case SELNEZ:
 check_insn(ctx, ISA_MIPS_R6);
 gen_cond_move(ctx, OPC_SELNEZ, rd, rs, rt);
 break;
 case R6_RDHWR:
 check_insn(ctx, ISA_MIPS_R6);
 gen_rdhwr(ctx, rt, rs, extract32(ctx->opcode, 11, 3));
 break;
 default:
 goto pool32a_invalid;
 }
 break;
 case 0x10:
 minor = (ctx->opcode >> 6) & 0xf;
 switch (minor) {
 /* Arithmetic */
 case ADD:
 mips32_op = OPC_ADD;
 goto do_arith;
 case ADDU32:
 mips32_op = OPC_ADDU;
 goto do_arith;
 case SUB:
 mips32_op = OPC_SUB;
 goto do_arith;
 case SUBU32:
 mips32_op = OPC_SUBU;
 goto do

[RFC PATCH 38/75] hw/scsi: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/scsi/esp.c   | 2 +-
 hw/scsi/megasas.c   | 2 +-
 hw/scsi/scsi-bus.c  | 4 ++--
 hw/scsi/scsi-disk.c | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
index 9b11d8c573..d6c8298f51 100644
--- a/hw/scsi/esp.c
+++ b/hw/scsi/esp.c
@@ -1022,130 +1022,130 @@ uint64_t esp_reg_read(ESPState *s, uint32_t saddr)
 void esp_reg_write(ESPState *s, uint32_t saddr, uint64_t val)
 {
 trace_esp_mem_writeb(saddr, s->wregs[saddr], val);
 switch (saddr) {
 case ESP_TCHI:
 s->tchi_written = true;
-/* fall through */
+fallthrough;
 case ESP_TCLO:
 case ESP_TCMID:
 s->rregs[ESP_RSTAT] &= ~STAT_TC;
 break;
 case ESP_FIFO:
 if (s->do_cmd) {
 esp_fifo_push(&s->cmdfifo, val);
 
 /*
  * If any unexpected message out/command phase data is
  * transferred using non-DMA, raise the interrupt
  */
 if (s->rregs[ESP_CMD] == CMD_TI) {
 s->rregs[ESP_RINTR] |= INTR_BS;
 esp_raise_irq(s);
 }
 } else {
 esp_fifo_push(&s->fifo, val);
 }
 break;
 case ESP_CMD:
 s->rregs[saddr] = val;
 if (val & CMD_DMA) {
 s->dma = 1;
 /* Reload DMA counter.  */
 if (esp_get_stc(s) == 0) {
 esp_set_tc(s, 0x1);
 } else {
 esp_set_tc(s, esp_get_stc(s));
 }
 } else {
 s->dma = 0;
 }
 switch (val & CMD_CMD) {
 case CMD_NOP:
 trace_esp_mem_writeb_cmd_nop(val);
 break;
 case CMD_FLUSH:
 trace_esp_mem_writeb_cmd_flush(val);
 fifo8_reset(&s->fifo);
 break;
 case CMD_RESET:
 trace_esp_mem_writeb_cmd_reset(val);
 esp_soft_reset(s);
 break;
 case CMD_BUSRESET:
 trace_esp_mem_writeb_cmd_bus_reset(val);
 esp_bus_reset(s);
 if (!(s->wregs[ESP_CFG1] & CFG1_RESREPT)) {
 s->rregs[ESP_RINTR] |= INTR_RST;
 esp_raise_irq(s);
 }
 break;
 case CMD_TI:
 trace_esp_mem_writeb_cmd_ti(val);
 handle_ti(s);
 break;
 case CMD_ICCS:
 trace_esp_mem_writeb_cmd_iccs(val);
 write_response(s);
 s->rregs[ESP_RINTR] |= INTR_FC;
 s->rregs[ESP_RSTAT] |= STAT_MI;
 break;
 case CMD_MSGACC:
 trace_esp_mem_writeb_cmd_msgacc(val);
 s->rregs[ESP_RINTR] |= INTR_DC;
 s->rregs[ESP_RSEQ] = 0;
 s->rregs[ESP_RFLAGS] = 0;
 esp_raise_irq(s);
 break;
 case CMD_PAD:
 trace_esp_mem_writeb_cmd_pad(val);
 s->rregs[ESP_RSTAT] = STAT_TC;
 s->rregs[ESP_RINTR] |= INTR_FC;
 s->rregs[ESP_RSEQ] = 0;
 break;
 case CMD_SATN:
 trace_esp_mem_writeb_cmd_satn(val);
 break;
 case CMD_RSTATN:
 trace_esp_mem_writeb_cmd_rstatn(val);
 break;
 case CMD_SEL:
 trace_esp_mem_writeb_cmd_sel(val);
 handle_s_without_atn(s);
 break;
 case CMD_SELATN:
 trace_esp_mem_writeb_cmd_selatn(val);
 handle_satn(s);
 break;
 case CMD_SELATNS:
 trace_esp_mem_writeb_cmd_selatns(val);
 handle_satn_stop(s);
 break;
 case CMD_ENSEL:
 trace_esp_mem_writeb_cmd_ensel(val);
 s->rregs[ESP_RINTR] = 0;
 break;
 case CMD_DISSEL:
 trace_esp_mem_writeb_cmd_dissel(val);
 s->rregs[ESP_RINTR] = 0;
 esp_raise_irq(s);
 break;
 default:
 trace_esp_error_unhandled_command(val);
 break;
 }
 break;
 case ESP_WBUSID ... ESP_WSYNO:
 break;
 case ESP_CFG1:
 case ESP_CFG2: case ESP_CFG3:
 case ESP_RES3: case ESP_RES4:
 s->rregs[saddr] = val;
 break;
 case ESP_WCCF ... ESP_WTEST:
 break;
 default:
 trace_esp_error_invalid_write(val, saddr);
 return;
 }
 s->wregs[saddr] = val;
 }
diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
index 32c70c9e99..54e4d7c8b6 100644
--- a/hw/scsi/megasas.c
+++ b/hw/scsi/megasas.c
@@ -2084,113 +2084,113 @@ static int adp_reset_seq[] = {0x00, 0x04, 0x0b, 0x02, 
0x07, 0x0d};
 static void megasas_mmio_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
 {
 MegasasState *s = opaque;
 PCIDevice *pci_dev = PCI_DEVICE(s);
 uint64_t frame_addr;
 uint32_t frame_count;
 int i;
 
 switch (addr) {
 case MFI_IDB:
 trace_megasas_mmio_writ

[RFC PATCH 46/75] contrib/rdmacm-mux: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
Signed-off-by: Emmanouil Pitsidianakis 
---
 contrib/rdmacm-mux/main.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/contrib/rdmacm-mux/main.c b/contrib/rdmacm-mux/main.c
index 771ca01e03..dda6917d58 100644
--- a/contrib/rdmacm-mux/main.c
+++ b/contrib/rdmacm-mux/main.c
@@ -303,72 +303,72 @@ static void hash_tbl_remove_fd_ifid_pair(int fd)
 static int get_fd(const char *mad, int umad_len, int *fd, __be64 *gid_ifid)
 {
 struct umad_hdr *hdr = (struct umad_hdr *)mad;
 char *data = (char *)hdr + sizeof(*hdr);
 int32_t comm_id = 0;
 uint16_t attr_id = be16toh(hdr->attr_id);
 int rc = 0;
 
 if (umad_len <= sizeof(*hdr)) {
 rc = -EINVAL;
 syslog(LOG_DEBUG, "Ignoring MAD packets with header only\n");
 goto out;
 }
 
 switch (attr_id) {
 case UMAD_CM_ATTR_REQ:
 if (unlikely(umad_len < sizeof(*hdr) + CM_REQ_DGID_POS +
 sizeof(*gid_ifid))) {
 rc = -EINVAL;
 syslog(LOG_WARNING,
"Invalid MAD packet size (%d) for attr_id 0x%x\n", umad_len,
 attr_id);
 goto out;
 }
 memcpy(gid_ifid, data + CM_REQ_DGID_POS, sizeof(*gid_ifid));
 rc = hash_tbl_search_fd_by_ifid(fd, gid_ifid);
 break;
 
 case UMAD_CM_ATTR_SIDR_REQ:
 if (unlikely(umad_len < sizeof(*hdr) + CM_SIDR_REQ_DGID_POS +
 sizeof(*gid_ifid))) {
 rc = -EINVAL;
 syslog(LOG_WARNING,
"Invalid MAD packet size (%d) for attr_id 0x%x\n", umad_len,
 attr_id);
 goto out;
 }
 memcpy(gid_ifid, data + CM_SIDR_REQ_DGID_POS, sizeof(*gid_ifid));
 rc = hash_tbl_search_fd_by_ifid(fd, gid_ifid);
 break;
 
 case UMAD_CM_ATTR_REP:
-/* Fall through */
+fallthrough;
 case UMAD_CM_ATTR_REJ:
-/* Fall through */
+fallthrough;
 case UMAD_CM_ATTR_DREQ:
-/* Fall through */
+fallthrough;
 case UMAD_CM_ATTR_DREP:
-/* Fall through */
+fallthrough;
 case UMAD_CM_ATTR_RTU:
 data += sizeof(comm_id);
-/* Fall through */
+fallthrough;
 case UMAD_CM_ATTR_SIDR_REP:
 if (unlikely(umad_len < sizeof(*hdr) + sizeof(comm_id))) {
 rc = -EINVAL;
 syslog(LOG_WARNING,
"Invalid MAD packet size (%d) for attr_id 0x%x\n", umad_len,
attr_id);
 goto out;
 }
 memcpy(&comm_id, data, sizeof(comm_id));
 if (comm_id) {
 rc = hash_tbl_search_fd_by_comm_id(comm_id, fd, gid_ifid);
 }
 break;
 
 default:
 rc = -EINVAL;
 syslog(LOG_WARNING, "Unsupported attr_id 0x%x\n", attr_id);
 }
 
 syslog(LOG_DEBUG, "mad_to_vm: %d 0x%x 0x%x\n", *fd, attr_id, comm_id);
-- 
2.39.2




[RFC PATCH 31/78] target/xtensa: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/xtensa/op_helper.c | 8 
 target/xtensa/translate.c | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/target/xtensa/op_helper.c b/target/xtensa/op_helper.c
index 7bb8cd6726..69b72f474d 100644
--- a/target/xtensa/op_helper.c
+++ b/target/xtensa/op_helper.c
@@ -73,58 +73,58 @@ void HELPER(update_ccompare)(CPUXtensaState *env, uint32_t 
i)
 /*!
  * Check vaddr accessibility/cache attributes and raise an exception if
  * specified by the ATOMCTL SR.
  *
  * Note: local memory exclusion is not implemented
  */
 void HELPER(check_atomctl)(CPUXtensaState *env, uint32_t pc, uint32_t vaddr)
 {
 uint32_t paddr, page_size, access;
 uint32_t atomctl = env->sregs[ATOMCTL];
 int rc = xtensa_get_physical_addr(env, true, vaddr, 1,
 xtensa_get_cring(env), &paddr, &page_size, &access);
 
 /*
  * s32c1i never causes LOAD_PROHIBITED_CAUSE exceptions,
  * see opcode description in the ISA
  */
 if (rc == 0 &&
 (access & (PAGE_READ | PAGE_WRITE)) != (PAGE_READ | PAGE_WRITE)) {
 rc = STORE_PROHIBITED_CAUSE;
 }
 
 if (rc) {
 HELPER(exception_cause_vaddr)(env, pc, rc, vaddr);
 }
 
 /*
  * When data cache is not configured use ATOMCTL bypass field.
  * See ISA, 4.3.12.4 The Atomic Operation Control Register (ATOMCTL)
  * under the Conditional Store Option.
  */
 if (!xtensa_option_enabled(env->config, XTENSA_OPTION_DCACHE)) {
 access = PAGE_CACHE_BYPASS;
 }
 
 switch (access & PAGE_CACHE_MASK) {
 case PAGE_CACHE_WB:
 atomctl >>= 2;
-/* fall through */
+fallthrough;
 case PAGE_CACHE_WT:
 atomctl >>= 2;
-/* fall through */
+fallthrough;
 case PAGE_CACHE_BYPASS:
 if ((atomctl & 0x3) == 0) {
 HELPER(exception_cause_vaddr)(env, pc,
 LOAD_STORE_ERROR_CAUSE, vaddr);
 }
 break;
 
 case PAGE_CACHE_ISOLATE:
 HELPER(exception_cause_vaddr)(env, pc,
 LOAD_STORE_ERROR_CAUSE, vaddr);
 break;
 
 default:
 break;
 }
 }
@@ -132,41 +132,41 @@ void HELPER(check_atomctl)(CPUXtensaState *env, uint32_t 
pc, uint32_t vaddr)
 void HELPER(check_exclusive)(CPUXtensaState *env, uint32_t pc, uint32_t vaddr,
  uint32_t is_write)
 {
 uint32_t paddr, page_size, access;
 uint32_t atomctl = env->sregs[ATOMCTL];
 int rc = xtensa_get_physical_addr(env, true, vaddr, is_write,
   xtensa_get_cring(env), &paddr,
   &page_size, &access);
 
 if (rc) {
 HELPER(exception_cause_vaddr)(env, pc, rc, vaddr);
 }
 
 /* When data cache is not configured use ATOMCTL bypass field. */
 if (!xtensa_option_enabled(env->config, XTENSA_OPTION_DCACHE)) {
 access = PAGE_CACHE_BYPASS;
 }
 
 switch (access & PAGE_CACHE_MASK) {
 case PAGE_CACHE_WB:
 atomctl >>= 2;
-/* fall through */
+fallthrough;
 case PAGE_CACHE_WT:
 atomctl >>= 2;
-/* fall through */
+fallthrough;
 case PAGE_CACHE_BYPASS:
 if ((atomctl & 0x3) == 0) {
 HELPER(exception_cause_vaddr)(env, pc,
   EXCLUSIVE_ERROR_CAUSE, vaddr);
 }
 break;
 
 case PAGE_CACHE_ISOLATE:
 HELPER(exception_cause_vaddr)(env, pc,
 LOAD_STORE_ERROR_CAUSE, vaddr);
 break;
 
 default:
 break;
 }
 }
diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c
index 54bee7ddba..8ef940933c 100644
--- a/target/xtensa/translate.c
+++ b/target/xtensa/translate.c
@@ -795,24 +795,24 @@ again:
 static void opcode_add_resource(struct slot_prop *op,
 uint32_t resource, char direction,
 int index)
 {
 switch (direction) {
 case 'm':
 case 'i':
 assert(op->n_in < ARRAY_SIZE(op->in));
 op->in[op->n_in].resource = resource;
 op->in[op->n_in].index = index;
 ++op->n_in;
-/* fall through */
+fallthrough;
 case 'o':
 if (direction == 'm' || direction == 'o') {
 assert(op->n_out < ARRAY_SIZE(op->out));
 op->out[op->n_out].resource = resource;
 op->out[op->n_out].index = index;
 ++op->n_out;
 }
 break;
 default:
 g_assert_not_reached();
 }
 }
-- 
2.39.2




[RFC PATCH 56/75] hw/net: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/net/cadence_gem.c | 4 ++--
 hw/net/can/can_sja1000.c | 4 ++--
 hw/net/igb_core.c| 2 +-
 hw/net/igbvf.c   | 2 +-
 hw/net/imx_fec.c | 2 +-
 hw/net/net_rx_pkt.c  | 2 +-
 hw/net/pcnet.c   | 2 +-
 hw/net/rtl8139.c | 6 --
 hw/net/xilinx_ethlite.c  | 2 +-
 9 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
index f445d8bb5e..a59991af5b 100644
--- a/hw/net/cadence_gem.c
+++ b/hw/net/cadence_gem.c
@@ -748,119 +748,119 @@ static int gem_mac_address_filter(CadenceGEMState *s, 
const uint8_t *packet)
 /* Figure out which queue the received data should be sent to */
 static int get_queue_from_screen(CadenceGEMState *s, uint8_t *rxbuf_ptr,
  unsigned rxbufsize)
 {
 uint32_t reg;
 bool matched, mismatched;
 int i, j;
 
 for (i = 0; i < s->num_type1_screeners; i++) {
 reg = s->regs[GEM_SCREENING_TYPE1_REGISTER_0 + i];
 matched = false;
 mismatched = false;
 
 /* Screening is based on UDP Port */
 if (reg & GEM_ST1R_UDP_PORT_MATCH_ENABLE) {
 uint16_t udp_port = rxbuf_ptr[14 + 22] << 8 | rxbuf_ptr[14 + 23];
 if (udp_port == extract32(reg, GEM_ST1R_UDP_PORT_MATCH_SHIFT,
GEM_ST1R_UDP_PORT_MATCH_WIDTH)) {
 matched = true;
 } else {
 mismatched = true;
 }
 }
 
 /* Screening is based on DS/TC */
 if (reg & GEM_ST1R_DSTC_ENABLE) {
 uint8_t dscp = rxbuf_ptr[14 + 1];
 if (dscp == extract32(reg, GEM_ST1R_DSTC_MATCH_SHIFT,
GEM_ST1R_DSTC_MATCH_WIDTH)) {
 matched = true;
 } else {
 mismatched = true;
 }
 }
 
 if (matched && !mismatched) {
 return extract32(reg, GEM_ST1R_QUEUE_SHIFT, GEM_ST1R_QUEUE_WIDTH);
 }
 }
 
 for (i = 0; i < s->num_type2_screeners; i++) {
 reg = s->regs[GEM_SCREENING_TYPE2_REGISTER_0 + i];
 matched = false;
 mismatched = false;
 
 if (reg & GEM_ST2R_ETHERTYPE_ENABLE) {
 uint16_t type = rxbuf_ptr[12] << 8 | rxbuf_ptr[13];
 int et_idx = extract32(reg, GEM_ST2R_ETHERTYPE_INDEX_SHIFT,
 GEM_ST2R_ETHERTYPE_INDEX_WIDTH);
 
 if (et_idx > s->num_type2_screeners) {
 qemu_log_mask(LOG_GUEST_ERROR, "Out of range ethertype "
   "register index: %d\n", et_idx);
 }
 if (type == s->regs[GEM_SCREENING_TYPE2_ETHERTYPE_REG_0 +
 et_idx]) {
 matched = true;
 } else {
 mismatched = true;
 }
 }
 
 /* Compare A, B, C */
 for (j = 0; j < 3; j++) {
 uint32_t cr0, cr1, mask;
 uint16_t rx_cmp;
 int offset;
 int cr_idx = extract32(reg, GEM_ST2R_COMPARE_A_SHIFT + j * 6,
 GEM_ST2R_COMPARE_WIDTH);
 
 if (!(reg & (GEM_ST2R_COMPARE_A_ENABLE << (j * 6 {
 continue;
 }
 if (cr_idx > s->num_type2_screeners) {
 qemu_log_mask(LOG_GUEST_ERROR, "Out of range compare "
   "register index: %d\n", cr_idx);
 }
 
 cr0 = s->regs[GEM_TYPE2_COMPARE_0_WORD_0 + cr_idx * 2];
 cr1 = s->regs[GEM_TYPE2_COMPARE_0_WORD_0 + cr_idx * 2 + 1];
 offset = extract32(cr1, GEM_T2CW1_OFFSET_VALUE_SHIFT,
 GEM_T2CW1_OFFSET_VALUE_WIDTH);
 
 switch (extract32(cr1, GEM_T2CW1_COMPARE_OFFSET_SHIFT,
GEM_T2CW1_COMPARE_OFFSET_WIDTH)) {
 case 3: /* Skip UDP header */
 qemu_log_mask(LOG_UNIMP, "TCP compare offsets"
   "unimplemented - assuming UDP\n");
 offset += 8;
-/* Fallthrough */
+fallthrough;
 case 2: /* skip the IP header */
 offset += 20;
-/* Fallthrough */
+fallthrough;
 case 1: /* Count from after the ethertype */
 offset += 14;
 break;
 case 0:
 /* Offset from start of frame */
 break;
 }
 
 rx_cmp = rxbuf_ptr[offset] << 8 | rxbuf_ptr[offset];
 mask = extract32(cr0, 0, 16);
 
 if ((rx_cmp & mask) == (extract32(cr0, 16, 16) & mask)) {
 matched = true;
 } else {
 mismatched = true;
 }
 }
 
 if (matched && !mismatched) {
 return extract32(reg, GEM_ST2R_QUEUE_SHIFT, 

[RFC PATCH 56/78] hw/input: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/input/hid.c | 3 ++-
 hw/input/tsc2005.c | 4 ++--
 hw/input/tsc210x.c | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/hw/input/hid.c b/hw/input/hid.c
index a9c7dd1ce1..15fffc5dfb 100644
--- a/hw/input/hid.c
+++ b/hw/input/hid.c
@@ -250,88 +250,89 @@ static void hid_keyboard_event(DeviceState *dev, 
QemuConsole *src,
 static void hid_keyboard_process_keycode(HIDState *hs)
 {
 uint8_t hid_code, index, key;
 int i, keycode, slot;
 
 if (hs->n == 0) {
 return;
 }
 slot = hs->head & QUEUE_MASK; QUEUE_INCR(hs->head); hs->n--;
 keycode = hs->kbd.keycodes[slot];
 
 if (!hs->n) {
 trace_hid_kbd_queue_empty();
 }
 
 key = keycode & 0x7f;
 index = key | ((hs->kbd.modifiers & (1 << 8)) >> 1);
 hid_code = hid_usage_keys[index];
 hs->kbd.modifiers &= ~(1 << 8);
 
 switch (hid_code) {
 case 0x00:
 return;
 
 case 0xe0:
 assert(key == 0x1d);
 if (hs->kbd.modifiers & (1 << 9)) {
 /* The hid_codes for the 0xe1/0x1d scancode sequence are 0xe9/0xe0.
  * Here we're processing the second hid_code.  By dropping bit 9
  * and setting bit 8, the scancode after 0x1d will access the
  * second half of the table.
  */
 hs->kbd.modifiers ^= (1 << 8) | (1 << 9);
 return;
 }
 /* fall through to process Ctrl_L */
+fallthrough;
 case 0xe1 ... 0xe7:
 /* Ctrl_L/Ctrl_R, Shift_L/Shift_R, Alt_L/Alt_R, Win_L/Win_R.
  * Handle releases here, or fall through to process presses.
  */
 if (keycode & (1 << 7)) {
 hs->kbd.modifiers &= ~(1 << (hid_code & 0x0f));
 return;
 }
-/* fall through */
+fallthrough;
 case 0xe8 ... 0xe9:
 /* USB modifiers are just 1 byte long.  Bits 8 and 9 of
  * hs->kbd.modifiers implement a state machine that detects the
  * 0xe0 and 0xe1/0x1d sequences.  These bits do not follow the
  * usual rules where bit 7 marks released keys; they are cleared
  * elsewhere in the function as the state machine dictates.
  */
 hs->kbd.modifiers |= 1 << (hid_code & 0x0f);
 return;
 
 case 0xea ... 0xef:
 abort();
 
 default:
 break;
 }
 
 if (keycode & (1 << 7)) {
 for (i = hs->kbd.keys - 1; i >= 0; i--) {
 if (hs->kbd.key[i] == hid_code) {
 hs->kbd.key[i] = hs->kbd.key[-- hs->kbd.keys];
 hs->kbd.key[hs->kbd.keys] = 0x00;
 break;
 }
 }
 if (i < 0) {
 return;
 }
 } else {
 for (i = hs->kbd.keys - 1; i >= 0; i--) {
 if (hs->kbd.key[i] == hid_code) {
 break;
 }
 }
 if (i < 0) {
 if (hs->kbd.keys < sizeof(hs->kbd.key)) {
 hs->kbd.key[hs->kbd.keys++] = hid_code;
 }
 } else {
 return;
 }
 }
 }
diff --git a/hw/input/tsc2005.c b/hw/input/tsc2005.c
index db2b80e35f..4f3f1d9d12 100644
--- a/hw/input/tsc2005.c
+++ b/hw/input/tsc2005.c
@@ -234,70 +234,70 @@ static void tsc2005_write(TSC2005State *s, int reg, 
uint16_t data)
 /* This handles most of the chip's logic.  */
 static void tsc2005_pin_update(TSC2005State *s)
 {
 int64_t expires;
 bool pin_state;
 
 switch (s->pin_func) {
 case 0:
 pin_state = !s->pressure && !!s->dav;
 break;
 case 1:
 case 3:
 default:
 pin_state = !s->dav;
 break;
 case 2:
 pin_state = !s->pressure;
 }
 
 if (pin_state != s->irq) {
 s->irq = pin_state;
 qemu_set_irq(s->pint, s->irq);
 }
 
 switch (s->nextfunction) {
 case TSC_MODE_XYZ_SCAN:
 case TSC_MODE_XY_SCAN:
 if (!s->host_mode && s->dav)
 s->enabled = false;
 if (!s->pressure)
 return;
-/* Fall through */
+fallthrough;
 case TSC_MODE_AUX_SCAN:
 break;
 
 case TSC_MODE_X:
 case TSC_MODE_Y:
 case TSC_MODE_Z:
 if (!s->pressure)
 return;
-/* Fall through */
+fallthrough;
 case TSC_MODE_AUX:
 case TSC_MODE_TEMP1:
 case TSC_MODE_TEMP2:
 case TSC_MODE_X_TEST:
 case TSC_MODE_Y_TEST:
 case TSC_MODE_TS_TEST:
 if (s->dav)
 s->enabled = false;
 break;
 
 case TSC_MODE_RESERVED:
 case TSC_MODE_XX_DRV:
 case TSC_MODE_YY_DRV:
 case TSC_MODE_YX_DRV:
 default:
 return;
 }
 
 if (!s->enabled || s->busy)
 return;
 
 s->busy = true;
 s->precision = s->nextprecision;
 s->function = s->nextfunction;
 s->pdst = !

[RFC PATCH 50/78] hw/audio: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/audio/asc.c| 2 +-
 hw/audio/cs4231a.c| 2 +-
 hw/audio/gusemu_hal.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/audio/asc.c b/hw/audio/asc.c
index 0f36b4ce9b..336da09509 100644
--- a/hw/audio/asc.c
+++ b/hw/audio/asc.c
@@ -154,126 +154,126 @@ static uint8_t asc_fifo_get(ASCFIFOState *fs)
 static int generate_fifo(ASCState *s, int maxsamples)
 {
 int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
 uint8_t *buf = s->mixbuf;
 int i, wcount = 0;
 
 while (wcount < maxsamples) {
 uint8_t val;
 int16_t d, f0, f1;
 int32_t t;
 int shift, filter;
 bool hasdata = false;
 
 for (i = 0; i < 2; i++) {
 ASCFIFOState *fs = &s->fifos[i];
 
 switch (fs->extregs[ASC_EXTREGS_FIFOCTRL] & 0x83) {
 case 0x82:
 /*
  * CD-XA BRR mode: decompress 15 bytes into 28 16-bit
  * samples
  */
 if (!fs->cnt) {
 val = 0x80;
 break;
 }
 
 if (fs->xa_cnt == -1) {
 /* Start of packet, get flags */
 fs->xa_flags = asc_fifo_get(fs);
 fs->xa_cnt = 0;
 }
 
 shift = fs->xa_flags & 0xf;
 filter = fs->xa_flags >> 4;
 f0 = (int8_t)fs->extregs[ASC_EXTREGS_CDXA_DECOMP_FILT +
  (filter << 1) + 1];
 f1 = (int8_t)fs->extregs[ASC_EXTREGS_CDXA_DECOMP_FILT +
  (filter << 1)];
 
 if ((fs->xa_cnt & 1) == 0) {
 if (!fs->cnt) {
 val = 0x80;
 break;
 }
 
 fs->xa_val = asc_fifo_get(fs);
 d = (fs->xa_val & 0xf) << 12;
 } else {
 d = (fs->xa_val & 0xf0) << 8;
 }
 t = (d >> shift) + (((fs->xa_last[0] * f0) +
  (fs->xa_last[1] * f1) + 32) >> 6);
 if (t < -32768) {
 t = -32768;
 } else if (t > 32767) {
 t = 32767;
 }
 
 /*
  * CD-XA BRR generates 16-bit signed output, so convert to
  * 8-bit before writing to buffer. Does real hardware do the
  * same?
  */
 val = (uint8_t)(t / 256) ^ 0x80;
 hasdata = true;
 fs->xa_cnt++;
 
 fs->xa_last[1] = fs->xa_last[0];
 fs->xa_last[0] = (int16_t)t;
 
 if (fs->xa_cnt == 28) {
 /* End of packet */
 fs->xa_cnt = -1;
 }
 break;
 
 default:
-/* fallthrough */
+fallthrough;
 case 0x80:
 /* Raw mode */
 if (fs->cnt) {
 val = asc_fifo_get(fs);
 hasdata = true;
 } else {
 val = 0x80;
 }
 break;
 }
 
 buf[wcount * 2 + i] = val;
 }
 
 if (!hasdata) {
 break;
 }
 
 wcount++;
 }
 
 /*
  * MacOS (un)helpfully leaves the FIFO engine running even when it has
  * finished writing out samples, but still expects the FIFO empty
  * interrupts to be generated for each FIFO cycle (without these interrupts
  * MacOS will freeze)
  */
 if (s->fifos[0].cnt == 0 && s->fifos[1].cnt == 0) {
 if (!s->fifo_empty_ns) {
 /* FIFO has completed first empty cycle */
 s->fifo_empty_ns = now;
 } else if (now > (s->fifo_empty_ns + ASC_FIFO_CYCLE_TIME)) {
 /* FIFO has completed entire cycle with no data */
 s->fifos[0].int_status |= ASC_FIFO_STATUS_HALF_FULL |
   ASC_FIFO_STATUS_FULL_EMPTY;
 s->fifos[1].int_status |= ASC_FIFO_STATUS_HALF_FULL |
   ASC_FIFO_STATUS_FULL_EMPTY;
 s->fifo_empty_ns = now;
 asc_raise_irq(s);
 }
 } else {
 /* FIFO contains data, reset empty time */
 s->fifo_empty_ns = 0;
 }
 
 return wcount;
 }
diff --git a/hw/audio/cs4231a.c b/hw/audio/cs4231a.c
index 3aa105748d..3bf0116c68 100644
--- a/hw/audio/cs4231a.c
+++ b/hw/audio/cs4231a.c
@@ -272,90 +272,90 @@ static void cs_audio_callback (void *opaque, int free)
 static void cs_reset_voices (CSState *s, uint32_t val)
 {
 int xtal;
 struct audsettings a

[RFC PATCH v2 12/78] hw/usb: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/usb/dev-mtp.c   | 2 +-
 hw/usb/dev-wacom.c | 2 +-
 hw/usb/hcd-ehci.c  | 4 +++-
 hw/usb/hcd-xhci.c  | 4 ++--
 hw/usb/redirect.c  | 4 ++--
 hw/usb/tusb6010.c  | 2 +-
 6 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 1cac1cd435..5cbaabd2b2 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -1602,76 +1602,76 @@ static int usb_mtp_update_object(MTPObject *parent, 
char *name)
 static void usb_mtp_write_data(MTPState *s, uint32_t handle)
 {
 MTPData *d = s->data_out;
 MTPObject *parent =
 usb_mtp_object_lookup(s, s->dataset.parent_handle);
 char *path = NULL;
 uint64_t rc;
 mode_t mask = 0755;
 int ret = 0;
 
 assert(d != NULL);
 
 switch (d->write_status) {
 case WRITE_START:
 if (!parent || !s->write_pending) {
 usb_mtp_queue_result(s, RES_INVALID_OBJECTINFO, d->trans,
 0, 0, 0, 0);
 return;
 }
 
 if (s->dataset.filename) {
 path = g_strdup_printf("%s/%s", parent->path, s->dataset.filename);
 if (s->dataset.format == FMT_ASSOCIATION) {
 ret = g_mkdir(path, mask);
 if (!ret) {
 usb_mtp_queue_result(s, RES_OK, d->trans, 3,
  QEMU_STORAGE_ID,
  s->dataset.parent_handle,
  handle);
 goto close;
 }
 goto done;
 }
 
 d->fd = open(path, O_CREAT | O_WRONLY |
  O_CLOEXEC | O_NOFOLLOW, mask & 0666);
 if (d->fd == -1) {
 ret = 1;
 goto done;
 }
 
 /* Return success if initiator sent 0 sized data */
 if (!s->dataset.size) {
 goto done;
 }
 if (d->length != MTP_WRITE_BUF_SZ && !d->pending) {
 d->write_status = WRITE_END;
 }
 }
-/* fall through */
+fallthrough;
 case WRITE_CONTINUE:
 case WRITE_END:
 rc = write_retry(d->fd, d->data, d->data_offset,
  d->offset - d->data_offset);
 if (rc != d->data_offset) {
 ret = 1;
 goto done;
 }
 if (d->write_status != WRITE_END) {
 g_free(path);
 return;
 } else {
 /*
  * Return an incomplete transfer if file size doesn't match
  * for < 4G file or if lstat fails which will result in an 
incorrect
  * file size
  */
 if ((s->dataset.size != 0x &&
  d->offset != s->dataset.size) ||
 usb_mtp_update_object(parent, s->dataset.filename)) {
 usb_mtp_queue_result(s, RES_INCOMPLETE_TRANSFER, d->trans,
  0, 0, 0, 0);
 goto close;
 }
 }
 }
diff --git a/hw/usb/dev-wacom.c b/hw/usb/dev-wacom.c
index 7177c17f03..bd2a1bae50 100644
--- a/hw/usb/dev-wacom.c
+++ b/hw/usb/dev-wacom.c
@@ -371,27 +371,27 @@ static void usb_wacom_handle_control(USBDevice *dev, 
USBPacket *p,
 static void usb_wacom_handle_data(USBDevice *dev, USBPacket *p)
 {
 USBWacomState *s = (USBWacomState *) dev;
 g_autofree uint8_t *buf = g_malloc(p->iov.size);
 int len = 0;
 
 switch (p->pid) {
 case USB_TOKEN_IN:
 if (p->ep->nr == 1) {
 if (!(s->changed || s->idle)) {
 p->status = USB_RET_NAK;
 return;
 }
 s->changed = 0;
 if (s->mode == WACOM_MODE_HID)
 len = usb_mouse_poll(s, buf, p->iov.size);
 else if (s->mode == WACOM_MODE_WACOM)
 len = usb_wacom_poll(s, buf, p->iov.size);
 usb_packet_copy(p, buf, len);
 break;
 }
-/* Fall through.  */
+fallthrough;
 case USB_TOKEN_OUT:
 default:
 p->status = USB_RET_STALL;
 }
 }
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 19b4534c20..e29cc21957 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -1402,116 +1402,116 @@ static int ehci_execute(EHCIPacket *p, const char 
*action)
 static int ehci_process_itd(EHCIState *ehci,
 EHCIitd *itd,
 uint32_t addr)
 {
 USBDevice *dev;
 USBEndpoint *ep;
 uint32_t i, len, pid, dir, devaddr, endp;
 uint32_t pg, off, ptr1, ptr2, max, mult;
 
 ehci->periodic_sched_active = PERIODIC_ACTIVE;
 
 dir =(itd->bufptr[1] & ITD_BUFPTR_DIRECTION);
 devaddr = get_field(itd->bufptr[0], ITD_BUFPTR_DEVADDR);
 endp = get_field(itd-

[RFC PATCH 41/78] linux-user: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 linux-user/mips/cpu_loop.c | 8 
 linux-user/mmap.c  | 2 +-
 linux-user/syscall.c   | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/linux-user/mips/cpu_loop.c b/linux-user/mips/cpu_loop.c
index 8735e58bad..38ddcadfc6 100644
--- a/linux-user/mips/cpu_loop.c
+++ b/linux-user/mips/cpu_loop.c
@@ -63,68 +63,68 @@ static void do_tr_or_bp(CPUMIPSState *env, unsigned int 
code, bool trap)
 void cpu_loop(CPUMIPSState *env)
 {
 CPUState *cs = env_cpu(env);
 int trapnr, si_code;
 unsigned int code;
 abi_long ret;
 # ifdef TARGET_ABI_MIPSO32
 unsigned int syscall_num;
 # endif
 
 for(;;) {
 cpu_exec_start(cs);
 trapnr = cpu_exec(cs);
 cpu_exec_end(cs);
 process_queued_cpu_work(cs);
 
 switch(trapnr) {
 case EXCP_SYSCALL:
 env->active_tc.PC += 4;
 # ifdef TARGET_ABI_MIPSO32
 syscall_num = env->active_tc.gpr[2] - 4000;
 if (syscall_num >= sizeof(mips_syscall_args)) {
 /* syscall_num is larger that any defined for MIPS O32 */
 ret = -TARGET_ENOSYS;
 } else if (mips_syscall_args[syscall_num] ==
MIPS_SYSCALL_NUMBER_UNUSED) {
 /* syscall_num belongs to the range not defined for MIPS O32 */
 ret = -TARGET_ENOSYS;
 } else {
 /* syscall_num is valid */
 int nb_args;
 abi_ulong sp_reg;
 abi_ulong arg5 = 0, arg6 = 0, arg7 = 0, arg8 = 0;
 
 nb_args = mips_syscall_args[syscall_num];
 sp_reg = env->active_tc.gpr[29];
 switch (nb_args) {
 /* these arguments are taken from the stack */
 case 8:
 if ((ret = get_user_ual(arg8, sp_reg + 28)) != 0) {
 goto done_syscall;
 }
-/* fall through */
+fallthrough;
 case 7:
 if ((ret = get_user_ual(arg7, sp_reg + 24)) != 0) {
 goto done_syscall;
 }
-/* fall through */
+fallthrough;
 case 6:
 if ((ret = get_user_ual(arg6, sp_reg + 20)) != 0) {
 goto done_syscall;
 }
-/* fall through */
+fallthrough;
 case 5:
 if ((ret = get_user_ual(arg5, sp_reg + 16)) != 0) {
 goto done_syscall;
 }
-/* fall through */
+fallthrough;
 default:
 break;
 }
 ret = do_syscall(env, env->active_tc.gpr[2],
  env->active_tc.gpr[4],
  env->active_tc.gpr[5],
  env->active_tc.gpr[6],
  env->active_tc.gpr[7],
  arg5, arg6, arg7, arg8);
 }
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 8ccaab7859..ff33b4ccf6 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -960,84 +960,84 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong 
old_size,
 abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice)
 {
 abi_ulong len;
 int ret = 0;
 
 if (start & ~TARGET_PAGE_MASK) {
 return -TARGET_EINVAL;
 }
 if (len_in == 0) {
 return 0;
 }
 len = TARGET_PAGE_ALIGN(len_in);
 if (len == 0 || !guest_range_valid_untagged(start, len)) {
 return -TARGET_EINVAL;
 }
 
 /* Translate for some architectures which have different MADV_xxx values */
 switch (advice) {
 case TARGET_MADV_DONTNEED:  /* alpha */
 advice = MADV_DONTNEED;
 break;
 case TARGET_MADV_WIPEONFORK:/* parisc */
 advice = MADV_WIPEONFORK;
 break;
 case TARGET_MADV_KEEPONFORK:/* parisc */
 advice = MADV_KEEPONFORK;
 break;
 /* we do not care about the other MADV_xxx values yet */
 }
 
 /*
  * Most advice values are hints, so ignoring and returning success is ok.
  *
  * However, some advice values such as MADV_DONTNEED, MADV_WIPEONFORK and
  * MADV_KEEPONFORK are not hints and need to be emulated.
  *
  * A straight passthrough for those may not be safe because qemu sometimes
  * turns private file-backed mappings into anonymous mappings.
  * If all guest pages have PAGE_PASSTHROUGH set, mappings have the
  * same semantics for the host as for the guest.
  *
  * We pass through MADV_WIPEONFORK and M

[RFC PATCH v2 19/78] target/hppa: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/hppa/translate.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/target/hppa/translate.c b/target/hppa/translate.c
index 9f3ba9f42f..1df81b0fa2 100644
--- a/target/hppa/translate.c
+++ b/target/hppa/translate.c
@@ -480,14 +480,14 @@ static DisasCond cond_make(TCGCond c, TCGv_reg a0, 
TCGv_reg a1)
 static void cond_free(DisasCond *cond)
 {
 switch (cond->c) {
 default:
 cond->a0 = NULL;
 cond->a1 = NULL;
-/* fallthru */
+fallthrough;
 case TCG_COND_ALWAYS:
 cond->c = TCG_COND_NEVER;
 break;
 case TCG_COND_NEVER:
 break;
 }
 }
@@ -3831,65 +3831,65 @@ static bool trans_fcmp_d(DisasContext *ctx, arg_fclass2 
*a)
 static bool trans_ftest(DisasContext *ctx, arg_ftest *a)
 {
 TCGv_reg t;
 
 nullify_over(ctx);
 
 t = get_temp(ctx);
 tcg_gen_ld32u_reg(t, tcg_env, offsetof(CPUHPPAState, fr0_shadow));
 
 if (a->y == 1) {
 int mask;
 bool inv = false;
 
 switch (a->c) {
 case 0: /* simple */
 tcg_gen_andi_reg(t, t, 0x400);
 ctx->null_cond = cond_make_0(TCG_COND_NE, t);
 goto done;
 case 2: /* rej */
 inv = true;
-/* fallthru */
+fallthrough;
 case 1: /* acc */
 mask = 0x43ff800;
 break;
 case 6: /* rej8 */
 inv = true;
-/* fallthru */
+fallthrough;
 case 5: /* acc8 */
 mask = 0x43f8000;
 break;
 case 9: /* acc6 */
 mask = 0x43e;
 break;
 case 13: /* acc4 */
 mask = 0x438;
 break;
 case 17: /* acc2 */
 mask = 0x420;
 break;
 default:
 gen_illegal(ctx);
 return true;
 }
 if (inv) {
 TCGv_reg c = load_const(ctx, mask);
 tcg_gen_or_reg(t, t, c);
 ctx->null_cond = cond_make(TCG_COND_EQ, t, c);
 } else {
 tcg_gen_andi_reg(t, t, mask);
 ctx->null_cond = cond_make_0(TCG_COND_EQ, t);
 }
 } else {
 unsigned cbit = (a->y ^ 1) - 1;
 
 tcg_gen_extract_reg(t, t, 21 - cbit, 1);
 ctx->null_cond = cond_make_0(TCG_COND_NE, t);
 }
 
  done:
 return nullify_end(ctx);
 }
 
 /*
  * Float class 2
  */
@@ -4219,28 +4219,28 @@ static void hppa_tr_translate_insn(DisasContextBase 
*dcbase, CPUState *cs)
 static void hppa_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
 {
 DisasContext *ctx = container_of(dcbase, DisasContext, base);
 DisasJumpType is_jmp = ctx->base.is_jmp;
 
 switch (is_jmp) {
 case DISAS_NORETURN:
 break;
 case DISAS_TOO_MANY:
 case DISAS_IAQ_N_STALE:
 case DISAS_IAQ_N_STALE_EXIT:
 copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_f, cpu_iaoq_f);
 copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_b, cpu_iaoq_b);
 nullify_save(ctx);
-/* FALLTHRU */
+fallthrough;
 case DISAS_IAQ_N_UPDATED:
 if (is_jmp != DISAS_IAQ_N_STALE_EXIT) {
 tcg_gen_lookup_and_goto_ptr();
 break;
 }
-/* FALLTHRU */
+fallthrough;
 case DISAS_EXIT:
 tcg_gen_exit_tb(NULL, 0);
 break;
 default:
 g_assert_not_reached();
 }
 }
-- 
2.39.2




[RFC PATCH v2 04/78] qapi/opts-visitor: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 qapi/opts-visitor.c | 1 +
 qapi/string-input-visitor.c | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
index 8f1efab8b9..d7376bf239 100644
--- a/qapi/opts-visitor.c
+++ b/qapi/opts-visitor.c
@@ -249,41 +249,42 @@ static GenericList *
 opts_next_list(Visitor *v, GenericList *tail, size_t size)
 {
 OptsVisitor *ov = to_ov(v);
 
 switch (ov->list_mode) {
 case LM_TRAVERSED:
 return NULL;
 case LM_SIGNED_INTERVAL:
 case LM_UNSIGNED_INTERVAL:
 if (ov->list_mode == LM_SIGNED_INTERVAL) {
 if (ov->range_next.s < ov->range_limit.s) {
 ++ov->range_next.s;
 break;
 }
 } else if (ov->range_next.u < ov->range_limit.u) {
 ++ov->range_next.u;
 break;
 }
 ov->list_mode = LM_IN_PROGRESS;
 /* range has been completed, fall through in order to pop option */
+fallthrough;
 
 case LM_IN_PROGRESS: {
 const QemuOpt *opt;
 
 opt = g_queue_pop_head(ov->repeated_opts);
 if (g_queue_is_empty(ov->repeated_opts)) {
 g_hash_table_remove(ov->unprocessed_opts, opt->name);
 ov->repeated_opts = NULL;
 ov->list_mode = LM_TRAVERSED;
 return NULL;
 }
 break;
 }
 
 default:
 abort();
 }
 
 tail->next = g_malloc0(size);
 return tail->next;
 }
diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c
index 197139c1c0..1ce43da20b 100644
--- a/qapi/string-input-visitor.c
+++ b/qapi/string-input-visitor.c
@@ -182,41 +182,41 @@ static int try_parse_int64_list_entry(StringInputVisitor 
*siv, int64_t *obj)
 static bool parse_type_int64(Visitor *v, const char *name, int64_t *obj,
  Error **errp)
 {
 StringInputVisitor *siv = to_siv(v);
 int64_t val;
 
 switch (siv->lm) {
 case LM_NONE:
 /* just parse a simple int64, bail out if not completely consumed */
 if (qemu_strtoi64(siv->string, NULL, 0, &val)) {
 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
name ? name : "null", "int64");
 return false;
 }
 *obj = val;
 return true;
 case LM_UNPARSED:
 if (try_parse_int64_list_entry(siv, obj)) {
 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : 
"null",
"list of int64 values or ranges");
 return false;
 }
 assert(siv->lm == LM_INT64_RANGE);
-/* fall through */
+fallthrough;
 case LM_INT64_RANGE:
 /* return the next element in the range */
 assert(siv->rangeNext.i64 <= siv->rangeEnd.i64);
 *obj = siv->rangeNext.i64++;
 
 if (siv->rangeNext.i64 > siv->rangeEnd.i64 || *obj == INT64_MAX) {
 /* end of range, check if there is more to parse */
 siv->lm = siv->unparsed_string[0] ? LM_UNPARSED : LM_END;
 }
 return true;
 case LM_END:
 error_setg(errp, "Fewer list elements expected");
 return false;
 default:
 abort();
 }
 }
@@ -272,41 +272,41 @@ static int try_parse_uint64_list_entry(StringInputVisitor 
*siv, uint64_t *obj)
 static bool parse_type_uint64(Visitor *v, const char *name, uint64_t *obj,
   Error **errp)
 {
 StringInputVisitor *siv = to_siv(v);
 uint64_t val;
 
 switch (siv->lm) {
 case LM_NONE:
 /* just parse a simple uint64, bail out if not completely consumed */
 if (qemu_strtou64(siv->string, NULL, 0, &val)) {
 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : 
"null",
"uint64");
 return false;
 }
 *obj = val;
 return true;
 case LM_UNPARSED:
 if (try_parse_uint64_list_entry(siv, obj)) {
 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : 
"null",
"list of uint64 values or ranges");
 return false;
 }
 assert(siv->lm == LM_UINT64_RANGE);
-/* fall through */
+fallthrough;
 case LM_UINT64_RANGE:
 /* return the next element in the range */
 assert(siv->rangeNext.u64 <= siv->rangeEnd.u64);
 *obj = siv->rangeNext.u64++;
 
 if (siv->rangeNext.u64 > siv->rangeEnd.u64 || *obj == UINT64_MAX) {
 /* end of range, check if there is more to parse */
 siv->lm = siv->unparsed_string[0] ? LM_UNPARSED : LM_END;
 }
 return true;
 case LM_END:
 error_setg(errp, "Fewer list elements expected");
 return false;
 default:
 abort();
 }
 }
-- 
2.39.2

[RFC PATCH 26/78] target/s390x: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/s390x/cpu.c  |  4 ++--
 target/s390x/kvm/kvm.c  |  2 +-
 target/s390x/mmu_helper.c   |  6 +++---
 target/s390x/tcg/translate.c| 18 +++---
 target/s390x/tcg/translate_vx.c.inc |  2 +-
 5 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c
index 4f7599d72c..01df983991 100644
--- a/target/s390x/cpu.c
+++ b/target/s390x/cpu.c
@@ -150,69 +150,69 @@ static void s390_query_cpu_fast(CPUState *cpu, 
CpuInfoFast *value)
 /* S390CPUClass::reset() */
 static void s390_cpu_reset(CPUState *s, cpu_reset_type type)
 {
 S390CPU *cpu = S390_CPU(s);
 S390CPUClass *scc = S390_CPU_GET_CLASS(cpu);
 CPUS390XState *env = &cpu->env;
 DeviceState *dev = DEVICE(s);
 
 scc->parent_reset(dev);
 cpu->env.sigp_order = 0;
 s390_cpu_set_state(S390_CPU_STATE_STOPPED, cpu);
 
 switch (type) {
 case S390_CPU_RESET_CLEAR:
 memset(env, 0, offsetof(CPUS390XState, start_initial_reset_fields));
-/* fall through */
+fallthrough;
 case S390_CPU_RESET_INITIAL:
 /* initial reset does not clear everything! */
 memset(&env->start_initial_reset_fields, 0,
offsetof(CPUS390XState, start_normal_reset_fields) -
offsetof(CPUS390XState, start_initial_reset_fields));
 
 /* architectured initial value for Breaking-Event-Address register */
 env->gbea = 1;
 
 /* architectured initial values for CR 0 and 14 */
 env->cregs[0] = CR0_RESET;
 env->cregs[14] = CR14_RESET;
 
 #if defined(CONFIG_USER_ONLY)
 /* user mode should always be allowed to use the full FPU */
 env->cregs[0] |= CR0_AFP;
 if (s390_has_feat(S390_FEAT_VECTOR)) {
 env->cregs[0] |= CR0_VECTOR;
 }
 #endif
 
 /* tininess for underflow is detected before rounding */
 set_float_detect_tininess(float_tininess_before_rounding,
   &env->fpu_status);
-   /* fall through */
+fallthrough;
 case S390_CPU_RESET_NORMAL:
 env->psw.mask &= ~PSW_MASK_RI;
 memset(&env->start_normal_reset_fields, 0,
offsetof(CPUS390XState, end_reset_fields) -
offsetof(CPUS390XState, start_normal_reset_fields));
 
 env->pfault_token = -1UL;
 env->bpbc = false;
 break;
 default:
 g_assert_not_reached();
 }
 
 /* Reset state inside the kernel that we cannot access yet from QEMU. */
 if (kvm_enabled()) {
 switch (type) {
 case S390_CPU_RESET_CLEAR:
 kvm_s390_reset_vcpu_clear(cpu);
 break;
 case S390_CPU_RESET_INITIAL:
 kvm_s390_reset_vcpu_initial(cpu);
 break;
 case S390_CPU_RESET_NORMAL:
 kvm_s390_reset_vcpu_normal(cpu);
 break;
 }
 }
 }
diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c
index bc5c56a305..11b2c05df6 100644
--- a/target/s390x/kvm/kvm.c
+++ b/target/s390x/kvm/kvm.c
@@ -1080,48 +1080,48 @@ int kvm_arch_process_async_events(CPUState *cs)
 static int s390_kvm_irq_to_interrupt(struct kvm_s390_irq *irq,
  struct kvm_s390_interrupt *interrupt)
 {
 int r = 0;
 
 interrupt->type = irq->type;
 switch (irq->type) {
 case KVM_S390_INT_VIRTIO:
 interrupt->parm = irq->u.ext.ext_params;
-/* fall through */
+fallthrough;
 case KVM_S390_INT_PFAULT_INIT:
 case KVM_S390_INT_PFAULT_DONE:
 interrupt->parm64 = irq->u.ext.ext_params2;
 break;
 case KVM_S390_PROGRAM_INT:
 interrupt->parm = irq->u.pgm.code;
 break;
 case KVM_S390_SIGP_SET_PREFIX:
 interrupt->parm = irq->u.prefix.address;
 break;
 case KVM_S390_INT_SERVICE:
 interrupt->parm = irq->u.ext.ext_params;
 break;
 case KVM_S390_MCHK:
 interrupt->parm = irq->u.mchk.cr14;
 interrupt->parm64 = irq->u.mchk.mcic;
 break;
 case KVM_S390_INT_EXTERNAL_CALL:
 interrupt->parm = irq->u.extcall.code;
 break;
 case KVM_S390_INT_EMERGENCY:
 interrupt->parm = irq->u.emerg.code;
 break;
 case KVM_S390_SIGP_STOP:
 case KVM_S390_RESTART:
 break; /* These types have no parameters */
 case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
 interrupt->parm = irq->u.io.subchannel_id << 16;
 interrupt->parm |= irq->u.io.subchannel_nr;
 interrupt->parm64 = (uint64_t)irq->u.io.io_int_parm << 32;
 interrupt->parm64 |= irq->u.io.io_int_word;
 break;
 default:
 r = -EINVAL;
 break;
 }
 return r;
 }
diff --git a/target/s390x/mmu_helper.c b/target/s390

[RFC PATCH 04/78] qapi/opts-visitor: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 qapi/opts-visitor.c | 1 +
 qapi/string-input-visitor.c | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
index 8f1efab8b9..d7376bf239 100644
--- a/qapi/opts-visitor.c
+++ b/qapi/opts-visitor.c
@@ -249,41 +249,42 @@ static GenericList *
 opts_next_list(Visitor *v, GenericList *tail, size_t size)
 {
 OptsVisitor *ov = to_ov(v);
 
 switch (ov->list_mode) {
 case LM_TRAVERSED:
 return NULL;
 case LM_SIGNED_INTERVAL:
 case LM_UNSIGNED_INTERVAL:
 if (ov->list_mode == LM_SIGNED_INTERVAL) {
 if (ov->range_next.s < ov->range_limit.s) {
 ++ov->range_next.s;
 break;
 }
 } else if (ov->range_next.u < ov->range_limit.u) {
 ++ov->range_next.u;
 break;
 }
 ov->list_mode = LM_IN_PROGRESS;
 /* range has been completed, fall through in order to pop option */
+fallthrough;
 
 case LM_IN_PROGRESS: {
 const QemuOpt *opt;
 
 opt = g_queue_pop_head(ov->repeated_opts);
 if (g_queue_is_empty(ov->repeated_opts)) {
 g_hash_table_remove(ov->unprocessed_opts, opt->name);
 ov->repeated_opts = NULL;
 ov->list_mode = LM_TRAVERSED;
 return NULL;
 }
 break;
 }
 
 default:
 abort();
 }
 
 tail->next = g_malloc0(size);
 return tail->next;
 }
diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c
index 197139c1c0..1ce43da20b 100644
--- a/qapi/string-input-visitor.c
+++ b/qapi/string-input-visitor.c
@@ -182,41 +182,41 @@ static int try_parse_int64_list_entry(StringInputVisitor 
*siv, int64_t *obj)
 static bool parse_type_int64(Visitor *v, const char *name, int64_t *obj,
  Error **errp)
 {
 StringInputVisitor *siv = to_siv(v);
 int64_t val;
 
 switch (siv->lm) {
 case LM_NONE:
 /* just parse a simple int64, bail out if not completely consumed */
 if (qemu_strtoi64(siv->string, NULL, 0, &val)) {
 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
name ? name : "null", "int64");
 return false;
 }
 *obj = val;
 return true;
 case LM_UNPARSED:
 if (try_parse_int64_list_entry(siv, obj)) {
 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : 
"null",
"list of int64 values or ranges");
 return false;
 }
 assert(siv->lm == LM_INT64_RANGE);
-/* fall through */
+fallthrough;
 case LM_INT64_RANGE:
 /* return the next element in the range */
 assert(siv->rangeNext.i64 <= siv->rangeEnd.i64);
 *obj = siv->rangeNext.i64++;
 
 if (siv->rangeNext.i64 > siv->rangeEnd.i64 || *obj == INT64_MAX) {
 /* end of range, check if there is more to parse */
 siv->lm = siv->unparsed_string[0] ? LM_UNPARSED : LM_END;
 }
 return true;
 case LM_END:
 error_setg(errp, "Fewer list elements expected");
 return false;
 default:
 abort();
 }
 }
@@ -272,41 +272,41 @@ static int try_parse_uint64_list_entry(StringInputVisitor 
*siv, uint64_t *obj)
 static bool parse_type_uint64(Visitor *v, const char *name, uint64_t *obj,
   Error **errp)
 {
 StringInputVisitor *siv = to_siv(v);
 uint64_t val;
 
 switch (siv->lm) {
 case LM_NONE:
 /* just parse a simple uint64, bail out if not completely consumed */
 if (qemu_strtou64(siv->string, NULL, 0, &val)) {
 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : 
"null",
"uint64");
 return false;
 }
 *obj = val;
 return true;
 case LM_UNPARSED:
 if (try_parse_uint64_list_entry(siv, obj)) {
 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : 
"null",
"list of uint64 values or ranges");
 return false;
 }
 assert(siv->lm == LM_UINT64_RANGE);
-/* fall through */
+fallthrough;
 case LM_UINT64_RANGE:
 /* return the next element in the range */
 assert(siv->rangeNext.u64 <= siv->rangeEnd.u64);
 *obj = siv->rangeNext.u64++;
 
 if (siv->rangeNext.u64 > siv->rangeEnd.u64 || *obj == UINT64_MAX) {
 /* end of range, check if there is more to parse */
 siv->lm = siv->unparsed_string[0] ? LM_UNPARSED : LM_END;
 }
 return true;
 case LM_END:
 error_setg(errp, "Fewer list elements expected");
 return false;
 default:
 abort();
 }
 }
-- 
2.39.2

[RFC PATCH 30/78] target/nios2: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/nios2/helper.c| 6 +++---
 target/nios2/translate.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/target/nios2/helper.c b/target/nios2/helper.c
index bb3b09e5a7..b44e73768e 100644
--- a/target/nios2/helper.c
+++ b/target/nios2/helper.c
@@ -125,136 +125,136 @@ static void do_eic_irq(Nios2CPU *cpu)
 void nios2_cpu_do_interrupt(CPUState *cs)
 {
 Nios2CPU *cpu = NIOS2_CPU(cs);
 CPUNios2State *env = &cpu->env;
 uint32_t tlbmisc_set = 0;
 
 if (qemu_loglevel_mask(CPU_LOG_INT)) {
 const char *name = NULL;
 
 switch (cs->exception_index) {
 case EXCP_IRQ:
 name = "interrupt";
 break;
 case EXCP_TLB_X:
 case EXCP_TLB_D:
 if (env->ctrl[CR_STATUS] & CR_STATUS_EH) {
 name = "TLB MISS (double)";
 } else {
 name = "TLB MISS (fast)";
 }
 break;
 case EXCP_PERM_R:
 case EXCP_PERM_W:
 case EXCP_PERM_X:
 name = "TLB PERM";
 break;
 case EXCP_SUPERA_X:
 case EXCP_SUPERA_D:
 name = "SUPERVISOR (address)";
 break;
 case EXCP_SUPERI:
 name = "SUPERVISOR (insn)";
 break;
 case EXCP_ILLEGAL:
 name = "ILLEGAL insn";
 break;
 case EXCP_UNALIGN:
 name = "Misaligned (data)";
 break;
 case EXCP_UNALIGND:
 name = "Misaligned (destination)";
 break;
 case EXCP_DIV:
 name = "DIV error";
 break;
 case EXCP_TRAP:
 name = "TRAP insn";
 break;
 case EXCP_BREAK:
 name = "BREAK insn";
 break;
 case EXCP_SEMIHOST:
 name = "SEMIHOST insn";
 break;
 }
 if (name) {
 qemu_log("%s at pc=0x%08x\n", name, env->pc);
 } else {
 qemu_log("Unknown exception %d at pc=0x%08x\n",
  cs->exception_index, env->pc);
 }
 }
 
 switch (cs->exception_index) {
 case EXCP_IRQ:
 /* Note that PC is advanced for interrupts as well. */
 env->pc += 4;
 if (cpu->eic_present) {
 do_eic_irq(cpu);
 } else {
 do_iic_irq(cpu);
 }
 break;
 
 case EXCP_TLB_D:
 tlbmisc_set = CR_TLBMISC_D;
-/* fall through */
+fallthrough;
 case EXCP_TLB_X:
 if (env->ctrl[CR_STATUS] & CR_STATUS_EH) {
 tlbmisc_set |= CR_TLBMISC_DBL;
 /*
  * Normally, we don't write to tlbmisc unless !EH,
  * so do it manually for the double-tlb miss exception.
  */
 env->ctrl[CR_TLBMISC] &= ~(CR_TLBMISC_D |
CR_TLBMISC_PERM |
CR_TLBMISC_BAD);
 env->ctrl[CR_TLBMISC] |= tlbmisc_set;
 do_exception(cpu, cpu->exception_addr, 0, false);
 } else {
 tlbmisc_set |= CR_TLBMISC_WE;
 do_exception(cpu, cpu->fast_tlb_miss_addr, tlbmisc_set, false);
 }
 break;
 
 case EXCP_PERM_R:
 case EXCP_PERM_W:
 tlbmisc_set = CR_TLBMISC_D;
-/* fall through */
+fallthrough;
 case EXCP_PERM_X:
 tlbmisc_set |= CR_TLBMISC_PERM;
 if (!(env->ctrl[CR_STATUS] & CR_STATUS_EH)) {
 tlbmisc_set |= CR_TLBMISC_WE;
 }
 do_exception(cpu, cpu->exception_addr, tlbmisc_set, false);
 break;
 
 case EXCP_SUPERA_D:
 case EXCP_UNALIGN:
 tlbmisc_set = CR_TLBMISC_D;
-/* fall through */
+fallthrough;
 case EXCP_SUPERA_X:
 case EXCP_UNALIGND:
 tlbmisc_set |= CR_TLBMISC_BAD;
 do_exception(cpu, cpu->exception_addr, tlbmisc_set, false);
 break;
 
 case EXCP_SUPERI:
 case EXCP_ILLEGAL:
 case EXCP_DIV:
 case EXCP_TRAP:
 do_exception(cpu, cpu->exception_addr, 0, false);
 break;
 
 case EXCP_BREAK:
 do_exception(cpu, cpu->exception_addr, 0, true);
 break;
 
 case EXCP_SEMIHOST:
 do_nios2_semihosting(env);
 break;
 
 default:
 cpu_abort(cs, "unhandled exception type=%d\n", cs->exception_index);
 }
 }
diff --git a/target/nios2/translate.c b/target/nios2/translate.c
index e806623594..2cfe77c90a 100644
--- a/target/nios2/translate.c
+++ b/target/nios2/translate.c
@@ -617,64 +617,64 @@ static void rdctl(DisasContext *dc, uint32_t code, 
uint32_t flags)
 /* ctlN <- rA */
 static void wrctl(DisasContext *dc, uint32_t code, uint32_t flags)
 {
 if (!gen_check_supervisor(dc)) {
 return;
 }
 
 #ifdef CONFIG_USER_ON

[RFC PATCH v2 10/78] hw/ide/atapi.c: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/ide/atapi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index dcc39df9a4..85c74a5ffe 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -1189,53 +1189,54 @@ static void cmd_read_disc_information(IDEState *s, 
uint8_t* buf)
 static void cmd_read_dvd_structure(IDEState *s, uint8_t* buf)
 {
 int max_len;
 int media = buf[1];
 int format = buf[7];
 int ret;
 
 max_len = lduw_be_p(buf + 8);
 
 if (format < 0xff) {
 if (media_is_cd(s)) {
 ide_atapi_cmd_error(s, ILLEGAL_REQUEST,
 ASC_INCOMPATIBLE_FORMAT);
 return;
 } else if (!media_present(s)) {
 ide_atapi_cmd_error(s, ILLEGAL_REQUEST,
 ASC_INV_FIELD_IN_CMD_PACKET);
 return;
 }
 }
 
 memset(buf, 0, max_len > IDE_DMA_BUF_SECTORS * BDRV_SECTOR_SIZE + 4 ?
IDE_DMA_BUF_SECTORS * BDRV_SECTOR_SIZE + 4 : max_len);
 
 switch (format) {
 case 0x00 ... 0x7f:
 case 0xff:
 if (media == 0) {
 ret = ide_dvd_read_structure(s, format, buf, buf);
 
 if (ret < 0) {
 ide_atapi_cmd_error(s, ILLEGAL_REQUEST, -ret);
 } else {
 ide_atapi_cmd_reply(s, ret, max_len);
 }
 
 break;
 }
 /* TODO: BD support, fall through for now */
+fallthrough;
 
 /* Generic disk structures */
 case 0x80: /* TODO: AACS volume identifier */
 case 0x81: /* TODO: AACS media serial number */
 case 0x82: /* TODO: AACS media identifier */
 case 0x83: /* TODO: AACS media key block */
 case 0x90: /* TODO: List of recognized format layers */
 case 0xc0: /* TODO: Write protection status */
 default:
 ide_atapi_cmd_error(s, ILLEGAL_REQUEST,
 ASC_INV_FIELD_IN_CMD_PACKET);
 break;
 }
 }
-- 
2.39.2




[RFC PATCH 27/78] target/riscv: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/riscv/insn_trans/trans_rvi.c.inc   |  2 +-
 target/riscv/insn_trans/trans_rvzce.c.inc | 22 +++---
 target/riscv/translate.c  |  4 ++--
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/target/riscv/insn_trans/trans_rvi.c.inc 
b/target/riscv/insn_trans/trans_rvi.c.inc
index 25cb60558a..98dd2e3cf6 100644
--- a/target/riscv/insn_trans/trans_rvi.c.inc
+++ b/target/riscv/insn_trans/trans_rvi.c.inc
@@ -89,61 +89,61 @@ static bool trans_jalr(DisasContext *ctx, arg_jalr *a)
 static TCGCond gen_compare_i128(bool bz, TCGv rl,
 TCGv al, TCGv ah, TCGv bl, TCGv bh,
 TCGCond cond)
 {
 TCGv rh = tcg_temp_new();
 bool invert = false;
 
 switch (cond) {
 case TCG_COND_EQ:
 case TCG_COND_NE:
 if (bz) {
 tcg_gen_or_tl(rl, al, ah);
 } else {
 tcg_gen_xor_tl(rl, al, bl);
 tcg_gen_xor_tl(rh, ah, bh);
 tcg_gen_or_tl(rl, rl, rh);
 }
 break;
 
 case TCG_COND_GE:
 case TCG_COND_LT:
 if (bz) {
 tcg_gen_mov_tl(rl, ah);
 } else {
 TCGv tmp = tcg_temp_new();
 
 tcg_gen_sub2_tl(rl, rh, al, ah, bl, bh);
 tcg_gen_xor_tl(rl, rh, ah);
 tcg_gen_xor_tl(tmp, ah, bh);
 tcg_gen_and_tl(rl, rl, tmp);
 tcg_gen_xor_tl(rl, rh, rl);
 }
 break;
 
 case TCG_COND_LTU:
 invert = true;
-/* fallthrough */
+fallthrough;
 case TCG_COND_GEU:
 {
 TCGv tmp = tcg_temp_new();
 TCGv zero = tcg_constant_tl(0);
 TCGv one = tcg_constant_tl(1);
 
 cond = TCG_COND_NE;
 /* borrow in to second word */
 tcg_gen_setcond_tl(TCG_COND_LTU, tmp, al, bl);
 /* seed third word with 1, which will be result */
 tcg_gen_sub2_tl(tmp, rh, ah, one, tmp, zero);
 tcg_gen_sub2_tl(tmp, rl, tmp, rh, bh, zero);
 }
 break;
 
 default:
 g_assert_not_reached();
 }
 
 if (invert) {
 cond = tcg_invert_cond(cond);
 }
 return cond;
 }
diff --git a/target/riscv/insn_trans/trans_rvzce.c.inc 
b/target/riscv/insn_trans/trans_rvzce.c.inc
index 2d992e14c4..f0bcbb4f72 100644
--- a/target/riscv/insn_trans/trans_rvzce.c.inc
+++ b/target/riscv/insn_trans/trans_rvzce.c.inc
@@ -116,52 +116,52 @@ static bool trans_c_sh(DisasContext *ctx, arg_c_sh *a)
 static uint32_t decode_push_pop_list(DisasContext *ctx, target_ulong rlist)
 {
 uint32_t reg_bitmap = 0;
 
 if (has_ext(ctx, RVE) && rlist > 6) {
 return 0;
 }
 
 switch (rlist) {
 case 15:
 reg_bitmap |=  1 << (X_Sn + 11) ;
 reg_bitmap |=  1 << (X_Sn + 10) ;
-/* FALL THROUGH */
+fallthrough;
 case 14:
 reg_bitmap |=  1 << (X_Sn + 9) ;
-/* FALL THROUGH */
+fallthrough;
 case 13:
 reg_bitmap |=  1 << (X_Sn + 8) ;
-/* FALL THROUGH */
+fallthrough;
 case 12:
 reg_bitmap |=  1 << (X_Sn + 7) ;
-/* FALL THROUGH */
+fallthrough;
 case 11:
 reg_bitmap |=  1 << (X_Sn + 6) ;
-/* FALL THROUGH */
+fallthrough;
 case 10:
 reg_bitmap |=  1 << (X_Sn + 5) ;
-/* FALL THROUGH */
+fallthrough;
 case 9:
 reg_bitmap |=  1 << (X_Sn + 4) ;
-/* FALL THROUGH */
+fallthrough;
 case 8:
 reg_bitmap |=  1 << (X_Sn + 3) ;
-/* FALL THROUGH */
+fallthrough;
 case 7:
 reg_bitmap |=  1 << (X_Sn + 2) ;
-/* FALL THROUGH */
+fallthrough;
 case 6:
 reg_bitmap |=  1 << X_S1 ;
-/* FALL THROUGH */
+fallthrough;
 case 5:
 reg_bitmap |= 1 << X_S0;
-/* FALL THROUGH */
+fallthrough;
 case 4:
 reg_bitmap |= 1 << xRA;
 break;
 default:
 break;
 }
 
 return reg_bitmap;
 }
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
index f0be79bb16..c99e513221 100644
--- a/target/riscv/translate.c
+++ b/target/riscv/translate.c
@@ -431,26 +431,26 @@ static void gen_set_gpr128(DisasContext *ctx, int 
reg_num, TCGv rl, TCGv rh)
 static TCGv_i64 get_fpr_hs(DisasContext *ctx, int reg_num)
 {
 if (!ctx->cfg_ptr->ext_zfinx) {
 return cpu_fpr[reg_num];
 }
 
 if (reg_num == 0) {
 return tcg_constant_i64(0);
 }
 switch (get_xl(ctx)) {
 case MXL_RV32:
 #ifdef TARGET_RISCV32
 {
 TCGv_i64 t = tcg_temp_new_i64();
 tcg_gen_ext_i32_i64(t, cpu_gpr[reg_num]);
 return t;
 }
 #else
-/* fall through */
+fallthrough;
 case MXL_RV64:
 return cpu_gpr[reg_nu

[RFC PATCH v2 59/78] hw/intc: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/intc/apic.c  |  2 +-
 hw/intc/arm_gicv3_kvm.c | 16 
 hw/intc/armv7m_nvic.c   | 12 ++--
 hw/intc/xilinx_intc.c   |  2 +-
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/hw/intc/apic.c b/hw/intc/apic.c
index ac3d47d231..30f341c722 100644
--- a/hw/intc/apic.c
+++ b/hw/intc/apic.c
@@ -172,21 +172,21 @@ static void apic_local_deliver(APICCommonState *s, int 
vector)
 void apic_deliver_pic_intr(DeviceState *dev, int level)
 {
 APICCommonState *s = APIC(dev);
 
 if (level) {
 apic_local_deliver(s, APIC_LVT_LINT0);
 } else {
 uint32_t lvt = s->lvt[APIC_LVT_LINT0];
 
 switch ((lvt >> 8) & 7) {
 case APIC_DM_FIXED:
 if (!(lvt & APIC_LVT_LEVEL_TRIGGER))
 break;
 apic_reset_bit(s->irr, lvt & 0xff);
-/* fall through */
+fallthrough;
 case APIC_DM_EXTINT:
 apic_update_irq(s);
 break;
 }
 }
 }
diff --git a/hw/intc/arm_gicv3_kvm.c b/hw/intc/arm_gicv3_kvm.c
index 72ad916d3d..782cef3390 100644
--- a/hw/intc/arm_gicv3_kvm.c
+++ b/hw/intc/arm_gicv3_kvm.c
@@ -323,186 +323,186 @@ static void kvm_arm_gicv3_check(GICv3State *s)
 static void kvm_arm_gicv3_put(GICv3State *s)
 {
 uint32_t regl, regh, reg;
 uint64_t reg64, redist_typer;
 int ncpu, i;
 
 kvm_arm_gicv3_check(s);
 
 kvm_gicr_access(s, GICR_TYPER, 0, ®l, false);
 kvm_gicr_access(s, GICR_TYPER + 4, 0, ®h, false);
 redist_typer = ((uint64_t)regh << 32) | regl;
 
 reg = s->gicd_ctlr;
 kvm_gicd_access(s, GICD_CTLR, ®, true);
 
 if (redist_typer & GICR_TYPER_PLPIS) {
 /*
  * Restore base addresses before LPIs are potentially enabled by
  * GICR_CTLR write
  */
 for (ncpu = 0; ncpu < s->num_cpu; ncpu++) {
 GICv3CPUState *c = &s->cpu[ncpu];
 
 reg64 = c->gicr_propbaser;
 regl = (uint32_t)reg64;
 kvm_gicr_access(s, GICR_PROPBASER, ncpu, ®l, true);
 regh = (uint32_t)(reg64 >> 32);
 kvm_gicr_access(s, GICR_PROPBASER + 4, ncpu, ®h, true);
 
 reg64 = c->gicr_pendbaser;
 regl = (uint32_t)reg64;
 kvm_gicr_access(s, GICR_PENDBASER, ncpu, ®l, true);
 regh = (uint32_t)(reg64 >> 32);
 kvm_gicr_access(s, GICR_PENDBASER + 4, ncpu, ®h, true);
 }
 }
 
 /* Redistributor state (one per CPU) */
 
 for (ncpu = 0; ncpu < s->num_cpu; ncpu++) {
 GICv3CPUState *c = &s->cpu[ncpu];
 
 reg = c->gicr_ctlr;
 kvm_gicr_access(s, GICR_CTLR, ncpu, ®, true);
 
 reg = c->gicr_statusr[GICV3_NS];
 kvm_gicr_access(s, GICR_STATUSR, ncpu, ®, true);
 
 reg = c->gicr_waker;
 kvm_gicr_access(s, GICR_WAKER, ncpu, ®, true);
 
 reg = c->gicr_igroupr0;
 kvm_gicr_access(s, GICR_IGROUPR0, ncpu, ®, true);
 
 reg = ~0;
 kvm_gicr_access(s, GICR_ICENABLER0, ncpu, ®, true);
 reg = c->gicr_ienabler0;
 kvm_gicr_access(s, GICR_ISENABLER0, ncpu, ®, true);
 
 /* Restore config before pending so we treat level/edge correctly */
 reg = half_shuffle32(c->edge_trigger >> 16) << 1;
 kvm_gicr_access(s, GICR_ICFGR1, ncpu, ®, true);
 
 reg = c->level;
 kvm_gic_line_level_access(s, 0, ncpu, ®, true);
 
 reg = ~0;
 kvm_gicr_access(s, GICR_ICPENDR0, ncpu, ®, true);
 reg = c->gicr_ipendr0;
 kvm_gicr_access(s, GICR_ISPENDR0, ncpu, ®, true);
 
 reg = ~0;
 kvm_gicr_access(s, GICR_ICACTIVER0, ncpu, ®, true);
 reg = c->gicr_iactiver0;
 kvm_gicr_access(s, GICR_ISACTIVER0, ncpu, ®, true);
 
 for (i = 0; i < GIC_INTERNAL; i += 4) {
 reg = c->gicr_ipriorityr[i] |
 (c->gicr_ipriorityr[i + 1] << 8) |
 (c->gicr_ipriorityr[i + 2] << 16) |
 (c->gicr_ipriorityr[i + 3] << 24);
 kvm_gicr_access(s, GICR_IPRIORITYR + i, ncpu, ®, true);
 }
 }
 
 /* Distributor state (shared between all CPUs */
 reg = s->gicd_statusr[GICV3_NS];
 kvm_gicd_access(s, GICD_STATUSR, ®, true);
 
 /* s->enable bitmap -> GICD_ISENABLERn */
 kvm_dist_putbmp(s, GICD_ISENABLER, GICD_ICENABLER, s->enabled);
 
 /* s->group bitmap -> GICD_IGROUPRn */
 kvm_dist_putbmp(s, GICD_IGROUPR, 0, s->group);
 
 /* Restore targets before pending to ensure the pending state is set on
  * the appropriate CPU interfaces in the kernel
  */
 
 /* s->gicd_irouter[irq] -> GICD_IROUTERn
  * We can't use kvm_dist_put() here because the registers are 64-bit
  */
 for (i = GIC_INTERNAL; i < s->num_irq; i++) {
 uint32_t offset;
 
 offset = GICD_IROU

[RFC PATCH v2 75/78] migration: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 migration/migration.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/migration/migration.c b/migration/migration.c
index 585d3c8f55..fdad37efbb 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -2772,38 +2772,38 @@ static MigIterateState 
migration_iteration_run(MigrationState *s)
 static void migration_iteration_finish(MigrationState *s)
 {
 /* If we enabled cpu throttling for auto-converge, turn it off. */
 cpu_throttle_stop();
 
 qemu_mutex_lock_iothread();
 switch (s->state) {
 case MIGRATION_STATUS_COMPLETED:
 migration_calculate_complete(s);
 runstate_set(RUN_STATE_POSTMIGRATE);
 break;
 case MIGRATION_STATUS_COLO:
 assert(migrate_colo());
 migrate_start_colo_process(s);
 s->vm_old_state = RUN_STATE_RUNNING;
-/* Fallthrough */
+fallthrough;
 case MIGRATION_STATUS_FAILED:
 case MIGRATION_STATUS_CANCELLED:
 case MIGRATION_STATUS_CANCELLING:
 if (s->vm_old_state == RUN_STATE_RUNNING) {
 if (!runstate_check(RUN_STATE_SHUTDOWN)) {
 vm_start();
 }
 } else {
 if (runstate_check(RUN_STATE_FINISH_MIGRATE)) {
 runstate_set(s->vm_old_state);
 }
 }
 break;
 
 default:
 /* Should not reach here, but if so, forgive the VM. */
 error_report("%s: Unknown ending state %d", __func__, s->state);
 break;
 }
 migrate_fd_cleanup_schedule(s);
 qemu_mutex_unlock_iothread();
 }
-- 
2.39.2




[RFC PATCH 45/75] disas: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
Signed-off-by: Emmanouil Pitsidianakis 
---
 disas/hppa.c  | 4 ++--
 disas/m68k.c  | 2 +-
 disas/sh4.c   | 4 +++-
 disas/sparc.c | 2 +-
 4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/disas/hppa.c b/disas/hppa.c
index dcf9a47f34..1a2bdb8d39 100644
--- a/disas/hppa.c
+++ b/disas/hppa.c
@@ -1954,878 +1954,878 @@ int
 print_insn_hppa (bfd_vma memaddr, disassemble_info *info)
 {
   bfd_byte buffer[4];
   unsigned int insn, i;
 
   {
 int status =
   (*info->read_memory_func) (memaddr, buffer, sizeof (buffer), info);
 if (status != 0)
   {
(*info->memory_error_func) (status, memaddr, info);
return -1;
   }
   }
 
   insn = bfd_getb32 (buffer);
 
   for (i = 0; i < NUMOPCODES; ++i)
 {
   const struct pa_opcode *opcode = &pa_opcodes[i];
 
   if ((insn & opcode->mask) == opcode->match)
{
  const char *s;
 #ifndef BFD64
  if (opcode->arch == pa20w)
continue;
 #endif
  (*info->fprintf_func) (info->stream, "%s", opcode->name);
 
  if (!strchr ("cfCY?-+nHNZFIuv{", opcode->args[0]))
(*info->fprintf_func) (info->stream, " ");
  for (s = opcode->args; *s != '\0'; ++s)
{
  switch (*s)
{
case 'x':
  fput_reg (GET_FIELD (insn, 11, 15), info);
  break;
case 'a':
case 'b':
  fput_reg (GET_FIELD (insn, 6, 10), info);
  break;
case '^':
  fput_creg (GET_FIELD (insn, 6, 10), info);
  break;
case 't':
  fput_reg (GET_FIELD (insn, 27, 31), info);
  break;
 
  /* Handle floating point registers.  */
case 'f':
  switch (*++s)
{
case 't':
  fput_fp_reg (GET_FIELD (insn, 27, 31), info);
  break;
case 'T':
  if (GET_FIELD (insn, 25, 25))
fput_fp_reg_r (GET_FIELD (insn, 27, 31), info);
  else
fput_fp_reg (GET_FIELD (insn, 27, 31), info);
  break;
case 'a':
  if (GET_FIELD (insn, 25, 25))
fput_fp_reg_r (GET_FIELD (insn, 6, 10), info);
  else
fput_fp_reg (GET_FIELD (insn, 6, 10), info);
  break;
 
  /* 'fA' will not generate a space before the register
 name.  Normally that is fine.  Except that it
 causes problems with xmpyu which has no FP format
 completer.  */
case 'X':
  fputs_filtered (" ", info);
- /* FALLTHRU */
+ fallthrough;
 
case 'A':
  if (GET_FIELD (insn, 24, 24))
fput_fp_reg_r (GET_FIELD (insn, 6, 10), info);
  else
fput_fp_reg (GET_FIELD (insn, 6, 10), info);
  break;
case 'b':
  if (GET_FIELD (insn, 25, 25))
fput_fp_reg_r (GET_FIELD (insn, 11, 15), info);
  else
fput_fp_reg (GET_FIELD (insn, 11, 15), info);
  break;
case 'B':
  if (GET_FIELD (insn, 19, 19))
fput_fp_reg_r (GET_FIELD (insn, 11, 15), info);
  else
fput_fp_reg (GET_FIELD (insn, 11, 15), info);
  break;
case 'C':
  {
int reg = GET_FIELD (insn, 21, 22);
reg |= GET_FIELD (insn, 16, 18) << 2;
if (GET_FIELD (insn, 23, 23) != 0)
  fput_fp_reg_r (reg, info);
else
  fput_fp_reg (reg, info);
break;
  }
case 'i':
  {
int reg = GET_FIELD (insn, 6, 10);
 
reg |= (GET_FIELD (insn, 26, 26) << 4);
fput_fp_reg (reg, info);
break;
  }
case 'j':
  {
int reg = GET_FIELD (insn, 11, 15);
 
reg |= (GET_FIELD (insn, 26, 26) << 4);
fput_fp_reg (reg, info);
break;
  }
case 'k':
  {
int reg = GET_FIELD (insn, 27, 31);
 
reg |= (GET_FIELD (insn, 26, 26) << 4);
   

[RFC PATCH 37/78] target/hexagon: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/hexagon/idef-parser/parser-helpers.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/target/hexagon/idef-parser/parser-helpers.c 
b/target/hexagon/idef-parser/parser-helpers.c
index 4af020933a..0f1713ae4c 100644
--- a/target/hexagon/idef-parser/parser-helpers.c
+++ b/target/hexagon/idef-parser/parser-helpers.c
@@ -1,34 +1,35 @@
 /*
  *  Copyright(c) 2019-2023 rev.ng Labs Srl. All Rights Reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, see .
  */
 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 
 #include "idef-parser.h"
 #include "parser-helpers.h"
 #include "idef-parser.tab.h"
 #include "idef-parser.yy.h"
+#include "qemu/compiler.h"
 
 void yyerror(YYLTYPE *locp,
  yyscan_t scanner __attribute__((unused)),
@@ -621,51 +622,51 @@ static void gen_sub_op(Context *c, YYLTYPE *locp, 
unsigned bit_width,
 static void gen_asl_op(Context *c, YYLTYPE *locp, unsigned bit_width,
bool op_is64bit, const char *bit_suffix,
HexValue *res, enum OpTypes op_types,
HexValue *op1, HexValue *op2)
 {
 HexValue op1_m = *op1;
 HexValue op2_m = *op2;
 switch (op_types) {
 case IMM_IMM: {
 HexSignedness signedness = bin_op_signedness(c, locp,
  op1->signedness,
  op2->signedness);
 gen_c_int_type(c, locp, bit_width, signedness);
 OUT(c, locp, " ", res,
 " = ", op1, " << ", op2, ";\n");
 } break;
 case REG_IMM: {
 OUT(c, locp, "if (", op2, " >= ", &bit_width, ") {\n");
 OUT(c, locp, "tcg_gen_movi_", bit_suffix, "(", res, ", 0);\n");
 OUT(c, locp, "} else {\n");
 OUT(c, locp, "tcg_gen_shli_", bit_suffix,
 "(", res, ", ", op1, ", ", op2, ");\n");
 OUT(c, locp, "}\n");
 } break;
 case IMM_REG:
 op1_m.bit_width = bit_width;
 op1_m = rvalue_materialize(c, locp, &op1_m);
-/* fallthrough */
+fallthrough;
 case REG_REG: {
 OUT(c, locp, "tcg_gen_shl_", bit_suffix,
 "(", res, ", ", &op1_m, ", ", op2, ");\n");
 } break;
 }
 if (op_types == IMM_REG || op_types == REG_REG) {
 /*
  * Handle left shift by 64/32 which hexagon-sim expects to clear out
  * register
  */
 HexValue zero = gen_constant(c, locp, "0", bit_width, UNSIGNED);
 HexValue edge = gen_imm_value(c, locp, bit_width, bit_width, UNSIGNED);
 edge = rvalue_materialize(c, locp, &edge);
 if (op_is64bit) {
 op2_m = gen_rvalue_extend(c, locp, &op2_m);
 }
 op1_m = rvalue_materialize(c, locp, &op1_m);
 op2_m = rvalue_materialize(c, locp, &op2_m);
 OUT(c, locp, "tcg_gen_movcond_i", &bit_width);
 OUT(c, locp, "(TCG_COND_GEU, ", res, ", ", &op2_m, ", ", &edge);
 OUT(c, locp, ", ", &zero, ", ", res, ");\n");
 }
 }
@@ -800,41 +801,41 @@ static void gen_andl_op(Context *c, YYLTYPE *locp, 
unsigned bit_width,
 static void gen_minmax_op(Context *c, YYLTYPE *locp, unsigned bit_width,
   HexValue *res, enum OpTypes op_types,
   HexValue *op1, HexValue *op2, bool minmax)
 {
 const char *mm;
 HexValue op1_m = *op1;
 HexValue op2_m = *op2;
 bool is_unsigned;
 
 assert_signedness(c, locp, res->signedness);
 is_unsigned = res->signedness == UNSIGNED;
 
 if (minmax) {
 /* Max */
 mm = is_unsigned ? "tcg_gen_umax" : "tcg_gen_smax";
 } else {
 /* Min */
 mm = is_unsigned ? "tcg_gen_umin" : "tcg_gen_smin";
 }
 switch (op_types) {
 case IMM_IMM:
 yyassert(c, locp, false, "MINMAX between IMM op IMM, not handled!");
 break;
 case IMM_REG:
 op1_m.bit_width = bit_width;
 op1_m = rvalue_materialize(c, locp, &op1_m);
 OUT(c, locp, mm, "_i", &bit_width, "(");
 OUT(c, locp, res, ", ", &op1_m, ", ", op2, ");\n");
 break;
 case REG_IMM:
 op2_m.bit_width = 

[RFC PATCH 50/75] chardev: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
Signed-off-by: Emmanouil Pitsidianakis 
---
 chardev/char-socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 73947da188..1562e066a4 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -549,34 +549,34 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t 
*buf, int len)
 static char *qemu_chr_compute_filename(SocketChardev *s)
 {
 struct sockaddr_storage *ss = &s->sioc->localAddr;
 struct sockaddr_storage *ps = &s->sioc->remoteAddr;
 socklen_t ss_len = s->sioc->localAddrLen;
 socklen_t ps_len = s->sioc->remoteAddrLen;
 char shost[NI_MAXHOST], sserv[NI_MAXSERV];
 char phost[NI_MAXHOST], pserv[NI_MAXSERV];
 const char *left = "", *right = "";
 
 switch (ss->ss_family) {
 case AF_UNIX:
 return g_strdup_printf("unix:%s%s",
((struct sockaddr_un *)(ss))->sun_path,
s->is_listen ? ",server=on" : "");
 case AF_INET6:
 left  = "[";
 right = "]";
-/* fall through */
+fallthrough;
 case AF_INET:
 getnameinfo((struct sockaddr *) ss, ss_len, shost, sizeof(shost),
 sserv, sizeof(sserv), NI_NUMERICHOST | NI_NUMERICSERV);
 getnameinfo((struct sockaddr *) ps, ps_len, phost, sizeof(phost),
 pserv, sizeof(pserv), NI_NUMERICHOST | NI_NUMERICSERV);
 return g_strdup_printf("%s:%s%s%s:%s%s <-> %s%s%s:%s",
qemu_chr_socket_protocol(s),
left, shost, right, sserv,
s->is_listen ? ",server=on" : "",
left, phost, right, pserv);
 
 default:
 return g_strdup_printf("unknown");
 }
 }
-- 
2.39.2




[RFC PATCH 38/78] system/rtc.c: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 system/rtc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/system/rtc.c b/system/rtc.c
index 4904581abe..bb406542c8 100644
--- a/system/rtc.c
+++ b/system/rtc.c
@@ -48,22 +48,22 @@ QEMUClockType rtc_clock;
 /***/
 /* RTC reference time/date access */
 static time_t qemu_ref_timedate(QEMUClockType clock)
 {
 time_t value = qemu_clock_get_ms(clock) / 1000;
 switch (clock) {
 case QEMU_CLOCK_REALTIME:
 value -= rtc_realtime_clock_offset;
-/* fall through */
+fallthrough;
 case QEMU_CLOCK_VIRTUAL:
 value += rtc_ref_start_datetime;
 break;
 case QEMU_CLOCK_HOST:
 if (rtc_base_type == RTC_BASE_DATETIME) {
 value -= rtc_host_datetime_offset;
 }
 break;
 default:
 assert(0);
 }
 return value;
 }
-- 
2.39.2




[RFC PATCH v2 65/78] hw/nvme: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/nvme/ctrl.c | 24 
 hw/nvme/dif.c  |  4 ++--
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index f026245d1e..acb2012fb9 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -1912,29 +1912,29 @@ static uint16_t nvme_check_zone_read(NvmeNamespace *ns, 
uint64_t slba,
 static uint16_t nvme_zrm_finish(NvmeNamespace *ns, NvmeZone *zone)
 {
 switch (nvme_get_zone_state(zone)) {
 case NVME_ZONE_STATE_FULL:
 return NVME_SUCCESS;
 
 case NVME_ZONE_STATE_IMPLICITLY_OPEN:
 case NVME_ZONE_STATE_EXPLICITLY_OPEN:
 nvme_aor_dec_open(ns);
-/* fallthrough */
+fallthrough;
 case NVME_ZONE_STATE_CLOSED:
 nvme_aor_dec_active(ns);
 
 if (zone->d.za & NVME_ZA_ZRWA_VALID) {
 zone->d.za &= ~NVME_ZA_ZRWA_VALID;
 if (ns->params.numzrwa) {
 ns->zns.numzrwa++;
 }
 }
 
-/* fallthrough */
+fallthrough;
 case NVME_ZONE_STATE_EMPTY:
 nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_FULL);
 return NVME_SUCCESS;
 
 default:
 return NVME_ZONE_INVAL_TRANSITION;
 }
 }
@@ -1942,15 +1942,15 @@ static uint16_t nvme_zrm_finish(NvmeNamespace *ns, 
NvmeZone *zone)
 static uint16_t nvme_zrm_close(NvmeNamespace *ns, NvmeZone *zone)
 {
 switch (nvme_get_zone_state(zone)) {
 case NVME_ZONE_STATE_EXPLICITLY_OPEN:
 case NVME_ZONE_STATE_IMPLICITLY_OPEN:
 nvme_aor_dec_open(ns);
 nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_CLOSED);
-/* fall through */
+fallthrough;
 case NVME_ZONE_STATE_CLOSED:
 return NVME_SUCCESS;
 
 default:
 return NVME_ZONE_INVAL_TRANSITION;
 }
 }
@@ -1958,29 +1958,29 @@ static uint16_t nvme_zrm_close(NvmeNamespace *ns, 
NvmeZone *zone)
 static uint16_t nvme_zrm_reset(NvmeNamespace *ns, NvmeZone *zone)
 {
 switch (nvme_get_zone_state(zone)) {
 case NVME_ZONE_STATE_EXPLICITLY_OPEN:
 case NVME_ZONE_STATE_IMPLICITLY_OPEN:
 nvme_aor_dec_open(ns);
-/* fallthrough */
+fallthrough;
 case NVME_ZONE_STATE_CLOSED:
 nvme_aor_dec_active(ns);
 
 if (zone->d.za & NVME_ZA_ZRWA_VALID) {
 if (ns->params.numzrwa) {
 ns->zns.numzrwa++;
 }
 }
 
-/* fallthrough */
+fallthrough;
 case NVME_ZONE_STATE_FULL:
 zone->w_ptr = zone->d.zslba;
 zone->d.wp = zone->w_ptr;
 nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_EMPTY);
-/* fallthrough */
+fallthrough;
 case NVME_ZONE_STATE_EMPTY:
 return NVME_SUCCESS;
 
 default:
 return NVME_ZONE_INVAL_TRANSITION;
 }
 }
@@ -2010,57 +2010,57 @@ enum {
 static uint16_t nvme_zrm_open_flags(NvmeCtrl *n, NvmeNamespace *ns,
 NvmeZone *zone, int flags)
 {
 int act = 0;
 uint16_t status;
 
 switch (nvme_get_zone_state(zone)) {
 case NVME_ZONE_STATE_EMPTY:
 act = 1;
 
-/* fallthrough */
+fallthrough;
 
 case NVME_ZONE_STATE_CLOSED:
 if (n->params.auto_transition_zones) {
 nvme_zrm_auto_transition_zone(ns);
 }
 status = nvme_zns_check_resources(ns, act, 1,
   (flags & NVME_ZRM_ZRWA) ? 1 : 0);
 if (status) {
 return status;
 }
 
 if (act) {
 nvme_aor_inc_active(ns);
 }
 
 nvme_aor_inc_open(ns);
 
 if (flags & NVME_ZRM_AUTO) {
 nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_IMPLICITLY_OPEN);
 return NVME_SUCCESS;
 }
 
-/* fallthrough */
+fallthrough;
 
 case NVME_ZONE_STATE_IMPLICITLY_OPEN:
 if (flags & NVME_ZRM_AUTO) {
 return NVME_SUCCESS;
 }
 
 nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_EXPLICITLY_OPEN);
 
-/* fallthrough */
+fallthrough;
 
 case NVME_ZONE_STATE_EXPLICITLY_OPEN:
 if (flags & NVME_ZRM_ZRWA) {
 ns->zns.numzrwa--;
 
 zone->d.za |= NVME_ZA_ZRWA_VALID;
 }
 
 return NVME_SUCCESS;
 
 default:
 return NVME_ZONE_INVAL_TRANSITION;
 }
 }
@@ -3508,135 +3508,135 @@ static void nvme_do_write_fdp(NvmeCtrl *n, 
NvmeRequest *req, uint64_t slba,
 static uint16_t nvme_do_write(NvmeCtrl *n, NvmeRequest *req, bool append,
   bool wrz)
 {
 NvmeRwCmd *rw = (NvmeRwCmd *)&req->cmd;
 NvmeNamespace *ns = req->ns;
 uint64_t slba = le64_to_cpu(rw->slba);
 uint32_t nlb = (uint32_t)le16_to_cpu(rw->nlb) + 1;
 uint16_t ctrl = le16_to_cpu(rw->control);
 uint8_t prinfo = NVME_RW_PRINFO(ctrl);
 uint64

[RFC PATCH 52/78] hw/char: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/char/nrf51_uart.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/char/nrf51_uart.c b/hw/char/nrf51_uart.c
index dfe2276d71..3e2b35c7ad 100644
--- a/hw/char/nrf51_uart.c
+++ b/hw/char/nrf51_uart.c
@@ -113,79 +113,79 @@ static void uart_cancel_transmit(NRF51UARTState *s)
 static void uart_write(void *opaque, hwaddr addr,
uint64_t value, unsigned int size)
 {
 NRF51UARTState *s = NRF51_UART(opaque);
 
 trace_nrf51_uart_write(addr, value, size);
 
 if (!s->enabled && (addr != A_UART_ENABLE)) {
 return;
 }
 
 switch (addr) {
 case A_UART_TXD:
 if (!s->pending_tx_byte && s->tx_started) {
 s->reg[R_UART_TXD] = value;
 s->pending_tx_byte = true;
 uart_transmit(NULL, G_IO_OUT, s);
 }
 break;
 case A_UART_INTEN:
 s->reg[R_UART_INTEN] = value;
 break;
 case A_UART_INTENSET:
 s->reg[R_UART_INTEN] |= value;
 break;
 case A_UART_INTENCLR:
 s->reg[R_UART_INTEN] &= ~value;
 break;
 case A_UART_TXDRDY ... A_UART_RXTO:
 s->reg[addr / 4] = value;
 break;
 case A_UART_ERRORSRC:
 s->reg[addr / 4] &= ~value;
 break;
 case A_UART_RXD:
 break;
 case A_UART_RXDRDY:
 if (value == 0) {
 s->reg[R_UART_RXDRDY] = 0;
 }
 break;
 case A_UART_STARTTX:
 if (value == 1) {
 s->tx_started = true;
 }
 break;
 case A_UART_STARTRX:
 if (value == 1) {
 s->rx_started = true;
 }
 break;
 case A_UART_ENABLE:
 if (value) {
 if (value == 4) {
 s->enabled = true;
 }
 break;
 }
 s->enabled = false;
 value = 1;
-/* fall through */
+fallthrough;
 case A_UART_SUSPEND:
 case A_UART_STOPTX:
 if (value == 1) {
 s->tx_started = false;
 }
-/* fall through */
+fallthrough;
 case A_UART_STOPRX:
 if (addr != A_UART_STOPTX && value == 1) {
 s->rx_started = false;
 s->reg[R_UART_RXTO] = 1;
 }
 break;
 default:
 s->reg[addr / 4] = value;
 break;
 }
 nrf51_uart_update_irq(s);
 }
-- 
2.39.2




[RFC PATCH v2 16/78] audio: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 audio/audio.c | 16 
 audio/jackaudio.c |  4 ++--
 audio/pwaudio.c   |  4 ++--
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/audio/audio.c b/audio/audio.c
index e9815d6812..ed7c795af7 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -245,39 +245,39 @@ static int audio_validate_settings (struct audsettings 
*as)
 static int audio_pcm_info_eq (struct audio_pcm_info *info, struct audsettings 
*as)
 {
 int bits = 8;
 bool is_signed = false, is_float = false;
 
 switch (as->fmt) {
 case AUDIO_FORMAT_S8:
 is_signed = true;
-/* fall through */
+fallthrough;
 case AUDIO_FORMAT_U8:
 break;
 
 case AUDIO_FORMAT_S16:
 is_signed = true;
-/* fall through */
+fallthrough;
 case AUDIO_FORMAT_U16:
 bits = 16;
 break;
 
 case AUDIO_FORMAT_F32:
 is_float = true;
-/* fall through */
+fallthrough;
 case AUDIO_FORMAT_S32:
 is_signed = true;
-/* fall through */
+fallthrough;
 case AUDIO_FORMAT_U32:
 bits = 32;
 break;
 
 default:
 abort();
 }
 return info->freq == as->freq
 && info->nchannels == as->nchannels
 && info->is_signed == is_signed
 && info->is_float == is_float
 && info->bits == bits
 && info->swap_endianness == (as->endianness != AUDIO_HOST_ENDIANNESS);
 }
@@ -285,45 +285,45 @@ static int audio_pcm_info_eq (struct audio_pcm_info 
*info, struct audsettings *a
 void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as)
 {
 int bits = 8, mul;
 bool is_signed = false, is_float = false;
 
 switch (as->fmt) {
 case AUDIO_FORMAT_S8:
 is_signed = true;
-/* fall through */
+fallthrough;
 case AUDIO_FORMAT_U8:
 mul = 1;
 break;
 
 case AUDIO_FORMAT_S16:
 is_signed = true;
-/* fall through */
+fallthrough;
 case AUDIO_FORMAT_U16:
 bits = 16;
 mul = 2;
 break;
 
 case AUDIO_FORMAT_F32:
 is_float = true;
-/* fall through */
+fallthrough;
 case AUDIO_FORMAT_S32:
 is_signed = true;
-/* fall through */
+fallthrough;
 case AUDIO_FORMAT_U32:
 bits = 32;
 mul = 4;
 break;
 
 default:
 abort();
 }
 
 info->freq = as->freq;
 info->bits = bits;
 info->is_signed = is_signed;
 info->is_float = is_float;
 info->nchannels = as->nchannels;
 info->bytes_per_frame = as->nchannels * mul;
 info->bytes_per_second = info->freq * info->bytes_per_frame;
 info->swap_endianness = (as->endianness != AUDIO_HOST_ENDIANNESS);
 }
diff --git a/audio/jackaudio.c b/audio/jackaudio.c
index 974a3caad3..fc602411cd 100644
--- a/audio/jackaudio.c
+++ b/audio/jackaudio.c
@@ -574,22 +574,22 @@ static int qjack_init_in(HWVoiceIn *hw, struct 
audsettings *as,
 static void qjack_client_fini_locked(QJackClient *c)
 {
 switch (c->state) {
 case QJACK_STATE_RUNNING:
 jack_deactivate(c->client);
-/* fallthrough */
+fallthrough;
 
 case QJACK_STATE_SHUTDOWN:
 jack_client_close(c->client);
 c->client = NULL;
 
 qjack_buffer_free(&c->fifo);
 g_free(c->port);
 g_free(c->process_buffers);
 
 c->state = QJACK_STATE_DISCONNECTED;
-/* fallthrough */
+fallthrough;
 
 case QJACK_STATE_DISCONNECTED:
 break;
 }
 }
diff --git a/audio/pwaudio.c b/audio/pwaudio.c
index bf26fadb06..89b31617a6 100644
--- a/audio/pwaudio.c
+++ b/audio/pwaudio.c
@@ -487,31 +487,31 @@ static void
 qpw_set_position(uint32_t channels, uint32_t position[SPA_AUDIO_MAX_CHANNELS])
 {
 memcpy(position, (uint32_t[SPA_AUDIO_MAX_CHANNELS]) { 
SPA_AUDIO_CHANNEL_UNKNOWN, },
sizeof(uint32_t) * SPA_AUDIO_MAX_CHANNELS);
 /*
  * TODO: This currently expects the only frontend supporting more than 2
  * channels is the usb-audio.  We will need some means to set channel
  * order when a new frontend gains multi-channel support.
  */
 switch (channels) {
 case 8:
 position[6] = SPA_AUDIO_CHANNEL_SL;
 position[7] = SPA_AUDIO_CHANNEL_SR;
-/* fallthrough */
+fallthrough;
 case 6:
 position[2] = SPA_AUDIO_CHANNEL_FC;
 position[3] = SPA_AUDIO_CHANNEL_LFE;
 position[4] = SPA_AUDIO_CHANNEL_RL;
 position[5] = SPA_AUDIO_CHANNEL_RR;
-/* fallthrough */
+fallthrough;
 case 2:
 position[0] = SPA_AUDIO_CHANNEL_FL;
 position[1] = SPA_AUDIO_CHANNEL_FR;
 break;
 case 1:
 position[0] = SPA_AUDIO_CHANNEL_MONO;
 break;
 default:
 dolog("In

[RFC PATCH v2 15/78] accel/tcg: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 accel/tcg/cputlb.c | 4 ++--
 accel/tcg/ldst_atomicity.c.inc | 2 +-
 accel/tcg/plugin-gen.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c
index b8c5e345b8..92b7ab529a 100644
--- a/accel/tcg/cputlb.c
+++ b/accel/tcg/cputlb.c
@@ -2209,53 +2209,53 @@ static Int128 do_ld_whole_be16(CPUState *cpu, uintptr_t 
ra,
 /*
  * Wrapper for the above.
  */
 static uint64_t do_ld_beN(CPUState *cpu, MMULookupPageData *p,
   uint64_t ret_be, int mmu_idx, MMUAccessType type,
   MemOp mop, uintptr_t ra)
 {
 MemOp atom;
 unsigned tmp, half_size;
 
 if (unlikely(p->flags & TLB_MMIO)) {
 return do_ld_mmio_beN(cpu, p->full, ret_be, p->addr, p->size,
   mmu_idx, type, ra);
 }
 
 /*
  * It is a given that we cross a page and therefore there is no
  * atomicity for the load as a whole, but subobjects may need attention.
  */
 atom = mop & MO_ATOM_MASK;
 switch (atom) {
 case MO_ATOM_SUBALIGN:
 return do_ld_parts_beN(p, ret_be);
 
 case MO_ATOM_IFALIGN_PAIR:
 case MO_ATOM_WITHIN16_PAIR:
 tmp = mop & MO_SIZE;
 tmp = tmp ? tmp - 1 : 0;
 half_size = 1 << tmp;
 if (atom == MO_ATOM_IFALIGN_PAIR
 ? p->size == half_size
 : p->size >= half_size) {
 if (!HAVE_al8_fast && p->size < 4) {
 return do_ld_whole_be4(p, ret_be);
 } else {
 return do_ld_whole_be8(cpu, ra, p, ret_be);
 }
 }
-/* fall through */
+fallthrough;
 
 case MO_ATOM_IFALIGN:
 case MO_ATOM_WITHIN16:
 case MO_ATOM_NONE:
 return do_ld_bytes_beN(p, ret_be);
 
 default:
 g_assert_not_reached();
 }
 }
 
 /*
  * Wrapper for the above, for 8 < size < 16.
  */
@@ -2625,57 +2625,57 @@ static uint64_t do_st16_mmio_leN(CPUState *cpu, 
CPUTLBEntryFull *full,
 /*
  * Wrapper for the above.
  */
 static uint64_t do_st_leN(CPUState *cpu, MMULookupPageData *p,
   uint64_t val_le, int mmu_idx,
   MemOp mop, uintptr_t ra)
 {
 MemOp atom;
 unsigned tmp, half_size;
 
 if (unlikely(p->flags & TLB_MMIO)) {
 return do_st_mmio_leN(cpu, p->full, val_le, p->addr,
   p->size, mmu_idx, ra);
 } else if (unlikely(p->flags & TLB_DISCARD_WRITE)) {
 return val_le >> (p->size * 8);
 }
 
 /*
  * It is a given that we cross a page and therefore there is no atomicity
  * for the store as a whole, but subobjects may need attention.
  */
 atom = mop & MO_ATOM_MASK;
 switch (atom) {
 case MO_ATOM_SUBALIGN:
 return store_parts_leN(p->haddr, p->size, val_le);
 
 case MO_ATOM_IFALIGN_PAIR:
 case MO_ATOM_WITHIN16_PAIR:
 tmp = mop & MO_SIZE;
 tmp = tmp ? tmp - 1 : 0;
 half_size = 1 << tmp;
 if (atom == MO_ATOM_IFALIGN_PAIR
 ? p->size == half_size
 : p->size >= half_size) {
 if (!HAVE_al8_fast && p->size <= 4) {
 return store_whole_le4(p->haddr, p->size, val_le);
 } else if (HAVE_al8) {
 return store_whole_le8(p->haddr, p->size, val_le);
 } else {
 cpu_loop_exit_atomic(cpu, ra);
 }
 }
-/* fall through */
+fallthrough;
 
 case MO_ATOM_IFALIGN:
 case MO_ATOM_WITHIN16:
 case MO_ATOM_NONE:
 return store_bytes_leN(p->haddr, p->size, val_le);
 
 default:
 g_assert_not_reached();
 }
 }
 
 /*
  * Wrapper for the above, for 8 < size < 16.
  */
diff --git a/accel/tcg/ldst_atomicity.c.inc b/accel/tcg/ldst_atomicity.c.inc
index 1cf5b92166..3752f74214 100644
--- a/accel/tcg/ldst_atomicity.c.inc
+++ b/accel/tcg/ldst_atomicity.c.inc
@@ -22,86 +22,86 @@
 /**
  * required_atomicity:
  *
  * Return the lg2 bytes of atomicity required by @memop for @p.
  * If the operation must be split into two operations to be
  * examined separately for atomicity, return -lg2.
  */
 static int required_atomicity(CPUState *cpu, uintptr_t p, MemOp memop)
 {
 MemOp atom = memop & MO_ATOM_MASK;
 MemOp size = memop & MO_SIZE;
 MemOp half = size ? size - 1 : 0;
 unsigned tmp;
 int atmax;
 
 switch (atom) {
 case MO_ATOM_NONE:
 atmax = MO_8;
 break;
 
 case MO_ATOM_IFALIGN_PAIR:
 size = half;
-/* fall through */
+fallthrough;
 
 case MO_ATOM_IFALIGN:
 tmp = (1 << size) - 1;
 atmax = p & tmp ? MO_8 : size;
 break;
 
 case MO_ATOM_WITHIN16:
 tmp = p & 15;
 atmax = (tmp + (1 << size) <= 16 ? size : MO_8);

[RFC PATCH 55/75] hw/input: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/input/hid.c | 3 ++-
 hw/input/tsc2005.c | 4 ++--
 hw/input/tsc210x.c | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/hw/input/hid.c b/hw/input/hid.c
index a9c7dd1ce1..15fffc5dfb 100644
--- a/hw/input/hid.c
+++ b/hw/input/hid.c
@@ -250,88 +250,89 @@ static void hid_keyboard_event(DeviceState *dev, 
QemuConsole *src,
 static void hid_keyboard_process_keycode(HIDState *hs)
 {
 uint8_t hid_code, index, key;
 int i, keycode, slot;
 
 if (hs->n == 0) {
 return;
 }
 slot = hs->head & QUEUE_MASK; QUEUE_INCR(hs->head); hs->n--;
 keycode = hs->kbd.keycodes[slot];
 
 if (!hs->n) {
 trace_hid_kbd_queue_empty();
 }
 
 key = keycode & 0x7f;
 index = key | ((hs->kbd.modifiers & (1 << 8)) >> 1);
 hid_code = hid_usage_keys[index];
 hs->kbd.modifiers &= ~(1 << 8);
 
 switch (hid_code) {
 case 0x00:
 return;
 
 case 0xe0:
 assert(key == 0x1d);
 if (hs->kbd.modifiers & (1 << 9)) {
 /* The hid_codes for the 0xe1/0x1d scancode sequence are 0xe9/0xe0.
  * Here we're processing the second hid_code.  By dropping bit 9
  * and setting bit 8, the scancode after 0x1d will access the
  * second half of the table.
  */
 hs->kbd.modifiers ^= (1 << 8) | (1 << 9);
 return;
 }
 /* fall through to process Ctrl_L */
+fallthrough;
 case 0xe1 ... 0xe7:
 /* Ctrl_L/Ctrl_R, Shift_L/Shift_R, Alt_L/Alt_R, Win_L/Win_R.
  * Handle releases here, or fall through to process presses.
  */
 if (keycode & (1 << 7)) {
 hs->kbd.modifiers &= ~(1 << (hid_code & 0x0f));
 return;
 }
-/* fall through */
+fallthrough;
 case 0xe8 ... 0xe9:
 /* USB modifiers are just 1 byte long.  Bits 8 and 9 of
  * hs->kbd.modifiers implement a state machine that detects the
  * 0xe0 and 0xe1/0x1d sequences.  These bits do not follow the
  * usual rules where bit 7 marks released keys; they are cleared
  * elsewhere in the function as the state machine dictates.
  */
 hs->kbd.modifiers |= 1 << (hid_code & 0x0f);
 return;
 
 case 0xea ... 0xef:
 abort();
 
 default:
 break;
 }
 
 if (keycode & (1 << 7)) {
 for (i = hs->kbd.keys - 1; i >= 0; i--) {
 if (hs->kbd.key[i] == hid_code) {
 hs->kbd.key[i] = hs->kbd.key[-- hs->kbd.keys];
 hs->kbd.key[hs->kbd.keys] = 0x00;
 break;
 }
 }
 if (i < 0) {
 return;
 }
 } else {
 for (i = hs->kbd.keys - 1; i >= 0; i--) {
 if (hs->kbd.key[i] == hid_code) {
 break;
 }
 }
 if (i < 0) {
 if (hs->kbd.keys < sizeof(hs->kbd.key)) {
 hs->kbd.key[hs->kbd.keys++] = hid_code;
 }
 } else {
 return;
 }
 }
 }
diff --git a/hw/input/tsc2005.c b/hw/input/tsc2005.c
index db2b80e35f..4f3f1d9d12 100644
--- a/hw/input/tsc2005.c
+++ b/hw/input/tsc2005.c
@@ -234,70 +234,70 @@ static void tsc2005_write(TSC2005State *s, int reg, 
uint16_t data)
 /* This handles most of the chip's logic.  */
 static void tsc2005_pin_update(TSC2005State *s)
 {
 int64_t expires;
 bool pin_state;
 
 switch (s->pin_func) {
 case 0:
 pin_state = !s->pressure && !!s->dav;
 break;
 case 1:
 case 3:
 default:
 pin_state = !s->dav;
 break;
 case 2:
 pin_state = !s->pressure;
 }
 
 if (pin_state != s->irq) {
 s->irq = pin_state;
 qemu_set_irq(s->pint, s->irq);
 }
 
 switch (s->nextfunction) {
 case TSC_MODE_XYZ_SCAN:
 case TSC_MODE_XY_SCAN:
 if (!s->host_mode && s->dav)
 s->enabled = false;
 if (!s->pressure)
 return;
-/* Fall through */
+fallthrough;
 case TSC_MODE_AUX_SCAN:
 break;
 
 case TSC_MODE_X:
 case TSC_MODE_Y:
 case TSC_MODE_Z:
 if (!s->pressure)
 return;
-/* Fall through */
+fallthrough;
 case TSC_MODE_AUX:
 case TSC_MODE_TEMP1:
 case TSC_MODE_TEMP2:
 case TSC_MODE_X_TEST:
 case TSC_MODE_Y_TEST:
 case TSC_MODE_TS_TEST:
 if (s->dav)
 s->enabled = false;
 break;
 
 case TSC_MODE_RESERVED:
 case TSC_MODE_XX_DRV:
 case TSC_MODE_YY_DRV:
 case TSC_MODE_YX_DRV:
 default:
 return;
 }
 
 if (!s->enabled || s->busy)
 return;
 
 s->busy = true;
 s->precision = s->nextprecision;
 s->function = s->nextfunction;
 s->pdst = !s->pnd0;/* Synchronised on internal clock */
 expires = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
 (NANOSECONDS_PER_SEC

[RFC PATCH v2 57/78] hw/net: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/net/cadence_gem.c | 4 ++--
 hw/net/can/can_sja1000.c | 4 ++--
 hw/net/igb_core.c| 2 +-
 hw/net/igbvf.c   | 2 +-
 hw/net/imx_fec.c | 2 +-
 hw/net/net_rx_pkt.c  | 2 +-
 hw/net/pcnet.c   | 2 +-
 hw/net/rtl8139.c | 6 --
 hw/net/xilinx_ethlite.c  | 2 +-
 9 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
index f445d8bb5e..a59991af5b 100644
--- a/hw/net/cadence_gem.c
+++ b/hw/net/cadence_gem.c
@@ -748,119 +748,119 @@ static int gem_mac_address_filter(CadenceGEMState *s, 
const uint8_t *packet)
 /* Figure out which queue the received data should be sent to */
 static int get_queue_from_screen(CadenceGEMState *s, uint8_t *rxbuf_ptr,
  unsigned rxbufsize)
 {
 uint32_t reg;
 bool matched, mismatched;
 int i, j;
 
 for (i = 0; i < s->num_type1_screeners; i++) {
 reg = s->regs[GEM_SCREENING_TYPE1_REGISTER_0 + i];
 matched = false;
 mismatched = false;
 
 /* Screening is based on UDP Port */
 if (reg & GEM_ST1R_UDP_PORT_MATCH_ENABLE) {
 uint16_t udp_port = rxbuf_ptr[14 + 22] << 8 | rxbuf_ptr[14 + 23];
 if (udp_port == extract32(reg, GEM_ST1R_UDP_PORT_MATCH_SHIFT,
GEM_ST1R_UDP_PORT_MATCH_WIDTH)) {
 matched = true;
 } else {
 mismatched = true;
 }
 }
 
 /* Screening is based on DS/TC */
 if (reg & GEM_ST1R_DSTC_ENABLE) {
 uint8_t dscp = rxbuf_ptr[14 + 1];
 if (dscp == extract32(reg, GEM_ST1R_DSTC_MATCH_SHIFT,
GEM_ST1R_DSTC_MATCH_WIDTH)) {
 matched = true;
 } else {
 mismatched = true;
 }
 }
 
 if (matched && !mismatched) {
 return extract32(reg, GEM_ST1R_QUEUE_SHIFT, GEM_ST1R_QUEUE_WIDTH);
 }
 }
 
 for (i = 0; i < s->num_type2_screeners; i++) {
 reg = s->regs[GEM_SCREENING_TYPE2_REGISTER_0 + i];
 matched = false;
 mismatched = false;
 
 if (reg & GEM_ST2R_ETHERTYPE_ENABLE) {
 uint16_t type = rxbuf_ptr[12] << 8 | rxbuf_ptr[13];
 int et_idx = extract32(reg, GEM_ST2R_ETHERTYPE_INDEX_SHIFT,
 GEM_ST2R_ETHERTYPE_INDEX_WIDTH);
 
 if (et_idx > s->num_type2_screeners) {
 qemu_log_mask(LOG_GUEST_ERROR, "Out of range ethertype "
   "register index: %d\n", et_idx);
 }
 if (type == s->regs[GEM_SCREENING_TYPE2_ETHERTYPE_REG_0 +
 et_idx]) {
 matched = true;
 } else {
 mismatched = true;
 }
 }
 
 /* Compare A, B, C */
 for (j = 0; j < 3; j++) {
 uint32_t cr0, cr1, mask;
 uint16_t rx_cmp;
 int offset;
 int cr_idx = extract32(reg, GEM_ST2R_COMPARE_A_SHIFT + j * 6,
 GEM_ST2R_COMPARE_WIDTH);
 
 if (!(reg & (GEM_ST2R_COMPARE_A_ENABLE << (j * 6 {
 continue;
 }
 if (cr_idx > s->num_type2_screeners) {
 qemu_log_mask(LOG_GUEST_ERROR, "Out of range compare "
   "register index: %d\n", cr_idx);
 }
 
 cr0 = s->regs[GEM_TYPE2_COMPARE_0_WORD_0 + cr_idx * 2];
 cr1 = s->regs[GEM_TYPE2_COMPARE_0_WORD_0 + cr_idx * 2 + 1];
 offset = extract32(cr1, GEM_T2CW1_OFFSET_VALUE_SHIFT,
 GEM_T2CW1_OFFSET_VALUE_WIDTH);
 
 switch (extract32(cr1, GEM_T2CW1_COMPARE_OFFSET_SHIFT,
GEM_T2CW1_COMPARE_OFFSET_WIDTH)) {
 case 3: /* Skip UDP header */
 qemu_log_mask(LOG_UNIMP, "TCP compare offsets"
   "unimplemented - assuming UDP\n");
 offset += 8;
-/* Fallthrough */
+fallthrough;
 case 2: /* skip the IP header */
 offset += 20;
-/* Fallthrough */
+fallthrough;
 case 1: /* Count from after the ethertype */
 offset += 14;
 break;
 case 0:
 /* Offset from start of frame */
 break;
 }
 
 rx_cmp = rxbuf_ptr[offset] << 8 | rxbuf_ptr[offset];
 mask = extract32(cr0, 0, 16);
 
 if ((rx_cmp & mask) == (extract32(cr0, 16, 16) & mask)) {
 matched = true;
 } else {
 mismat

[RFC PATCH 43/75] hw/m68k/mcf_intc.c: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/m68k/mcf_intc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/m68k/mcf_intc.c b/hw/m68k/mcf_intc.c
index 4cd30188c0..9556a0ccb7 100644
--- a/hw/m68k/mcf_intc.c
+++ b/hw/m68k/mcf_intc.c
@@ -58,34 +58,34 @@ static void mcf_intc_update(mcf_intc_state *s)
 static uint64_t mcf_intc_read(void *opaque, hwaddr addr,
   unsigned size)
 {
 int offset;
 mcf_intc_state *s = (mcf_intc_state *)opaque;
 offset = addr & 0xff;
 if (offset >= 0x40 && offset < 0x80) {
 return s->icr[offset - 0x40];
 }
 switch (offset) {
 case 0x00:
 return (uint32_t)(s->ipr >> 32);
 case 0x04:
 return (uint32_t)s->ipr;
 case 0x08:
 return (uint32_t)(s->imr >> 32);
 case 0x0c:
 return (uint32_t)s->imr;
 case 0x10:
 return (uint32_t)(s->ifr >> 32);
 case 0x14:
 return (uint32_t)s->ifr;
 case 0xe0: /* SWIACK.  */
 return s->active_vector;
 case 0xe1: case 0xe2: case 0xe3: case 0xe4:
 case 0xe5: case 0xe6: case 0xe7:
 /* LnIACK */
 qemu_log_mask(LOG_UNIMP, "%s: LnIACK not implemented (offset 
0x%02x)\n",
   __func__, offset);
-/* fallthru */
+fallthrough;
 default:
 return 0;
 }
 }
-- 
2.39.2




[RFC PATCH v2 07/78] hw/virtio/virtio-balloon.c: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/virtio/virtio-balloon.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index d004cf29d2..0f0d94bd94 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -636,56 +636,57 @@ static int
 virtio_balloon_free_page_hint_notify(NotifierWithReturn *n, void *data)
 {
 VirtIOBalloon *dev = container_of(n, VirtIOBalloon, free_page_hint_notify);
 VirtIODevice *vdev = VIRTIO_DEVICE(dev);
 PrecopyNotifyData *pnd = data;
 
 if (!virtio_balloon_free_page_support(dev)) {
 /*
  * This is an optimization provided to migration, so just return 0 to
  * have the normal migration process not affected when this feature is
  * not supported.
  */
 return 0;
 }
 
 /*
  * Pages hinted via qemu_guest_free_page_hint() are cleared from the dirty
  * bitmap and will not get migrated, especially also not when the postcopy
  * destination starts using them and requests migration from the source; 
the
  * faulting thread will stall until postcopy migration finishes and
  * all threads are woken up. Let's not start free page hinting if postcopy
  * is possible.
  */
 if (migrate_postcopy_ram()) {
 return 0;
 }
 
 switch (pnd->reason) {
 case PRECOPY_NOTIFY_BEFORE_BITMAP_SYNC:
 virtio_balloon_free_page_stop(dev);
 break;
 case PRECOPY_NOTIFY_AFTER_BITMAP_SYNC:
 if (vdev->vm_running) {
 virtio_balloon_free_page_start(dev);
 break;
 }
 /*
  * Set S_DONE before migrating the vmstate, so the guest will reuse
  * all hinted pages once running on the destination. Fall through.
  */
+fallthrough;
 case PRECOPY_NOTIFY_CLEANUP:
 /*
  * Especially, if something goes wrong during precopy or if migration
  * is canceled, we have to properly communicate S_DONE to the VM.
  */
 virtio_balloon_free_page_done(dev);
 break;
 case PRECOPY_NOTIFY_SETUP:
 case PRECOPY_NOTIFY_COMPLETE:
 break;
 default:
 virtio_error(vdev, "%s: %d reason unknown", __func__, pnd->reason);
 }
 
 return 0;
 }
-- 
2.39.2




[RFC PATCH 53/75] hw/core: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/core/loader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/core/loader.c b/hw/core/loader.c
index 4dd5a71fb7..559d63a1e2 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -625,138 +625,138 @@ toosmall:
 /* Load a U-Boot image.  */
 static ssize_t load_uboot_image(const char *filename, hwaddr *ep,
 hwaddr *loadaddr, int *is_linux,
 uint8_t image_type,
 uint64_t (*translate_fn)(void *, uint64_t),
 void *translate_opaque, AddressSpace *as)
 {
 int fd;
 ssize_t size;
 hwaddr address;
 uboot_image_header_t h;
 uboot_image_header_t *hdr = &h;
 uint8_t *data = NULL;
 int ret = -1;
 int do_uncompress = 0;
 
 fd = open(filename, O_RDONLY | O_BINARY);
 if (fd < 0)
 return -1;
 
 size = read(fd, hdr, sizeof(uboot_image_header_t));
 if (size < sizeof(uboot_image_header_t)) {
 goto out;
 }
 
 bswap_uboot_header(hdr);
 
 if (hdr->ih_magic != IH_MAGIC)
 goto out;
 
 if (hdr->ih_type != image_type) {
 if (!(image_type == IH_TYPE_KERNEL &&
 hdr->ih_type == IH_TYPE_KERNEL_NOLOAD)) {
 fprintf(stderr, "Wrong image type %d, expected %d\n", hdr->ih_type,
 image_type);
 goto out;
 }
 }
 
 /* TODO: Implement other image types.  */
 switch (hdr->ih_type) {
 case IH_TYPE_KERNEL_NOLOAD:
 if (!loadaddr || *loadaddr == LOAD_UIMAGE_LOADADDR_INVALID) {
 fprintf(stderr, "this image format (kernel_noload) cannot be "
 "loaded on this machine type");
 goto out;
 }
 
 hdr->ih_load = *loadaddr + sizeof(*hdr);
 hdr->ih_ep += hdr->ih_load;
-/* fall through */
+fallthrough;
 case IH_TYPE_KERNEL:
 address = hdr->ih_load;
 if (translate_fn) {
 address = translate_fn(translate_opaque, address);
 }
 if (loadaddr) {
 *loadaddr = hdr->ih_load;
 }
 
 switch (hdr->ih_comp) {
 case IH_COMP_NONE:
 break;
 case IH_COMP_GZIP:
 do_uncompress = 1;
 break;
 default:
 fprintf(stderr,
 "Unable to load u-boot images with compression type %d\n",
 hdr->ih_comp);
 goto out;
 }
 
 if (ep) {
 *ep = hdr->ih_ep;
 }
 
 /* TODO: Check CPU type.  */
 if (is_linux) {
 if (hdr->ih_os == IH_OS_LINUX) {
 *is_linux = 1;
 } else if (hdr->ih_os == IH_OS_VXWORKS) {
 /*
  * VxWorks 7 uses the same boot interface as the Linux kernel
  * on Arm (64-bit only), PowerPC and RISC-V architectures.
  */
 switch (hdr->ih_arch) {
 case IH_ARCH_ARM64:
 case IH_ARCH_PPC:
 case IH_ARCH_RISCV:
 *is_linux = 1;
 break;
 default:
 *is_linux = 0;
 break;
 }
 } else {
 *is_linux = 0;
 }
 }
 
 break;
 case IH_TYPE_RAMDISK:
 address = *loadaddr;
 break;
 default:
 fprintf(stderr, "Unsupported u-boot image type %d\n", hdr->ih_type);
 goto out;
 }
 
 data = g_malloc(hdr->ih_size);
 
 if (read(fd, data, hdr->ih_size) != hdr->ih_size) {
 fprintf(stderr, "Error reading file\n");
 goto out;
 }
 
 if (do_uncompress) {
 uint8_t *compressed_data;
 size_t max_bytes;
 ssize_t bytes;
 
 compressed_data = data;
 max_bytes = UBOOT_MAX_GUNZIP_BYTES;
 data = g_malloc(max_bytes);
 
 bytes = gunzip(data, max_bytes, compressed_data, hdr->ih_size);
 g_free(compressed_data);
 if (bytes < 0) {
 fprintf(stderr, "Unable to decompress gzipped image!\n");
 goto out;
 }
 hdr->ih_size = bytes;
 }
 
 rom_add_blob_fixed_as(filename, data, hdr->ih_size, address, as);
 
 ret = hdr->ih_size;
-- 
2.39.2




[RFC PATCH v2 77/78] tests/unit/test-char.c: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 tests/unit/test-char.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/unit/test-char.c b/tests/unit/test-char.c
index 649fdf64e1..6f5a2c4108 100644
--- a/tests/unit/test-char.c
+++ b/tests/unit/test-char.c
@@ -56,25 +56,25 @@ static void fe_read(void *opaque, const uint8_t *buf, int 
size)
 static void fe_event(void *opaque, QEMUChrEvent event)
 {
 FeHandler *h = opaque;
 bool new_open_state;
 
 h->last_event = event;
 switch (event) {
 case CHR_EVENT_BREAK:
 break;
 case CHR_EVENT_OPENED:
 case CHR_EVENT_CLOSED:
 h->openclose_count++;
 new_open_state = (event == CHR_EVENT_OPENED);
 if (h->is_open == new_open_state) {
 h->openclose_mismatch = true;
 }
 h->is_open = new_open_state;
-/* fallthrough */
+fallthrough;
 default:
 quit = true;
 break;
 }
 }
 
 #ifdef _WIN32
-- 
2.39.2




[RFC PATCH 45/78] hw/dma: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/dma/omap_dma.c| 32 
 hw/dma/pxa2xx_dma.c  |  4 ++--
 hw/dma/sparc32_dma.c |  2 +-
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/hw/dma/omap_dma.c b/hw/dma/omap_dma.c
index 77797a67b5..dd43dbf3d2 100644
--- a/hw/dma/omap_dma.c
+++ b/hw/dma/omap_dma.c
@@ -1457,46 +1457,46 @@ static int omap_dma_sys_read(struct omap_dma_s *s, int 
offset,
 static uint64_t omap_dma_read(void *opaque, hwaddr addr, unsigned size)
 {
 struct omap_dma_s *s = opaque;
 int reg, ch;
 uint16_t ret;
 
 if (size != 2) {
 return omap_badwidth_read16(opaque, addr);
 }
 
 switch (addr) {
 case 0x300 ... 0x3fe:
 if (s->model <= omap_dma_3_1 || !s->omap_3_1_mapping_disabled) {
 if (omap_dma_3_1_lcd_read(&s->lcd_ch, addr, &ret))
 break;
 return ret;
 }
-/* Fall through. */
+fallthrough;
 case 0x000 ... 0x2fe:
 reg = addr & 0x3f;
 ch = (addr >> 6) & 0x0f;
 if (omap_dma_ch_reg_read(s, &s->ch[ch], reg, &ret))
 break;
 return ret;
 
 case 0x404 ... 0x4fe:
 if (s->model <= omap_dma_3_1)
 break;
-/* Fall through. */
+fallthrough;
 case 0x400:
 if (omap_dma_sys_read(s, addr, &ret))
 break;
 return ret;
 
 case 0xb00 ... 0xbfe:
 if (s->model == omap_dma_3_2 && s->omap_3_1_mapping_disabled) {
 if (omap_dma_3_2_lcd_read(&s->lcd_ch, addr, &ret))
 break;
 return ret;
 }
 break;
 }
 
 OMAP_BAD_REG(addr);
 return 0;
 }
@@ -1504,46 +1504,46 @@ static uint64_t omap_dma_read(void *opaque, hwaddr 
addr, unsigned size)
 static void omap_dma_write(void *opaque, hwaddr addr,
uint64_t value, unsigned size)
 {
 struct omap_dma_s *s = opaque;
 int reg, ch;
 
 if (size != 2) {
 omap_badwidth_write16(opaque, addr, value);
 return;
 }
 
 switch (addr) {
 case 0x300 ... 0x3fe:
 if (s->model <= omap_dma_3_1 || !s->omap_3_1_mapping_disabled) {
 if (omap_dma_3_1_lcd_write(&s->lcd_ch, addr, value))
 break;
 return;
 }
-/* Fall through.  */
+fallthrough;
 case 0x000 ... 0x2fe:
 reg = addr & 0x3f;
 ch = (addr >> 6) & 0x0f;
 if (omap_dma_ch_reg_write(s, &s->ch[ch], reg, value))
 break;
 return;
 
 case 0x404 ... 0x4fe:
 if (s->model <= omap_dma_3_1)
 break;
-/* fall through */
+fallthrough;
 case 0x400:
 if (omap_dma_sys_write(s, addr, value))
 break;
 return;
 
 case 0xb00 ... 0xbfe:
 if (s->model == omap_dma_3_2 && s->omap_3_1_mapping_disabled) {
 if (omap_dma_3_2_lcd_write(&s->lcd_ch, addr, value))
 break;
 return;
 }
 break;
 }
 
 OMAP_BAD_REG(addr);
 }
@@ -1702,155 +1702,155 @@ static void omap_dma_interrupts_4_update(struct 
omap_dma_s *s)
 static uint64_t omap_dma4_read(void *opaque, hwaddr addr,
unsigned size)
 {
 struct omap_dma_s *s = opaque;
 int irqn = 0, chnum;
 struct omap_dma_channel_s *ch;
 
 if (size == 1) {
 return omap_badwidth_read16(opaque, addr);
 }
 
 switch (addr) {
 case 0x00: /* DMA4_REVISION */
 return 0x40;
 
 case 0x14: /* DMA4_IRQSTATUS_L3 */
 irqn ++;
-/* fall through */
+fallthrough;
 case 0x10: /* DMA4_IRQSTATUS_L2 */
 irqn ++;
-/* fall through */
+fallthrough;
 case 0x0c: /* DMA4_IRQSTATUS_L1 */
 irqn ++;
-/* fall through */
+fallthrough;
 case 0x08: /* DMA4_IRQSTATUS_L0 */
 return s->irqstat[irqn];
 
 case 0x24: /* DMA4_IRQENABLE_L3 */
 irqn ++;
-/* fall through */
+fallthrough;
 case 0x20: /* DMA4_IRQENABLE_L2 */
 irqn ++;
-/* fall through */
+fallthrough;
 case 0x1c: /* DMA4_IRQENABLE_L1 */
 irqn ++;
-/* fall through */
+fallthrough;
 case 0x18: /* DMA4_IRQENABLE_L0 */
 return s->irqen[irqn];
 
 case 0x28: /* DMA4_SYSSTATUS */
 return 1;  /* RESETDONE */
 
 case 0x2c: /* DMA4_OCP_SYSCONFIG */
 return s->ocp;
 
 case 0x64: /* DMA4_CAPS_0 */
 return s->caps[0];
 case 0x6c: /* DMA4_CAPS_2 */
 return s->caps[2];
 case 0x70: /* DMA4_CAPS_3 */
 return s->caps[3];
 case 0x74: /* DMA4_CAPS_4 */
 return s->caps[4];
 
 case 0x78: /* DMA4_GCR */
 return s->gcr;
 
 case 0x80 ... 0xfff:
  

[RFC PATCH v2 63/78] hw/ipmi: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/ipmi/ipmi_bmc_extern.c | 2 +-
 hw/ipmi/smbus_ipmi.c  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/ipmi/ipmi_bmc_extern.c b/hw/ipmi/ipmi_bmc_extern.c
index e232d35ba2..b2ca02b21f 100644
--- a/hw/ipmi/ipmi_bmc_extern.c
+++ b/hw/ipmi/ipmi_bmc_extern.c
@@ -168,15 +168,15 @@ static void extern_timeout(void *opaque)
 static void addchar(IPMIBmcExtern *ibe, unsigned char ch)
 {
 switch (ch) {
 case VM_MSG_CHAR:
 case VM_CMD_CHAR:
 case VM_ESCAPE_CHAR:
 ibe->outbuf[ibe->outlen] = VM_ESCAPE_CHAR;
 ibe->outlen++;
 ch |= 0x10;
-/* fall through */
+fallthrough;
 default:
 ibe->outbuf[ibe->outlen] = ch;
 ibe->outlen++;
 }
 }
diff --git a/hw/ipmi/smbus_ipmi.c b/hw/ipmi/smbus_ipmi.c
index d0991ab7f9..58f5328a19 100644
--- a/hw/ipmi/smbus_ipmi.c
+++ b/hw/ipmi/smbus_ipmi.c
@@ -207,90 +207,90 @@ static int ipmi_load_readbuf(SMBusIPMIDevice *sid)
 static int ipmi_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len)
 {
 SMBusIPMIDevice *sid = SMBUS_IPMI(dev);
 bool send = false;
 uint8_t cmd;
 int ret = 0;
 
 /* length is guaranteed to be >= 1. */
 cmd = *buf++;
 len--;
 
 /* Handle read request, which don't have any data in the write part. */
 switch (cmd) {
 case SSIF_IPMI_RESPONSE:
 sid->currblk = 0;
 ret = ipmi_load_readbuf(sid);
 break;
 
 case SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE:
 sid->currblk++;
 ret = ipmi_load_readbuf(sid);
 break;
 
 case SSIF_IPMI_MULTI_PART_RETRY:
 if (len >= 1) {
 sid->currblk = buf[0];
 ret = ipmi_load_readbuf(sid);
 } else {
 ret = -1;
 }
 break;
 
 default:
 break;
 }
 
 /* This should be a message write, make the length is there and correct. */
 if (len >= 1) {
 if (*buf != len - 1 || *buf > MAX_SSIF_IPMI_MSG_CHUNK) {
 return -1; /* Bogus message */
 }
 buf++;
 len--;
 }
 
 switch (cmd) {
 case SSIF_IPMI_REQUEST:
 send = true;
-/* FALLTHRU */
+fallthrough;
 case SSIF_IPMI_MULTI_PART_REQUEST_START:
 if (len < 2) {
 return -1; /* Bogus. */
 }
 memcpy(sid->inmsg, buf, len);
 sid->inlen = len;
 break;
 
 case SSIF_IPMI_MULTI_PART_REQUEST_END:
 send = true;
-/* FALLTHRU */
+fallthrough;
 case SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE:
 if (!sid->inlen) {
 return -1; /* Bogus. */
 }
 if (sid->inlen + len > MAX_SSIF_IPMI_MSG_SIZE) {
 sid->inlen = 0; /* Discard the message. */
 return -1; /* Bogus. */
 }
 if (len < 32) {
 /*
  * Special hack, a multi-part middle that is less than 32 bytes
  * marks the end of a message.  The specification is fairly
  * confusing, so some systems to this, even sending a zero
  * length end message to mark the end.
  */
 send = true;
 }
 if (len > 0) {
 memcpy(sid->inmsg + sid->inlen, buf, len);
 }
 sid->inlen += len;
 break;
 }
 
 if (send && sid->inlen) {
 smbus_ipmi_send_msg(sid);
 }
 
 return ret;
 }
-- 
2.39.2




[RFC PATCH v2 40/78] hw/sd/sdhci.c: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/sd/sdhci.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 5564765a9b..5c641d24de 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -75,138 +75,138 @@ static bool sdhci_check_capab_freq_range(SDHCIState *s, 
const char *desc,
 static void sdhci_check_capareg(SDHCIState *s, Error **errp)
 {
 uint64_t msk = s->capareg;
 uint32_t val;
 bool y;
 
 switch (s->sd_spec_version) {
 case 4:
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, BUS64BIT_V4);
 trace_sdhci_capareg("64-bit system bus (v4)", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, BUS64BIT_V4, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, UHS_II);
 trace_sdhci_capareg("UHS-II", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, UHS_II, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, ADMA3);
 trace_sdhci_capareg("ADMA3", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, ADMA3, 0);
 
-/* fallthrough */
+fallthrough;
 case 3:
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, ASYNC_INT);
 trace_sdhci_capareg("async interrupt", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, ASYNC_INT, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, SLOT_TYPE);
 if (val) {
 error_setg(errp, "slot-type not supported");
 return;
 }
 trace_sdhci_capareg("slot type", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, SLOT_TYPE, 0);
 
 if (val != 2) {
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, EMBEDDED_8BIT);
 trace_sdhci_capareg("8-bit bus", val);
 }
 msk = FIELD_DP64(msk, SDHC_CAPAB, EMBEDDED_8BIT, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, BUS_SPEED);
 trace_sdhci_capareg("bus speed mask", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, BUS_SPEED, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, DRIVER_STRENGTH);
 trace_sdhci_capareg("driver strength mask", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, DRIVER_STRENGTH, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, TIMER_RETUNING);
 trace_sdhci_capareg("timer re-tuning", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, TIMER_RETUNING, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, SDR50_TUNING);
 trace_sdhci_capareg("use SDR50 tuning", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, SDR50_TUNING, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, RETUNING_MODE);
 trace_sdhci_capareg("re-tuning mode", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, RETUNING_MODE, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, CLOCK_MULT);
 trace_sdhci_capareg("clock multiplier", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, CLOCK_MULT, 0);
 
-/* fallthrough */
+fallthrough;
 case 2: /* default version */
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, ADMA2);
 trace_sdhci_capareg("ADMA2", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, ADMA2, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, ADMA1);
 trace_sdhci_capareg("ADMA1", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, ADMA1, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, BUS64BIT);
 trace_sdhci_capareg("64-bit system bus (v3)", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, BUS64BIT, 0);
 
-/* fallthrough */
+fallthrough;
 case 1:
 y = FIELD_EX64(s->capareg, SDHC_CAPAB, TOUNIT);
 msk = FIELD_DP64(msk, SDHC_CAPAB, TOUNIT, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, TOCLKFREQ);
 trace_sdhci_capareg(y ? "timeout (MHz)" : "Timeout (KHz)", val);
 if (sdhci_check_capab_freq_range(s, "timeout", val, errp)) {
 return;
 }
 msk = FIELD_DP64(msk, SDHC_CAPAB, TOCLKFREQ, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, BASECLKFREQ);
 trace_sdhci_capareg(y ? "base (MHz)" : "Base (KHz)", val);
 if (sdhci_check_capab_freq_range(s, "base", val, errp)) {
 return;
 }
 msk = FIELD_DP64(msk, SDHC_CAPAB, BASECLKFREQ, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, MAXBLOCKLENGTH);
 if (val >= 3) {
 error_setg(errp, "block size can be 512, 1024 or 2048 only");
 return;
 }
 trace_sdhci_capareg("max block length", sdhci_get_fifolen(s));
 msk = FIELD_DP64(msk, SDHC_CAPAB, MAXBLOCKLENGTH, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, HIGHSPEED);
 trace_sdhci_capareg("high speed", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, HIGHSPEED, 0);
 
 val = FIELD_EX64(s->capareg, SDHC_CAPAB, SDMA);
 trace_sdhci_capareg("SDMA", val);
 msk = FIELD_DP64(msk, SDHC_CAPAB, SDMA, 0);
 
  

[RFC PATCH v2 29/78] target/cris: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/cris/translate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/cris/translate.c b/target/cris/translate.c
index b3974ba0bb..bdd128db23 100644
--- a/target/cris/translate.c
+++ b/target/cris/translate.c
@@ -3061,94 +3061,94 @@ static void cris_tr_translate_insn(DisasContextBase 
*dcbase, CPUState *cs)
 static void cris_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
 {
 DisasContext *dc = container_of(dcbase, DisasContext, base);
 DisasJumpType is_jmp = dc->base.is_jmp;
 target_ulong npc = dc->pc;
 
 if (is_jmp == DISAS_NORETURN) {
 /* If we have a broken branch+delayslot sequence, it's too late. */
 assert(dc->delayed_branch != 1);
 return;
 }
 
 if (dc->clear_locked_irq) {
 t_gen_movi_env_TN(locked_irq, 0);
 }
 
 /* Broken branch+delayslot sequence.  */
 if (dc->delayed_branch == 1) {
 /* Set env->dslot to the size of the branch insn.  */
 t_gen_movi_env_TN(dslot, dc->pc - dc->ppc);
 cris_store_direct_jmp(dc);
 }
 
 cris_evaluate_flags(dc);
 
 /* Evaluate delayed branch destination and fold to another is_jmp case. */
 if (is_jmp == DISAS_DBRANCH) {
 if (dc->base.tb->flags & 7) {
 t_gen_movi_env_TN(dslot, 0);
 }
 
 switch (dc->jmp) {
 case JMP_DIRECT:
 npc = dc->jmp_pc;
 is_jmp = dc->cpustate_changed ? DISAS_UPDATE_NEXT : DISAS_TOO_MANY;
 break;
 
 case JMP_DIRECT_CC:
 /*
  * Use a conditional branch if either taken or not-taken path
  * can use goto_tb.  If neither can, then treat it as indirect.
  */
 if (likely(!dc->cpustate_changed)
 && (use_goto_tb(dc, dc->jmp_pc) || use_goto_tb(dc, npc))) {
 TCGLabel *not_taken = gen_new_label();
 
 tcg_gen_brcondi_tl(TCG_COND_EQ, env_btaken, 0, not_taken);
 gen_goto_tb(dc, 1, dc->jmp_pc);
 gen_set_label(not_taken);
 
 /* not-taken case handled below. */
 is_jmp = DISAS_TOO_MANY;
 break;
 }
 tcg_gen_movi_tl(env_btarget, dc->jmp_pc);
-/* fall through */
+fallthrough;
 
 case JMP_INDIRECT:
 tcg_gen_movcond_tl(TCG_COND_NE, env_pc,
env_btaken, tcg_constant_tl(0),
env_btarget, tcg_constant_tl(npc));
 is_jmp = dc->cpustate_changed ? DISAS_UPDATE : DISAS_JUMP;
 
 /*
  * We have now consumed btaken and btarget.  Hint to the
  * tcg compiler that the writeback to env may be dropped.
  */
 tcg_gen_discard_tl(env_btaken);
 tcg_gen_discard_tl(env_btarget);
 break;
 
 default:
 g_assert_not_reached();
 }
 }
 
 switch (is_jmp) {
 case DISAS_TOO_MANY:
 gen_goto_tb(dc, 0, npc);
 break;
 case DISAS_UPDATE_NEXT:
 tcg_gen_movi_tl(env_pc, npc);
-/* fall through */
+fallthrough;
 case DISAS_JUMP:
 tcg_gen_lookup_and_goto_ptr();
 break;
 case DISAS_UPDATE:
 /* Indicate that interrupts must be re-evaluated before the next TB. */
 tcg_gen_exit_tb(NULL, 0);
 break;
 default:
 g_assert_not_reached();
 }
 }
-- 
2.39.2




[RFC PATCH v2 03/78] fpu/softfloat: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 fpu/softfloat-parts.c.inc | 8 
 fpu/softfloat.c   | 7 ---
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc
index a44649f4f4..df64cc7a29 100644
--- a/fpu/softfloat-parts.c.inc
+++ b/fpu/softfloat-parts.c.inc
@@ -138,166 +138,166 @@ static void partsN(canonicalize)(FloatPartsN *p, 
float_status *status,
 /*
  * Round and uncanonicalize a floating-point number by parts. There
  * are FRAC_SHIFT bits that may require rounding at the bottom of the
  * fraction; these bits will be removed. The exponent will be biased
  * by EXP_BIAS and must be bounded by [EXP_MAX-1, 0].
  */
 static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s,
const FloatFmt *fmt)
 {
 const int exp_max = fmt->exp_max;
 const int frac_shift = fmt->frac_shift;
 const uint64_t round_mask = fmt->round_mask;
 const uint64_t frac_lsb = round_mask + 1;
 const uint64_t frac_lsbm1 = round_mask ^ (round_mask >> 1);
 const uint64_t roundeven_mask = round_mask | frac_lsb;
 uint64_t inc;
 bool overflow_norm = false;
 int exp, flags = 0;
 
 switch (s->float_rounding_mode) {
 case float_round_nearest_even:
 if (N > 64 && frac_lsb == 0) {
 inc = ((p->frac_hi & 1) || (p->frac_lo & round_mask) != frac_lsbm1
? frac_lsbm1 : 0);
 } else {
 inc = ((p->frac_lo & roundeven_mask) != frac_lsbm1
? frac_lsbm1 : 0);
 }
 break;
 case float_round_ties_away:
 inc = frac_lsbm1;
 break;
 case float_round_to_zero:
 overflow_norm = true;
 inc = 0;
 break;
 case float_round_up:
 inc = p->sign ? 0 : round_mask;
 overflow_norm = p->sign;
 break;
 case float_round_down:
 inc = p->sign ? round_mask : 0;
 overflow_norm = !p->sign;
 break;
 case float_round_to_odd:
 overflow_norm = true;
-/* fall through */
+fallthrough;
 case float_round_to_odd_inf:
 if (N > 64 && frac_lsb == 0) {
 inc = p->frac_hi & 1 ? 0 : round_mask;
 } else {
 inc = p->frac_lo & frac_lsb ? 0 : round_mask;
 }
 break;
 default:
 g_assert_not_reached();
 }
 
 exp = p->exp + fmt->exp_bias;
 if (likely(exp > 0)) {
 if (p->frac_lo & round_mask) {
 flags |= float_flag_inexact;
 if (frac_addi(p, p, inc)) {
 frac_shr(p, 1);
 p->frac_hi |= DECOMPOSED_IMPLICIT_BIT;
 exp++;
 }
 p->frac_lo &= ~round_mask;
 }
 
 if (fmt->arm_althp) {
 /* ARM Alt HP eschews Inf and NaN for a wider exponent.  */
 if (unlikely(exp > exp_max)) {
 /* Overflow.  Return the maximum normal.  */
 flags = float_flag_invalid;
 exp = exp_max;
 frac_allones(p);
 p->frac_lo &= ~round_mask;
 }
 } else if (unlikely(exp >= exp_max)) {
 flags |= float_flag_overflow;
 if (s->rebias_overflow) {
 exp -= fmt->exp_re_bias;
 } else if (overflow_norm) {
 flags |= float_flag_inexact;
 exp = exp_max - 1;
 frac_allones(p);
 p->frac_lo &= ~round_mask;
 } else {
 flags |= float_flag_inexact;
 p->cls = float_class_inf;
 exp = exp_max;
 frac_clear(p);
 }
 }
 frac_shr(p, frac_shift);
 } else if (unlikely(s->rebias_underflow)) {
 flags |= float_flag_underflow;
 exp += fmt->exp_re_bias;
 if (p->frac_lo & round_mask) {
 flags |= float_flag_inexact;
 if (frac_addi(p, p, inc)) {
 frac_shr(p, 1);
 p->frac_hi |= DECOMPOSED_IMPLICIT_BIT;
 exp++;
 }
 p->frac_lo &= ~round_mask;
 }
 frac_shr(p, frac_shift);
 } else if (s->flush_to_zero) {
 flags |= float_flag_output_denormal;
 p->cls = float_class_zero;
 exp = 0;
 frac_clear(p);
 } else {
 bool is_tiny = s->tininess_before_rounding || exp < 0;
 
 if (!is_tiny) {
 FloatPartsN discard;
 is_tiny = !frac_addi(&discard, p, inc);
 }
 
 frac_shrjam(p, !fmt->m68k_denormal - exp);
 
 if (p->frac_lo & round_mask) {
 /* Need to recompute round-to-even/round-to-odd. */
 switch (s->float_rounding_mode) {
 case float_round_nearest_even:
 if 

[RFC PATCH 21/78] target/sparc: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/sparc/ldst_helper.c | 4 ++--
 target/sparc/mmu_helper.c  | 6 +++---
 target/sparc/translate.c   | 3 ++-
 target/sparc/win_helper.c  | 1 +
 4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/target/sparc/ldst_helper.c b/target/sparc/ldst_helper.c
index 78b03308ae..b233e40da5 100644
--- a/target/sparc/ldst_helper.c
+++ b/target/sparc/ldst_helper.c
@@ -1296,294 +1296,294 @@ void helper_st_asi(CPUSPARCState *env, target_ulong 
addr, target_ulong val,
 uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr,
int asi, uint32_t memop)
 {
 int size = 1 << (memop & MO_SIZE);
 int sign = memop & MO_SIGN;
 CPUState *cs = env_cpu(env);
 uint64_t ret = 0;
 #if defined(DEBUG_ASI)
 target_ulong last_addr = addr;
 #endif
 
 asi &= 0xff;
 
 do_check_asi(env, asi, GETPC());
 do_check_align(env, addr, size - 1, GETPC());
 addr = asi_address_mask(env, asi, addr);
 
 switch (asi) {
 case ASI_PNF:
 case ASI_PNFL:
 case ASI_SNF:
 case ASI_SNFL:
 {
 MemOpIdx oi;
 int idx = (env->pstate & PS_PRIV
? (asi & 1 ? MMU_KERNEL_SECONDARY_IDX : MMU_KERNEL_IDX)
: (asi & 1 ? MMU_USER_SECONDARY_IDX : MMU_USER_IDX));
 
 if (cpu_get_phys_page_nofault(env, addr, idx) == -1ULL) {
 #ifdef DEBUG_ASI
 dump_asi("read ", last_addr, asi, size, ret);
 #endif
 /* exception_index is set in get_physical_address_data. */
 cpu_raise_exception_ra(env, cs->exception_index, GETPC());
 }
 oi = make_memop_idx(memop, idx);
 switch (size) {
 case 1:
 ret = cpu_ldb_mmu(env, addr, oi, GETPC());
 break;
 case 2:
 ret = cpu_ldw_mmu(env, addr, oi, GETPC());
 break;
 case 4:
 ret = cpu_ldl_mmu(env, addr, oi, GETPC());
 break;
 case 8:
 ret = cpu_ldq_mmu(env, addr, oi, GETPC());
 break;
 default:
 g_assert_not_reached();
 }
 }
 break;
 
 case ASI_AIUP:  /* As if user primary */
 case ASI_AIUS:  /* As if user secondary */
 case ASI_AIUPL: /* As if user primary LE */
 case ASI_AIUSL: /* As if user secondary LE */
 case ASI_P:  /* Primary */
 case ASI_S:  /* Secondary */
 case ASI_PL: /* Primary LE */
 case ASI_SL: /* Secondary LE */
 case ASI_REAL:  /* Bypass */
 case ASI_REAL_IO:   /* Bypass, non-cacheable */
 case ASI_REAL_L:/* Bypass LE */
 case ASI_REAL_IO_L: /* Bypass, non-cacheable LE */
 case ASI_N:  /* Nucleus */
 case ASI_NL: /* Nucleus Little Endian (LE) */
 case ASI_NUCLEUS_QUAD_LDD:   /* Nucleus quad LDD 128 bit atomic */
 case ASI_NUCLEUS_QUAD_LDD_L: /* Nucleus quad LDD 128 bit atomic LE */
 case ASI_TWINX_AIUP:   /* As if user primary, twinx */
 case ASI_TWINX_AIUS:   /* As if user secondary, twinx */
 case ASI_TWINX_REAL:   /* Real address, twinx */
 case ASI_TWINX_AIUP_L: /* As if user primary, twinx, LE */
 case ASI_TWINX_AIUS_L: /* As if user secondary, twinx, LE */
 case ASI_TWINX_REAL_L: /* Real address, twinx, LE */
 case ASI_TWINX_N:  /* Nucleus, twinx */
 case ASI_TWINX_NL: /* Nucleus, twinx, LE */
 /* ??? From the UA2011 document; overlaps BLK_INIT_QUAD_LDD_* */
 case ASI_TWINX_P:  /* Primary, twinx */
 case ASI_TWINX_PL: /* Primary, twinx, LE */
 case ASI_TWINX_S:  /* Secondary, twinx */
 case ASI_TWINX_SL: /* Secondary, twinx, LE */
 /* These are always handled inline.  */
 g_assert_not_reached();
 
 case ASI_UPA_CONFIG: /* UPA config */
 /* XXX */
 break;
 case ASI_LSU_CONTROL: /* LSU */
 ret = env->lsu;
 break;
 case ASI_IMMU: /* I-MMU regs */
 {
 int reg = (addr >> 3) & 0xf;
 switch (reg) {
 case 0:
 /* 0x00 I-TSB Tag Target register */
 ret = ultrasparc_tag_target(env->immu.tag_access);
 break;
 case 3: /* SFSR */
 ret = env->immu.sfsr;
 break;
 case 5: /* TSB access */
 ret = env->immu.tsb;
 break;
 case 6:
 /* 0x30 I-TSB Tag Access register */
 ret = env->immu.tag_access;
 break;
 default:
 sparc_raise_mmu_fault(cs, addr, false, false, 1, size, 
GETPC());
 ret = 0;
 }
 break;
 }
 case ASI_IMMU_TSB_8KB_PTR: /* I-MMU 8k TSB pointer */
 {
 /* env->imm

[RFC PATCH 24/78] target/alpha: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/alpha/helper.c| 6 +++---
 target/alpha/translate.c | 4 +++-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/target/alpha/helper.c b/target/alpha/helper.c
index 970c869771..1afdc1beec 100644
--- a/target/alpha/helper.c
+++ b/target/alpha/helper.c
@@ -436,45 +436,45 @@ void alpha_cpu_do_interrupt(CPUState *cs)
 bool alpha_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
 {
 AlphaCPU *cpu = ALPHA_CPU(cs);
 CPUAlphaState *env = &cpu->env;
 int idx = -1;
 
 /* We never take interrupts while in PALmode.  */
 if (env->flags & ENV_FLAG_PAL_MODE) {
 return false;
 }
 
 /* Fall through the switch, collecting the highest priority
interrupt that isn't masked by the processor status IPL.  */
 /* ??? This hard-codes the OSF/1 interrupt levels.  */
 switch ((env->flags >> ENV_FLAG_PS_SHIFT) & PS_INT_MASK) {
 case 0 ... 3:
 if (interrupt_request & CPU_INTERRUPT_HARD) {
 idx = EXCP_DEV_INTERRUPT;
 }
-/* FALLTHRU */
+fallthrough;
 case 4:
 if (interrupt_request & CPU_INTERRUPT_TIMER) {
 idx = EXCP_CLK_INTERRUPT;
 }
-/* FALLTHRU */
+fallthrough;
 case 5:
 if (interrupt_request & CPU_INTERRUPT_SMP) {
 idx = EXCP_SMP_INTERRUPT;
 }
-/* FALLTHRU */
+fallthrough;
 case 6:
 if (interrupt_request & CPU_INTERRUPT_MCHK) {
 idx = EXCP_MCHK;
 }
 }
 if (idx >= 0) {
 cs->exception_index = idx;
 env->error_code = 0;
 alpha_cpu_do_interrupt(cs);
 return true;
 }
 return false;
 }
 
 #endif /* !CONFIG_USER_ONLY */
diff --git a/target/alpha/translate.c b/target/alpha/translate.c
index 32333081d8..19e1d2ed86 100644
--- a/target/alpha/translate.c
+++ b/target/alpha/translate.c
@@ -1377,1493 +1377,1493 @@ static DisasJumpType gen_mtpr(DisasContext *ctx, 
TCGv vb, int regno)
 static DisasJumpType translate_one(DisasContext *ctx, uint32_t insn)
 {
 int32_t disp21, disp16, disp12 __attribute__((unused));
 uint16_t fn11;
 uint8_t opc, ra, rb, rc, fpfn, fn7, lit;
 bool islit, real_islit;
 TCGv va, vb, vc, tmp, tmp2;
 TCGv_i32 t32;
 DisasJumpType ret;
 
 /* Decode all instruction fields */
 opc = extract32(insn, 26, 6);
 ra = extract32(insn, 21, 5);
 rb = extract32(insn, 16, 5);
 rc = extract32(insn, 0, 5);
 real_islit = islit = extract32(insn, 12, 1);
 lit = extract32(insn, 13, 8);
 
 disp21 = sextract32(insn, 0, 21);
 disp16 = sextract32(insn, 0, 16);
 disp12 = sextract32(insn, 0, 12);
 
 fn11 = extract32(insn, 5, 11);
 fpfn = extract32(insn, 5, 6);
 fn7 = extract32(insn, 5, 7);
 
 if (rb == 31 && !islit) {
 islit = true;
 lit = 0;
 }
 
 ret = DISAS_NEXT;
 switch (opc) {
 case 0x00:
 /* CALL_PAL */
 ret = gen_call_pal(ctx, insn & 0x03ff);
 break;
 case 0x01:
 /* OPC01 */
 goto invalid_opc;
 case 0x02:
 /* OPC02 */
 goto invalid_opc;
 case 0x03:
 /* OPC03 */
 goto invalid_opc;
 case 0x04:
 /* OPC04 */
 goto invalid_opc;
 case 0x05:
 /* OPC05 */
 goto invalid_opc;
 case 0x06:
 /* OPC06 */
 goto invalid_opc;
 case 0x07:
 /* OPC07 */
 goto invalid_opc;
 
 case 0x09:
 /* LDAH */
 disp16 = (uint32_t)disp16 << 16;
-/* fall through */
+fallthrough;
 case 0x08:
 /* LDA */
 va = dest_gpr(ctx, ra);
 /* It's worth special-casing immediate loads.  */
 if (rb == 31) {
 tcg_gen_movi_i64(va, disp16);
 } else {
 tcg_gen_addi_i64(va, load_gpr(ctx, rb), disp16);
 }
 break;
 
 case 0x0A:
 /* LDBU */
 REQUIRE_AMASK(BWX);
 gen_load_int(ctx, ra, rb, disp16, MO_UB, 0, 0);
 break;
 case 0x0B:
 /* LDQ_U */
 gen_load_int(ctx, ra, rb, disp16, MO_LEUQ, 1, 0);
 break;
 case 0x0C:
 /* LDWU */
 REQUIRE_AMASK(BWX);
 gen_load_int(ctx, ra, rb, disp16, MO_LEUW, 0, 0);
 break;
 case 0x0D:
 /* STW */
 REQUIRE_AMASK(BWX);
 gen_store_int(ctx, ra, rb, disp16, MO_LEUW, 0);
 break;
 case 0x0E:
 /* STB */
 REQUIRE_AMASK(BWX);
 gen_store_int(ctx, ra, rb, disp16, MO_UB, 0);
 break;
 case 0x0F:
 /* STQ_U */
 gen_store_int(ctx, ra, rb, disp16, MO_LEUQ, 1);
 break;
 
 case 0x10:
 vc = dest_gpr(ctx, rc);
 vb = load_gpr_lit(ctx, rb, lit, islit);
 
 if (ra == 31) {
 if (fn7 == 0x00) {

[RFC PATCH 22/78] target/ppc: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/ppc/cpu_init.c|  8 
 target/ppc/excp_helper.c |  6 +++---
 target/ppc/mmu-radix64.c |  6 +++---
 target/ppc/mmu_common.c  | 12 ++--
 target/ppc/translate.c   |  6 +++---
 5 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
index 40fe14a6c2..7a7bd4d824 100644
--- a/target/ppc/cpu_init.c
+++ b/target/ppc/cpu_init.c
@@ -840,84 +840,84 @@ static inline uint32_t register_tlbncfg(uint32_t assoc, 
uint32_t minsize,
 /* BookE 2.06 storage control registers */
 static void register_BookE206_sprs(CPUPPCState *env, uint32_t mas_mask,
  uint32_t *tlbncfg, uint32_t mmucfg)
 {
 #if !defined(CONFIG_USER_ONLY)
 const char *mas_names[8] = {
 "MAS0", "MAS1", "MAS2", "MAS3", "MAS4", "MAS5", "MAS6", "MAS7",
 };
 int mas_sprn[8] = {
 SPR_BOOKE_MAS0, SPR_BOOKE_MAS1, SPR_BOOKE_MAS2, SPR_BOOKE_MAS3,
 SPR_BOOKE_MAS4, SPR_BOOKE_MAS5, SPR_BOOKE_MAS6, SPR_BOOKE_MAS7,
 };
 int i;
 
 /* TLB assist registers */
 for (i = 0; i < 8; i++) {
 if (mas_mask & (1 << i)) {
 spr_register(env, mas_sprn[i], mas_names[i],
  SPR_NOACCESS, SPR_NOACCESS,
  &spr_read_generic,
  (i == 2 && (env->insns_flags & PPC_64B))
  ? &spr_write_generic : &spr_write_generic32,
  0x);
 }
 }
 if (env->nb_pids > 1) {
 spr_register(env, SPR_BOOKE_PID1, "PID1",
  SPR_NOACCESS, SPR_NOACCESS,
  &spr_read_generic, &spr_write_booke_pid,
  0x);
 }
 if (env->nb_pids > 2) {
 spr_register(env, SPR_BOOKE_PID2, "PID2",
  SPR_NOACCESS, SPR_NOACCESS,
  &spr_read_generic, &spr_write_booke_pid,
  0x);
 }
 
 spr_register(env, SPR_BOOKE_EPLC, "EPLC",
  SPR_NOACCESS, SPR_NOACCESS,
  &spr_read_generic, &spr_write_eplc,
  0x);
 spr_register(env, SPR_BOOKE_EPSC, "EPSC",
  SPR_NOACCESS, SPR_NOACCESS,
  &spr_read_generic, &spr_write_epsc,
  0x);
 
 spr_register(env, SPR_MMUCFG, "MMUCFG",
  SPR_NOACCESS, SPR_NOACCESS,
  &spr_read_generic, SPR_NOACCESS,
  mmucfg);
 switch (env->nb_ways) {
 case 4:
 spr_register(env, SPR_BOOKE_TLB3CFG, "TLB3CFG",
  SPR_NOACCESS, SPR_NOACCESS,
  &spr_read_generic, SPR_NOACCESS,
  tlbncfg[3]);
-/* Fallthru */
+fallthrough;
 case 3:
 spr_register(env, SPR_BOOKE_TLB2CFG, "TLB2CFG",
  SPR_NOACCESS, SPR_NOACCESS,
  &spr_read_generic, SPR_NOACCESS,
  tlbncfg[2]);
-/* Fallthru */
+fallthrough;
 case 2:
 spr_register(env, SPR_BOOKE_TLB1CFG, "TLB1CFG",
  SPR_NOACCESS, SPR_NOACCESS,
  &spr_read_generic, SPR_NOACCESS,
  tlbncfg[1]);
-/* Fallthru */
+fallthrough;
 case 1:
 spr_register(env, SPR_BOOKE_TLB0CFG, "TLB0CFG",
  SPR_NOACCESS, SPR_NOACCESS,
  &spr_read_generic, SPR_NOACCESS,
  tlbncfg[0]);
-/* Fallthru */
+fallthrough;
 case 0:
 default:
 break;
 }
 #endif
 }
 
 /* SPR specific to PowerPC 440 implementation */
diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c
index 7926114d5c..b8be34051c 100644
--- a/target/ppc/excp_helper.c
+++ b/target/ppc/excp_helper.c
@@ -1311,51 +1311,51 @@ static bool is_prefix_insn(CPUPPCState *env, uint32_t 
insn)
 static bool is_prefix_insn_excp(PowerPCCPU *cpu, int excp)
 {
 CPUPPCState *env = &cpu->env;
 
 if (!tcg_enabled()) {
 /*
  * This does not load instructions and set the prefix bit correctly
  * for injected interrupts with KVM. That may have to be discovered
  * and set by the KVM layer before injecting.
  */
 return false;
 }
 
 switch (excp) {
 case POWERPC_EXCP_HDSI:
 /* HDSI PRTABLE_FAULT has the originating access type in error_code */
 if ((env->spr[SPR_HDSISR] & DSISR_PRTABLE_FAULT) &&
 (env->error_code == MMU_INST_FETCH)) {
 /*
  * Fetch failed due to partition scope translation, so prefix
  * indication is not relevant (and attempting to load the
  * instruction at NIP would cause recursive faults with the same
  * translation).
  */
  

[RFC PATCH v2 42/78] hw/i386: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/i386/intel_iommu.c| 4 ++--
 hw/i386/kvm/xen_evtchn.c | 2 +-
 hw/i386/x86.c| 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 2c832ab68b..bdb2ea3ac5 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -2100,29 +2100,29 @@ static void 
vtd_context_device_invalidate(IntelIOMMUState *s,
 /* Context-cache invalidation
  * Returns the Context Actual Invalidation Granularity.
  * @val: the content of the CCMD_REG
  */
 static uint64_t vtd_context_cache_invalidate(IntelIOMMUState *s, uint64_t val)
 {
 uint64_t caig;
 uint64_t type = val & VTD_CCMD_CIRG_MASK;
 
 switch (type) {
 case VTD_CCMD_DOMAIN_INVL:
-/* Fall through */
+fallthrough;
 case VTD_CCMD_GLOBAL_INVL:
 caig = VTD_CCMD_GLOBAL_INVL_A;
 vtd_context_global_invalidate(s);
 break;
 
 case VTD_CCMD_DEVICE_INVL:
 caig = VTD_CCMD_DEVICE_INVL_A;
 vtd_context_device_invalidate(s, VTD_CCMD_SID(val), VTD_CCMD_FM(val));
 break;
 
 default:
 error_report_once("%s: invalid context: 0x%" PRIx64,
   __func__, val);
 caig = 0;
 }
 return caig;
 }
@@ -2513,34 +2513,34 @@ static bool vtd_process_wait_desc(IntelIOMMUState *s, 
VTDInvDesc *inv_desc)
 static bool vtd_process_context_cache_desc(IntelIOMMUState *s,
VTDInvDesc *inv_desc)
 {
 uint16_t sid, fmask;
 
 if ((inv_desc->lo & VTD_INV_DESC_CC_RSVD) || inv_desc->hi) {
 error_report_once("%s: invalid cc inv desc: hi=%"PRIx64", lo=%"PRIx64
   " (reserved nonzero)", __func__, inv_desc->hi,
   inv_desc->lo);
 return false;
 }
 switch (inv_desc->lo & VTD_INV_DESC_CC_G) {
 case VTD_INV_DESC_CC_DOMAIN:
 trace_vtd_inv_desc_cc_domain(
 (uint16_t)VTD_INV_DESC_CC_DID(inv_desc->lo));
-/* Fall through */
+fallthrough;
 case VTD_INV_DESC_CC_GLOBAL:
 vtd_context_global_invalidate(s);
 break;
 
 case VTD_INV_DESC_CC_DEVICE:
 sid = VTD_INV_DESC_CC_SID(inv_desc->lo);
 fmask = VTD_INV_DESC_CC_FM(inv_desc->lo);
 vtd_context_device_invalidate(s, sid, fmask);
 break;
 
 default:
 error_report_once("%s: invalid cc inv desc: hi=%"PRIx64", lo=%"PRIx64
   " (invalid type)", __func__, inv_desc->hi,
   inv_desc->lo);
 return false;
 }
 return true;
 }
diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c
index a731738411..d15e324f6e 100644
--- a/hw/i386/kvm/xen_evtchn.c
+++ b/hw/i386/kvm/xen_evtchn.c
@@ -2028,71 +2028,71 @@ static int find_be_port(XenEvtchnState *s, struct 
xenevtchn_handle *xc)
 int xen_be_evtchn_bind_interdomain(struct xenevtchn_handle *xc, uint32_t domid,
evtchn_port_t guest_port)
 {
 XenEvtchnState *s = xen_evtchn_singleton;
 XenEvtchnPort *gp;
 uint16_t be_port = 0;
 int ret;
 
 if (!s) {
 return -ENOTSUP;
 }
 
 if (!xc) {
 return -EFAULT;
 }
 
 if (domid != xen_domid) {
 return -ESRCH;
 }
 
 if (!valid_port(guest_port)) {
 return -EINVAL;
 }
 
 qemu_mutex_lock(&s->port_lock);
 
 /* The guest has to have an unbound port waiting for us to bind */
 gp = &s->port_table[guest_port];
 
 switch (gp->type) {
 case EVTCHNSTAT_interdomain:
 /* Allow rebinding after migration, preserve port # if possible */
 be_port = gp->type_val & ~PORT_INFO_TYPEVAL_REMOTE_QEMU;
 assert(be_port != 0);
 if (!s->be_handles[be_port]) {
 s->be_handles[be_port] = xc;
 xc->guest_port = guest_port;
 ret = xc->be_port = be_port;
 if (kvm_xen_has_cap(EVTCHN_SEND)) {
 assign_kernel_eventfd(gp->type, guest_port, xc->fd);
 }
 break;
 }
-/* fall through */
+fallthrough;
 
 case EVTCHNSTAT_unbound:
 be_port = find_be_port(s, xc);
 if (!be_port) {
 ret = -ENOSPC;
 goto out;
 }
 
 gp->type = EVTCHNSTAT_interdomain;
 gp->type_val = be_port | PORT_INFO_TYPEVAL_REMOTE_QEMU;
 xc->guest_port = guest_port;
 if (kvm_xen_has_cap(EVTCHN_SEND)) {
 assign_kernel_eventfd(gp->type, guest_port, xc->fd);
 }
 ret = be_port;
 break;
 
 default:
 ret = -EINVAL;
 break;
 }
 
  out:
 qemu_mutex_unlock(&s->port_lock);
 
 return ret;
 }
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index b3d054889b..c1fd0a966a 100644
--- a/hw/i386/x86.c
+++ b/hw/i

[RFC PATCH v2 44/78] hw/m68k/mcf_intc.c: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/m68k/mcf_intc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/m68k/mcf_intc.c b/hw/m68k/mcf_intc.c
index 4cd30188c0..9556a0ccb7 100644
--- a/hw/m68k/mcf_intc.c
+++ b/hw/m68k/mcf_intc.c
@@ -58,34 +58,34 @@ static void mcf_intc_update(mcf_intc_state *s)
 static uint64_t mcf_intc_read(void *opaque, hwaddr addr,
   unsigned size)
 {
 int offset;
 mcf_intc_state *s = (mcf_intc_state *)opaque;
 offset = addr & 0xff;
 if (offset >= 0x40 && offset < 0x80) {
 return s->icr[offset - 0x40];
 }
 switch (offset) {
 case 0x00:
 return (uint32_t)(s->ipr >> 32);
 case 0x04:
 return (uint32_t)s->ipr;
 case 0x08:
 return (uint32_t)(s->imr >> 32);
 case 0x0c:
 return (uint32_t)s->imr;
 case 0x10:
 return (uint32_t)(s->ifr >> 32);
 case 0x14:
 return (uint32_t)s->ifr;
 case 0xe0: /* SWIACK.  */
 return s->active_vector;
 case 0xe1: case 0xe2: case 0xe3: case 0xe4:
 case 0xe5: case 0xe6: case 0xe7:
 /* LnIACK */
 qemu_log_mask(LOG_UNIMP, "%s: LnIACK not implemented (offset 
0x%02x)\n",
   __func__, offset);
-/* fallthru */
+fallthrough;
 default:
 return 0;
 }
 }
-- 
2.39.2




[RFC PATCH v2 69/78] hw/rdma/rdma_backend.c: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/rdma/rdma_backend.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/rdma/rdma_backend.c b/hw/rdma/rdma_backend.c
index 6dcdfbbbe2..09e5ad961e 100644
--- a/hw/rdma/rdma_backend.c
+++ b/hw/rdma/rdma_backend.c
@@ -800,50 +800,50 @@ void rdma_backend_destroy_cq(RdmaBackendCQ *cq)
 int rdma_backend_create_qp(RdmaBackendQP *qp, uint8_t qp_type,
RdmaBackendPD *pd, RdmaBackendCQ *scq,
RdmaBackendCQ *rcq, RdmaBackendSRQ *srq,
uint32_t max_send_wr, uint32_t max_recv_wr,
uint32_t max_send_sge, uint32_t max_recv_sge)
 {
 struct ibv_qp_init_attr attr = {};
 
 qp->ibqp = 0;
 
 switch (qp_type) {
 case IBV_QPT_GSI:
 return 0;
 
 case IBV_QPT_RC:
-/* fall through */
+fallthrough;
 case IBV_QPT_UD:
 /* do nothing */
 break;
 
 default:
 rdma_error_report("Unsupported QP type %d", qp_type);
 return -EIO;
 }
 
 attr.qp_type = qp_type;
 attr.send_cq = scq->ibcq;
 attr.recv_cq = rcq->ibcq;
 attr.cap.max_send_wr = max_send_wr;
 attr.cap.max_recv_wr = max_recv_wr;
 attr.cap.max_send_sge = max_send_sge;
 attr.cap.max_recv_sge = max_recv_sge;
 if (srq) {
 attr.srq = srq->ibsrq;
 }
 
 qp->ibqp = ibv_create_qp(pd->ibpd, &attr);
 if (!qp->ibqp) {
 rdma_error_report("ibv_create_qp fail, errno=%d", errno);
 return -EIO;
 }
 
 rdma_protected_gslist_init(&qp->cqe_ctx_list);
 
 qp->ibpd = pd->ibpd;
 
 /* TODO: Query QP to get max_inline_data and save it to be used in send */
 
 return 0;
 }
-- 
2.39.2




[RFC PATCH v2 33/78] target/rx: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/rx/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/rx/translate.c b/target/rx/translate.c
index f8860830ae..b00c0a21fb 100644
--- a/target/rx/translate.c
+++ b/target/rx/translate.c
@@ -2232,24 +2232,24 @@ static void rx_tr_translate_insn(DisasContextBase 
*dcbase, CPUState *cs)
 static void rx_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
 {
 DisasContext *ctx = container_of(dcbase, DisasContext, base);
 
 switch (ctx->base.is_jmp) {
 case DISAS_NEXT:
 case DISAS_TOO_MANY:
 gen_goto_tb(ctx, 0, dcbase->pc_next);
 break;
 case DISAS_JUMP:
 tcg_gen_lookup_and_goto_ptr();
 break;
 case DISAS_UPDATE:
 tcg_gen_movi_i32(cpu_pc, ctx->base.pc_next);
-/* fall through */
+fallthrough;
 case DISAS_EXIT:
 tcg_gen_exit_tb(NULL, 0);
 break;
 case DISAS_NORETURN:
 break;
 default:
 g_assert_not_reached();
 }
 }
-- 
2.39.2




[RFC PATCH v2 20/78] target/mips: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/mips/sysemu/physaddr.c |  2 +-
 target/mips/tcg/micromips_translate.c.inc |  4 +-
 target/mips/tcg/mips16e_translate.c.inc   | 30 -
 target/mips/tcg/mxu_translate.c   |  8 +--
 target/mips/tcg/nanomips_translate.c.inc  |  4 +-
 target/mips/tcg/op_helper.c   |  2 +-
 target/mips/tcg/translate.c   | 79 ---
 7 files changed, 66 insertions(+), 63 deletions(-)

diff --git a/target/mips/sysemu/physaddr.c b/target/mips/sysemu/physaddr.c
index 05990aa5bb..ebcaeea1bc 100644
--- a/target/mips/sysemu/physaddr.c
+++ b/target/mips/sysemu/physaddr.c
@@ -24,52 +24,52 @@
 static int is_seg_am_mapped(unsigned int am, bool eu, int mmu_idx)
 {
 /*
  * Interpret access control mode and mmu_idx.
  *   AdE? TLB?
  *  AM  K S U E  K S U E
  * UK0  0 1 1 0  0 - - 0
  * MK1  0 1 1 0  1 - - !eu
  * MSK   2  0 0 1 0  1 1 - !eu
  * MUSK  3  0 0 0 0  1 1 1 !eu
  * MUSUK 4  0 0 0 0  0 1 1 0
  * USK   5  0 0 1 0  0 0 - 0
  * - 6  - - - -  - - - -
  * UUSK  7  0 0 0 0  0 0 0 0
  */
 int32_t adetlb_mask;
 
 switch (mmu_idx) {
 case 3: /* ERL */
 /* If EU is set, always unmapped */
 if (eu) {
 return 0;
 }
-/* fall through */
+fallthrough;
 case MIPS_HFLAG_KM:
 /* Never AdE, TLB mapped if AM={1,2,3} */
 adetlb_mask = 0x7000;
 goto check_tlb;
 
 case MIPS_HFLAG_SM:
 /* AdE if AM={0,1}, TLB mapped if AM={2,3,4} */
 adetlb_mask = 0xc038;
 goto check_ade;
 
 case MIPS_HFLAG_UM:
 /* AdE if AM={0,1,2,5}, TLB mapped if AM={3,4} */
 adetlb_mask = 0xe418;
 /* fall through */
 check_ade:
 /* does this AM cause AdE in current execution mode */
 if ((adetlb_mask << am) < 0) {
 return TLBRET_BADADDR;
 }
 adetlb_mask <<= 8;
 /* fall through */
 check_tlb:
 /* is this AM mapped in current execution mode */
 return ((adetlb_mask << am) < 0);
 default:
 g_assert_not_reached();
 };
 }
diff --git a/target/mips/tcg/micromips_translate.c.inc 
b/target/mips/tcg/micromips_translate.c.inc
index 7510831701..00e96ce27a 100644
--- a/target/mips/tcg/micromips_translate.c.inc
+++ b/target/mips/tcg/micromips_translate.c.inc
@@ -1621,1353 +1621,1353 @@ static void gen_pool32fxf(DisasContext *ctx, int 
rt, int rs)
 static void decode_micromips32_opc(CPUMIPSState *env, DisasContext *ctx)
 {
 int32_t offset;
 uint16_t insn;
 int rt, rs, rd, rr;
 int16_t imm;
 uint32_t op, minor, minor2, mips32_op;
 uint32_t cond, fmt, cc;
 
 insn = translator_lduw(env, &ctx->base, ctx->base.pc_next + 2);
 ctx->opcode = (ctx->opcode << 16) | insn;
 
 rt = (ctx->opcode >> 21) & 0x1f;
 rs = (ctx->opcode >> 16) & 0x1f;
 rd = (ctx->opcode >> 11) & 0x1f;
 rr = (ctx->opcode >> 6) & 0x1f;
 imm = (int16_t) ctx->opcode;
 
 op = (ctx->opcode >> 26) & 0x3f;
 switch (op) {
 case POOL32A:
 minor = ctx->opcode & 0x3f;
 switch (minor) {
 case 0x00:
 minor = (ctx->opcode >> 6) & 0xf;
 switch (minor) {
 case SLL32:
 mips32_op = OPC_SLL;
 goto do_shifti;
 case SRA:
 mips32_op = OPC_SRA;
 goto do_shifti;
 case SRL32:
 mips32_op = OPC_SRL;
 goto do_shifti;
 case ROTR:
 mips32_op = OPC_ROTR;
 do_shifti:
 gen_shift_imm(ctx, mips32_op, rt, rs, rd);
 break;
 case SELEQZ:
 check_insn(ctx, ISA_MIPS_R6);
 gen_cond_move(ctx, OPC_SELEQZ, rd, rs, rt);
 break;
 case SELNEZ:
 check_insn(ctx, ISA_MIPS_R6);
 gen_cond_move(ctx, OPC_SELNEZ, rd, rs, rt);
 break;
 case R6_RDHWR:
 check_insn(ctx, ISA_MIPS_R6);
 gen_rdhwr(ctx, rt, rs, extract32(ctx->opcode, 11, 3));
 break;
 default:
 goto pool32a_invalid;
 }
 break;
 case 0x10:
 minor = (ctx->opcode >> 6) & 0xf;
 switch (minor) {
 /* Arithmetic */
 case ADD:
 mips32_op = OPC_ADD;
 goto do_arith;
 case ADDU32:
 mips32_op = OPC_ADDU;
 goto do_arith;
 case SUB:
 mips32_op = OPC_SUB;
 goto do_arith;
 case SUBU32:
 mips32_op = OPC_SUBU;
 goto do

[RFC PATCH v2 27/78] target/riscv: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/riscv/insn_trans/trans_rvi.c.inc   |  2 +-
 target/riscv/insn_trans/trans_rvzce.c.inc | 22 +++---
 target/riscv/translate.c  |  4 ++--
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/target/riscv/insn_trans/trans_rvi.c.inc 
b/target/riscv/insn_trans/trans_rvi.c.inc
index 25cb60558a..98dd2e3cf6 100644
--- a/target/riscv/insn_trans/trans_rvi.c.inc
+++ b/target/riscv/insn_trans/trans_rvi.c.inc
@@ -89,61 +89,61 @@ static bool trans_jalr(DisasContext *ctx, arg_jalr *a)
 static TCGCond gen_compare_i128(bool bz, TCGv rl,
 TCGv al, TCGv ah, TCGv bl, TCGv bh,
 TCGCond cond)
 {
 TCGv rh = tcg_temp_new();
 bool invert = false;
 
 switch (cond) {
 case TCG_COND_EQ:
 case TCG_COND_NE:
 if (bz) {
 tcg_gen_or_tl(rl, al, ah);
 } else {
 tcg_gen_xor_tl(rl, al, bl);
 tcg_gen_xor_tl(rh, ah, bh);
 tcg_gen_or_tl(rl, rl, rh);
 }
 break;
 
 case TCG_COND_GE:
 case TCG_COND_LT:
 if (bz) {
 tcg_gen_mov_tl(rl, ah);
 } else {
 TCGv tmp = tcg_temp_new();
 
 tcg_gen_sub2_tl(rl, rh, al, ah, bl, bh);
 tcg_gen_xor_tl(rl, rh, ah);
 tcg_gen_xor_tl(tmp, ah, bh);
 tcg_gen_and_tl(rl, rl, tmp);
 tcg_gen_xor_tl(rl, rh, rl);
 }
 break;
 
 case TCG_COND_LTU:
 invert = true;
-/* fallthrough */
+fallthrough;
 case TCG_COND_GEU:
 {
 TCGv tmp = tcg_temp_new();
 TCGv zero = tcg_constant_tl(0);
 TCGv one = tcg_constant_tl(1);
 
 cond = TCG_COND_NE;
 /* borrow in to second word */
 tcg_gen_setcond_tl(TCG_COND_LTU, tmp, al, bl);
 /* seed third word with 1, which will be result */
 tcg_gen_sub2_tl(tmp, rh, ah, one, tmp, zero);
 tcg_gen_sub2_tl(tmp, rl, tmp, rh, bh, zero);
 }
 break;
 
 default:
 g_assert_not_reached();
 }
 
 if (invert) {
 cond = tcg_invert_cond(cond);
 }
 return cond;
 }
diff --git a/target/riscv/insn_trans/trans_rvzce.c.inc 
b/target/riscv/insn_trans/trans_rvzce.c.inc
index 2d992e14c4..f0bcbb4f72 100644
--- a/target/riscv/insn_trans/trans_rvzce.c.inc
+++ b/target/riscv/insn_trans/trans_rvzce.c.inc
@@ -116,52 +116,52 @@ static bool trans_c_sh(DisasContext *ctx, arg_c_sh *a)
 static uint32_t decode_push_pop_list(DisasContext *ctx, target_ulong rlist)
 {
 uint32_t reg_bitmap = 0;
 
 if (has_ext(ctx, RVE) && rlist > 6) {
 return 0;
 }
 
 switch (rlist) {
 case 15:
 reg_bitmap |=  1 << (X_Sn + 11) ;
 reg_bitmap |=  1 << (X_Sn + 10) ;
-/* FALL THROUGH */
+fallthrough;
 case 14:
 reg_bitmap |=  1 << (X_Sn + 9) ;
-/* FALL THROUGH */
+fallthrough;
 case 13:
 reg_bitmap |=  1 << (X_Sn + 8) ;
-/* FALL THROUGH */
+fallthrough;
 case 12:
 reg_bitmap |=  1 << (X_Sn + 7) ;
-/* FALL THROUGH */
+fallthrough;
 case 11:
 reg_bitmap |=  1 << (X_Sn + 6) ;
-/* FALL THROUGH */
+fallthrough;
 case 10:
 reg_bitmap |=  1 << (X_Sn + 5) ;
-/* FALL THROUGH */
+fallthrough;
 case 9:
 reg_bitmap |=  1 << (X_Sn + 4) ;
-/* FALL THROUGH */
+fallthrough;
 case 8:
 reg_bitmap |=  1 << (X_Sn + 3) ;
-/* FALL THROUGH */
+fallthrough;
 case 7:
 reg_bitmap |=  1 << (X_Sn + 2) ;
-/* FALL THROUGH */
+fallthrough;
 case 6:
 reg_bitmap |=  1 << X_S1 ;
-/* FALL THROUGH */
+fallthrough;
 case 5:
 reg_bitmap |= 1 << X_S0;
-/* FALL THROUGH */
+fallthrough;
 case 4:
 reg_bitmap |= 1 << xRA;
 break;
 default:
 break;
 }
 
 return reg_bitmap;
 }
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
index f0be79bb16..c99e513221 100644
--- a/target/riscv/translate.c
+++ b/target/riscv/translate.c
@@ -431,26 +431,26 @@ static void gen_set_gpr128(DisasContext *ctx, int 
reg_num, TCGv rl, TCGv rh)
 static TCGv_i64 get_fpr_hs(DisasContext *ctx, int reg_num)
 {
 if (!ctx->cfg_ptr->ext_zfinx) {
 return cpu_fpr[reg_num];
 }
 
 if (reg_num == 0) {
 return tcg_constant_i64(0);
 }
 switch (get_xl(ctx)) {
 case MXL_RV32:
 #ifdef TARGET_RISCV32
 {
 TCGv_i64 t = tcg_temp_new_i64();
 tcg_gen_ext_i32_i64(t, cpu_gpr[reg_num]);
 return t;
 }
 #else
-/* fall through */
+fallthrough;
 case MXL_RV64:
 return cpu_gpr[reg_nu

[RFC PATCH v2 53/78] nbd: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 nbd/client.c | 4 ++--
 nbd/common.c | 2 +-
 qemu-nbd.c   | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/nbd/client.c b/nbd/client.c
index 29ffc609a4..04507249b2 100644
--- a/nbd/client.c
+++ b/nbd/client.c
@@ -1014,102 +1014,102 @@ static int nbd_negotiate_finish_oldstyle(QIOChannel 
*ioc, NBDExportInfo *info,
 /*
  * nbd_receive_negotiate:
  * Connect to server, complete negotiation, and move into transmission phase.
  * Returns: negative errno: failure talking to server
  *  0: server is connected
  */
 int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
   const char *hostname, QIOChannel **outioc,
   NBDExportInfo *info, Error **errp)
 {
 ERRP_GUARD();
 int result;
 bool zeroes;
 bool base_allocation = info->base_allocation;
 
 assert(info->name && strlen(info->name) <= NBD_MAX_STRING_SIZE);
 trace_nbd_receive_negotiate_name(info->name);
 
 result = nbd_start_negotiate(ioc, tlscreds, hostname, outioc,
  info->mode, &zeroes, errp);
 if (result < 0) {
 return result;
 }
 
 info->mode = result;
 info->base_allocation = false;
 if (tlscreds && *outioc) {
 ioc = *outioc;
 }
 
 switch (info->mode) {
 case NBD_MODE_EXTENDED:
 case NBD_MODE_STRUCTURED:
 if (base_allocation) {
 result = nbd_negotiate_simple_meta_context(ioc, info, errp);
 if (result < 0) {
 return -EINVAL;
 }
 info->base_allocation = result == 1;
 }
-/* fall through */
+fallthrough;
 case NBD_MODE_SIMPLE:
 /* Try NBD_OPT_GO first - if it works, we are done (it
  * also gives us a good message if the server requires
  * TLS).  If it is not available, fall back to
  * NBD_OPT_LIST for nicer error messages about a missing
  * export, then use NBD_OPT_EXPORT_NAME.  */
 result = nbd_opt_info_or_go(ioc, NBD_OPT_GO, info, errp);
 if (result < 0) {
 return -EINVAL;
 }
 if (result > 0) {
 return 0;
 }
 /* Check our desired export is present in the
  * server export list. Since NBD_OPT_EXPORT_NAME
  * cannot return an error message, running this
  * query gives us better error reporting if the
  * export name is not available.
  */
 if (nbd_receive_query_exports(ioc, info->name, errp) < 0) {
 return -EINVAL;
 }
-/* fall through */
+fallthrough;
 case NBD_MODE_EXPORT_NAME:
 /* write the export name request */
 if (nbd_send_option_request(ioc, NBD_OPT_EXPORT_NAME, -1, info->name,
 errp) < 0) {
 return -EINVAL;
 }
 
 /* Read the response */
 if (nbd_read64(ioc, &info->size, "export length", errp) < 0) {
 return -EINVAL;
 }
 
 if (nbd_read16(ioc, &info->flags, "export flags", errp) < 0) {
 return -EINVAL;
 }
 break;
 case NBD_MODE_OLDSTYLE:
 if (*info->name) {
 error_setg(errp, "Server does not support non-empty export names");
 return -EINVAL;
 }
 if (nbd_negotiate_finish_oldstyle(ioc, info, errp) < 0) {
 return -EINVAL;
 }
 break;
 default:
 g_assert_not_reached();
 }
 
 trace_nbd_receive_negotiate_size_flags(info->size, info->flags);
 if (zeroes && nbd_drop(ioc, 124, errp) < 0) {
 error_prepend(errp, "Failed to read reserved block: ");
 return -EINVAL;
 }
 return 0;
 }
 
 /* Clean up result of nbd_receive_export_list */
diff --git a/nbd/common.c b/nbd/common.c
index 3247c1d618..1140ea0888 100644
--- a/nbd/common.c
+++ b/nbd/common.c
@@ -222,37 +222,37 @@ const char *nbd_err_lookup(int err)
 int nbd_errno_to_system_errno(int err)
 {
 int ret;
 switch (err) {
 case NBD_SUCCESS:
 ret = 0;
 break;
 case NBD_EPERM:
 ret = EPERM;
 break;
 case NBD_EIO:
 ret = EIO;
 break;
 case NBD_ENOMEM:
 ret = ENOMEM;
 break;
 case NBD_ENOSPC:
 ret = ENOSPC;
 break;
 case NBD_EOVERFLOW:
 ret = EOVERFLOW;
 break;
 case NBD_ENOTSUP:
 ret = ENOTSUP;
 break;
 case NBD_ESHUTDOWN:
 ret = ESHUTDOWN;
 break;
 default:
 trace_nbd_unknown_error(err);
-/* fallthrough */
+fallthrough;
 case NBD_EINVAL:
 ret = EINVAL;
 break;
 }
 return ret;
 }
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 186e6468b1..41e50208a5 100644
--- 

[RFC PATCH v2 31/78] target/xtensa: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/xtensa/op_helper.c | 8 
 target/xtensa/translate.c | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/target/xtensa/op_helper.c b/target/xtensa/op_helper.c
index 7bb8cd6726..69b72f474d 100644
--- a/target/xtensa/op_helper.c
+++ b/target/xtensa/op_helper.c
@@ -73,58 +73,58 @@ void HELPER(update_ccompare)(CPUXtensaState *env, uint32_t 
i)
 /*!
  * Check vaddr accessibility/cache attributes and raise an exception if
  * specified by the ATOMCTL SR.
  *
  * Note: local memory exclusion is not implemented
  */
 void HELPER(check_atomctl)(CPUXtensaState *env, uint32_t pc, uint32_t vaddr)
 {
 uint32_t paddr, page_size, access;
 uint32_t atomctl = env->sregs[ATOMCTL];
 int rc = xtensa_get_physical_addr(env, true, vaddr, 1,
 xtensa_get_cring(env), &paddr, &page_size, &access);
 
 /*
  * s32c1i never causes LOAD_PROHIBITED_CAUSE exceptions,
  * see opcode description in the ISA
  */
 if (rc == 0 &&
 (access & (PAGE_READ | PAGE_WRITE)) != (PAGE_READ | PAGE_WRITE)) {
 rc = STORE_PROHIBITED_CAUSE;
 }
 
 if (rc) {
 HELPER(exception_cause_vaddr)(env, pc, rc, vaddr);
 }
 
 /*
  * When data cache is not configured use ATOMCTL bypass field.
  * See ISA, 4.3.12.4 The Atomic Operation Control Register (ATOMCTL)
  * under the Conditional Store Option.
  */
 if (!xtensa_option_enabled(env->config, XTENSA_OPTION_DCACHE)) {
 access = PAGE_CACHE_BYPASS;
 }
 
 switch (access & PAGE_CACHE_MASK) {
 case PAGE_CACHE_WB:
 atomctl >>= 2;
-/* fall through */
+fallthrough;
 case PAGE_CACHE_WT:
 atomctl >>= 2;
-/* fall through */
+fallthrough;
 case PAGE_CACHE_BYPASS:
 if ((atomctl & 0x3) == 0) {
 HELPER(exception_cause_vaddr)(env, pc,
 LOAD_STORE_ERROR_CAUSE, vaddr);
 }
 break;
 
 case PAGE_CACHE_ISOLATE:
 HELPER(exception_cause_vaddr)(env, pc,
 LOAD_STORE_ERROR_CAUSE, vaddr);
 break;
 
 default:
 break;
 }
 }
@@ -132,41 +132,41 @@ void HELPER(check_atomctl)(CPUXtensaState *env, uint32_t 
pc, uint32_t vaddr)
 void HELPER(check_exclusive)(CPUXtensaState *env, uint32_t pc, uint32_t vaddr,
  uint32_t is_write)
 {
 uint32_t paddr, page_size, access;
 uint32_t atomctl = env->sregs[ATOMCTL];
 int rc = xtensa_get_physical_addr(env, true, vaddr, is_write,
   xtensa_get_cring(env), &paddr,
   &page_size, &access);
 
 if (rc) {
 HELPER(exception_cause_vaddr)(env, pc, rc, vaddr);
 }
 
 /* When data cache is not configured use ATOMCTL bypass field. */
 if (!xtensa_option_enabled(env->config, XTENSA_OPTION_DCACHE)) {
 access = PAGE_CACHE_BYPASS;
 }
 
 switch (access & PAGE_CACHE_MASK) {
 case PAGE_CACHE_WB:
 atomctl >>= 2;
-/* fall through */
+fallthrough;
 case PAGE_CACHE_WT:
 atomctl >>= 2;
-/* fall through */
+fallthrough;
 case PAGE_CACHE_BYPASS:
 if ((atomctl & 0x3) == 0) {
 HELPER(exception_cause_vaddr)(env, pc,
   EXCLUSIVE_ERROR_CAUSE, vaddr);
 }
 break;
 
 case PAGE_CACHE_ISOLATE:
 HELPER(exception_cause_vaddr)(env, pc,
 LOAD_STORE_ERROR_CAUSE, vaddr);
 break;
 
 default:
 break;
 }
 }
diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c
index 54bee7ddba..8ef940933c 100644
--- a/target/xtensa/translate.c
+++ b/target/xtensa/translate.c
@@ -795,24 +795,24 @@ again:
 static void opcode_add_resource(struct slot_prop *op,
 uint32_t resource, char direction,
 int index)
 {
 switch (direction) {
 case 'm':
 case 'i':
 assert(op->n_in < ARRAY_SIZE(op->in));
 op->in[op->n_in].resource = resource;
 op->in[op->n_in].index = index;
 ++op->n_in;
-/* fall through */
+fallthrough;
 case 'o':
 if (direction == 'm' || direction == 'o') {
 assert(op->n_out < ARRAY_SIZE(op->out));
 op->out[op->n_out].resource = resource;
 op->out[op->n_out].index = index;
 ++op->n_out;
 }
 break;
 default:
 g_assert_not_reached();
 }
 }
-- 
2.39.2




[RFC PATCH v2 36/78] target/openrisc: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/openrisc/mmu.c   | 2 +-
 target/openrisc/translate.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/openrisc/mmu.c b/target/openrisc/mmu.c
index 603c26715e..7ed744e81b 100644
--- a/target/openrisc/mmu.c
+++ b/target/openrisc/mmu.c
@@ -141,38 +141,38 @@ bool openrisc_cpu_tlb_fill(CPUState *cs, vaddr addr, int 
size,
 hwaddr openrisc_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
 {
 OpenRISCCPU *cpu = OPENRISC_CPU(cs);
 int prot, excp, sr = cpu->env.sr;
 hwaddr phys_addr;
 
 switch (sr & (SR_DME | SR_IME)) {
 case SR_DME | SR_IME:
 /* The mmu is definitely enabled.  */
 excp = get_phys_mmu(cpu, &phys_addr, &prot, addr,
 PAGE_READ,
 (sr & SR_SM) != 0);
 if (!excp) {
 return phys_addr;
 }
 excp = get_phys_mmu(cpu, &phys_addr, &prot, addr,
 PAGE_EXEC,
 (sr & SR_SM) != 0);
 return excp ? -1 : phys_addr;
 
 default:
 /* The mmu is partially enabled, and we don't really have
a "real" access type.  Begin by trying the mmu, but if
that fails try again without.  */
 excp = get_phys_mmu(cpu, &phys_addr, &prot, addr,
 PAGE_EXEC | PAGE_READ | PAGE_WRITE,
 (sr & SR_SM) != 0);
 if (!excp) {
 return phys_addr;
 }
-/* fallthru */
+fallthrough;
 
 case 0:
 /* The mmu is definitely disabled; lookups never fail.  */
 get_phys_nommu(&phys_addr, &prot, addr);
 return phys_addr;
 }
 }
diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c
index ecff4412b7..de77014d60 100644
--- a/target/openrisc/translate.c
+++ b/target/openrisc/translate.c
@@ -1588,53 +1588,53 @@ static void openrisc_tr_translate_insn(DisasContextBase 
*dcbase, CPUState *cs)
 static void openrisc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
 {
 DisasContext *dc = container_of(dcbase, DisasContext, base);
 target_ulong jmp_dest;
 
 /* If we have already exited the TB, nothing following has effect.  */
 if (dc->base.is_jmp == DISAS_NORETURN) {
 return;
 }
 
 /* Adjust the delayed branch state for the next TB.  */
 if ((dc->tb_flags & TB_FLAGS_DFLAG ? 1 : 0) != (dc->delayed_branch != 0)) {
 tcg_gen_movi_i32(cpu_dflag, dc->delayed_branch != 0);
 }
 
 /* For DISAS_TOO_MANY, jump to the next insn.  */
 jmp_dest = dc->base.pc_next;
 tcg_gen_movi_tl(cpu_ppc, jmp_dest - 4);
 
 switch (dc->base.is_jmp) {
 case DISAS_JUMP:
 jmp_dest = dc->jmp_pc_imm;
 if (jmp_dest == -1) {
 /* The jump destination is indirect/computed; use jmp_pc.  */
 tcg_gen_mov_tl(cpu_pc, jmp_pc);
 tcg_gen_discard_tl(jmp_pc);
 tcg_gen_lookup_and_goto_ptr();
 break;
 }
 /* The jump destination is direct; use jmp_pc_imm.
However, we will have stored into jmp_pc as well;
we know now that it wasn't needed.  */
 tcg_gen_discard_tl(jmp_pc);
-/* fallthru */
+fallthrough;
 
 case DISAS_TOO_MANY:
 if (translator_use_goto_tb(&dc->base, jmp_dest)) {
 tcg_gen_goto_tb(0);
 tcg_gen_movi_tl(cpu_pc, jmp_dest);
 tcg_gen_exit_tb(dc->base.tb, 0);
 break;
 }
 tcg_gen_movi_tl(cpu_pc, jmp_dest);
 tcg_gen_lookup_and_goto_ptr();
 break;
 
 case DISAS_EXIT:
 tcg_gen_exit_tb(NULL, 0);
 break;
 default:
 g_assert_not_reached();
 }
 }
-- 
2.39.2




[RFC PATCH 41/75] hw/i386: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/i386/intel_iommu.c| 4 ++--
 hw/i386/kvm/xen_evtchn.c | 2 +-
 hw/i386/x86.c| 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 2c832ab68b..bdb2ea3ac5 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -2100,29 +2100,29 @@ static void 
vtd_context_device_invalidate(IntelIOMMUState *s,
 /* Context-cache invalidation
  * Returns the Context Actual Invalidation Granularity.
  * @val: the content of the CCMD_REG
  */
 static uint64_t vtd_context_cache_invalidate(IntelIOMMUState *s, uint64_t val)
 {
 uint64_t caig;
 uint64_t type = val & VTD_CCMD_CIRG_MASK;
 
 switch (type) {
 case VTD_CCMD_DOMAIN_INVL:
-/* Fall through */
+fallthrough;
 case VTD_CCMD_GLOBAL_INVL:
 caig = VTD_CCMD_GLOBAL_INVL_A;
 vtd_context_global_invalidate(s);
 break;
 
 case VTD_CCMD_DEVICE_INVL:
 caig = VTD_CCMD_DEVICE_INVL_A;
 vtd_context_device_invalidate(s, VTD_CCMD_SID(val), VTD_CCMD_FM(val));
 break;
 
 default:
 error_report_once("%s: invalid context: 0x%" PRIx64,
   __func__, val);
 caig = 0;
 }
 return caig;
 }
@@ -2513,34 +2513,34 @@ static bool vtd_process_wait_desc(IntelIOMMUState *s, 
VTDInvDesc *inv_desc)
 static bool vtd_process_context_cache_desc(IntelIOMMUState *s,
VTDInvDesc *inv_desc)
 {
 uint16_t sid, fmask;
 
 if ((inv_desc->lo & VTD_INV_DESC_CC_RSVD) || inv_desc->hi) {
 error_report_once("%s: invalid cc inv desc: hi=%"PRIx64", lo=%"PRIx64
   " (reserved nonzero)", __func__, inv_desc->hi,
   inv_desc->lo);
 return false;
 }
 switch (inv_desc->lo & VTD_INV_DESC_CC_G) {
 case VTD_INV_DESC_CC_DOMAIN:
 trace_vtd_inv_desc_cc_domain(
 (uint16_t)VTD_INV_DESC_CC_DID(inv_desc->lo));
-/* Fall through */
+fallthrough;
 case VTD_INV_DESC_CC_GLOBAL:
 vtd_context_global_invalidate(s);
 break;
 
 case VTD_INV_DESC_CC_DEVICE:
 sid = VTD_INV_DESC_CC_SID(inv_desc->lo);
 fmask = VTD_INV_DESC_CC_FM(inv_desc->lo);
 vtd_context_device_invalidate(s, sid, fmask);
 break;
 
 default:
 error_report_once("%s: invalid cc inv desc: hi=%"PRIx64", lo=%"PRIx64
   " (invalid type)", __func__, inv_desc->hi,
   inv_desc->lo);
 return false;
 }
 return true;
 }
diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c
index a731738411..d15e324f6e 100644
--- a/hw/i386/kvm/xen_evtchn.c
+++ b/hw/i386/kvm/xen_evtchn.c
@@ -2028,71 +2028,71 @@ static int find_be_port(XenEvtchnState *s, struct 
xenevtchn_handle *xc)
 int xen_be_evtchn_bind_interdomain(struct xenevtchn_handle *xc, uint32_t domid,
evtchn_port_t guest_port)
 {
 XenEvtchnState *s = xen_evtchn_singleton;
 XenEvtchnPort *gp;
 uint16_t be_port = 0;
 int ret;
 
 if (!s) {
 return -ENOTSUP;
 }
 
 if (!xc) {
 return -EFAULT;
 }
 
 if (domid != xen_domid) {
 return -ESRCH;
 }
 
 if (!valid_port(guest_port)) {
 return -EINVAL;
 }
 
 qemu_mutex_lock(&s->port_lock);
 
 /* The guest has to have an unbound port waiting for us to bind */
 gp = &s->port_table[guest_port];
 
 switch (gp->type) {
 case EVTCHNSTAT_interdomain:
 /* Allow rebinding after migration, preserve port # if possible */
 be_port = gp->type_val & ~PORT_INFO_TYPEVAL_REMOTE_QEMU;
 assert(be_port != 0);
 if (!s->be_handles[be_port]) {
 s->be_handles[be_port] = xc;
 xc->guest_port = guest_port;
 ret = xc->be_port = be_port;
 if (kvm_xen_has_cap(EVTCHN_SEND)) {
 assign_kernel_eventfd(gp->type, guest_port, xc->fd);
 }
 break;
 }
-/* fall through */
+fallthrough;
 
 case EVTCHNSTAT_unbound:
 be_port = find_be_port(s, xc);
 if (!be_port) {
 ret = -ENOSPC;
 goto out;
 }
 
 gp->type = EVTCHNSTAT_interdomain;
 gp->type_val = be_port | PORT_INFO_TYPEVAL_REMOTE_QEMU;
 xc->guest_port = guest_port;
 if (kvm_xen_has_cap(EVTCHN_SEND)) {
 assign_kernel_eventfd(gp->type, guest_port, xc->fd);
 }
 ret = be_port;
 break;
 
 default:
 ret = -EINVAL;
 break;
 }
 
  out:
 qemu_mutex_unlock(&s->port_lock);
 
 return ret;
 }
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index b3d054889b..c1fd0a966a 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -597,32 +597,32 @@ DeviceState *cpu_get_current_apic(void)
 void gsi_handler(void *opaque, int n, int level)
 {
 GSIStat

[RFC PATCH v2 24/78] target/alpha: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/alpha/helper.c| 6 +++---
 target/alpha/translate.c | 4 +++-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/target/alpha/helper.c b/target/alpha/helper.c
index 970c869771..1afdc1beec 100644
--- a/target/alpha/helper.c
+++ b/target/alpha/helper.c
@@ -436,45 +436,45 @@ void alpha_cpu_do_interrupt(CPUState *cs)
 bool alpha_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
 {
 AlphaCPU *cpu = ALPHA_CPU(cs);
 CPUAlphaState *env = &cpu->env;
 int idx = -1;
 
 /* We never take interrupts while in PALmode.  */
 if (env->flags & ENV_FLAG_PAL_MODE) {
 return false;
 }
 
 /* Fall through the switch, collecting the highest priority
interrupt that isn't masked by the processor status IPL.  */
 /* ??? This hard-codes the OSF/1 interrupt levels.  */
 switch ((env->flags >> ENV_FLAG_PS_SHIFT) & PS_INT_MASK) {
 case 0 ... 3:
 if (interrupt_request & CPU_INTERRUPT_HARD) {
 idx = EXCP_DEV_INTERRUPT;
 }
-/* FALLTHRU */
+fallthrough;
 case 4:
 if (interrupt_request & CPU_INTERRUPT_TIMER) {
 idx = EXCP_CLK_INTERRUPT;
 }
-/* FALLTHRU */
+fallthrough;
 case 5:
 if (interrupt_request & CPU_INTERRUPT_SMP) {
 idx = EXCP_SMP_INTERRUPT;
 }
-/* FALLTHRU */
+fallthrough;
 case 6:
 if (interrupt_request & CPU_INTERRUPT_MCHK) {
 idx = EXCP_MCHK;
 }
 }
 if (idx >= 0) {
 cs->exception_index = idx;
 env->error_code = 0;
 alpha_cpu_do_interrupt(cs);
 return true;
 }
 return false;
 }
 
 #endif /* !CONFIG_USER_ONLY */
diff --git a/target/alpha/translate.c b/target/alpha/translate.c
index 32333081d8..19e1d2ed86 100644
--- a/target/alpha/translate.c
+++ b/target/alpha/translate.c
@@ -1377,1493 +1377,1493 @@ static DisasJumpType gen_mtpr(DisasContext *ctx, 
TCGv vb, int regno)
 static DisasJumpType translate_one(DisasContext *ctx, uint32_t insn)
 {
 int32_t disp21, disp16, disp12 __attribute__((unused));
 uint16_t fn11;
 uint8_t opc, ra, rb, rc, fpfn, fn7, lit;
 bool islit, real_islit;
 TCGv va, vb, vc, tmp, tmp2;
 TCGv_i32 t32;
 DisasJumpType ret;
 
 /* Decode all instruction fields */
 opc = extract32(insn, 26, 6);
 ra = extract32(insn, 21, 5);
 rb = extract32(insn, 16, 5);
 rc = extract32(insn, 0, 5);
 real_islit = islit = extract32(insn, 12, 1);
 lit = extract32(insn, 13, 8);
 
 disp21 = sextract32(insn, 0, 21);
 disp16 = sextract32(insn, 0, 16);
 disp12 = sextract32(insn, 0, 12);
 
 fn11 = extract32(insn, 5, 11);
 fpfn = extract32(insn, 5, 6);
 fn7 = extract32(insn, 5, 7);
 
 if (rb == 31 && !islit) {
 islit = true;
 lit = 0;
 }
 
 ret = DISAS_NEXT;
 switch (opc) {
 case 0x00:
 /* CALL_PAL */
 ret = gen_call_pal(ctx, insn & 0x03ff);
 break;
 case 0x01:
 /* OPC01 */
 goto invalid_opc;
 case 0x02:
 /* OPC02 */
 goto invalid_opc;
 case 0x03:
 /* OPC03 */
 goto invalid_opc;
 case 0x04:
 /* OPC04 */
 goto invalid_opc;
 case 0x05:
 /* OPC05 */
 goto invalid_opc;
 case 0x06:
 /* OPC06 */
 goto invalid_opc;
 case 0x07:
 /* OPC07 */
 goto invalid_opc;
 
 case 0x09:
 /* LDAH */
 disp16 = (uint32_t)disp16 << 16;
-/* fall through */
+fallthrough;
 case 0x08:
 /* LDA */
 va = dest_gpr(ctx, ra);
 /* It's worth special-casing immediate loads.  */
 if (rb == 31) {
 tcg_gen_movi_i64(va, disp16);
 } else {
 tcg_gen_addi_i64(va, load_gpr(ctx, rb), disp16);
 }
 break;
 
 case 0x0A:
 /* LDBU */
 REQUIRE_AMASK(BWX);
 gen_load_int(ctx, ra, rb, disp16, MO_UB, 0, 0);
 break;
 case 0x0B:
 /* LDQ_U */
 gen_load_int(ctx, ra, rb, disp16, MO_LEUQ, 1, 0);
 break;
 case 0x0C:
 /* LDWU */
 REQUIRE_AMASK(BWX);
 gen_load_int(ctx, ra, rb, disp16, MO_LEUW, 0, 0);
 break;
 case 0x0D:
 /* STW */
 REQUIRE_AMASK(BWX);
 gen_store_int(ctx, ra, rb, disp16, MO_LEUW, 0);
 break;
 case 0x0E:
 /* STB */
 REQUIRE_AMASK(BWX);
 gen_store_int(ctx, ra, rb, disp16, MO_UB, 0);
 break;
 case 0x0F:
 /* STQ_U */
 gen_store_int(ctx, ra, rb, disp16, MO_LEUQ, 1);
 break;
 
 case 0x10:
 vc = dest_gpr(ctx, rc);
 vb = load_gpr_lit(ctx, rb, lit, islit);
 
 if (ra == 31) {
 if (fn7 == 0x00) {

[RFC PATCH v2 05/78] qobject/json: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 qobject/json-lexer.c  | 4 ++--
 qobject/json-parser.c | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c
index 51341d96e4..ab74470ac6 100644
--- a/qobject/json-lexer.c
+++ b/qobject/json-lexer.c
@@ -283,61 +283,61 @@ void json_lexer_init(JSONLexer *lexer, bool 
enable_interpolation)
 static void json_lexer_feed_char(JSONLexer *lexer, char ch, bool flush)
 {
 int new_state;
 bool char_consumed = false;
 
 lexer->x++;
 if (ch == '\n') {
 lexer->x = 0;
 lexer->y++;
 }
 
 while (flush ? lexer->state != lexer->start_state : !char_consumed) {
 new_state = next_state(lexer, ch, flush, &char_consumed);
 if (char_consumed) {
 assert(!flush);
 g_string_append_c(lexer->token, ch);
 }
 
 switch (new_state) {
 case JSON_LCURLY:
 case JSON_RCURLY:
 case JSON_LSQUARE:
 case JSON_RSQUARE:
 case JSON_COLON:
 case JSON_COMMA:
 case JSON_INTERP:
 case JSON_INTEGER:
 case JSON_FLOAT:
 case JSON_KEYWORD:
 case JSON_STRING:
 json_message_process_token(lexer, lexer->token, new_state,
lexer->x, lexer->y);
-/* fall through */
+fallthrough;
 case IN_START:
 g_string_truncate(lexer->token, 0);
 new_state = lexer->start_state;
 break;
 case JSON_ERROR:
 json_message_process_token(lexer, lexer->token, JSON_ERROR,
lexer->x, lexer->y);
 new_state = IN_RECOVERY;
-/* fall through */
+fallthrough;
 case IN_RECOVERY:
 g_string_truncate(lexer->token, 0);
 break;
 default:
 break;
 }
 lexer->state = new_state;
 }
 
 /* Do not let a single token grow to an arbitrarily large size,
  * this is a security consideration.
  */
 if (lexer->token->len > MAX_TOKEN_SIZE) {
 json_message_process_token(lexer, lexer->token, lexer->state,
lexer->x, lexer->y);
 g_string_truncate(lexer->token, 0);
 lexer->state = lexer->start_state;
 }
 }
diff --git a/qobject/json-parser.c b/qobject/json-parser.c
index d498db6e70..4dc622dcc9 100644
--- a/qobject/json-parser.c
+++ b/qobject/json-parser.c
@@ -95,137 +95,137 @@ static int cvt4hex(const char *s)
 /**
  * parse_string(): Parse a JSON string
  *
  * From RFC 8259 "The JavaScript Object Notation (JSON) Data
  * Interchange Format":
  *
  *char = unescaped /
  *escape (
  *%x22 /  ; "quotation mark  U+0022
  *%x5C /  ; \reverse solidus U+005C
  *%x2F /  ; /solidus U+002F
  *%x62 /  ; bbackspace   U+0008
  *%x66 /  ; fform feed   U+000C
  *%x6E /  ; nline feed   U+000A
  *%x72 /  ; rcarriage return U+000D
  *%x74 /  ; ttab U+0009
  *%x75 4HEXDIG )  ; uU+
  *escape = %x5C  ; \
  *quotation-mark = %x22  ; "
  *unescaped = %x20-21 / %x23-5B / %x5D-10
  *
  * Extensions over RFC 8259:
  * - Extra escape sequence in strings:
  *   0x27 (apostrophe) is recognized after escape, too
  * - Single-quoted strings:
  *   Like double-quoted strings, except they're delimited by %x27
  *   (apostrophe) instead of %x22 (quotation mark), and can't contain
  *   unescaped apostrophe, but can contain unescaped quotation mark.
  *
  * Note:
  * - Encoding is modified UTF-8.
  * - Invalid Unicode characters are rejected.
  * - Control characters \x00..\x1F are rejected by the lexer.
  */
 static QString *parse_string(JSONParserContext *ctxt, JSONToken *token)
 {
 const char *ptr = token->str;
 GString *str;
 char quote;
 const char *beg;
 int cp, trailing;
 char *end;
 ssize_t len;
 char utf8_buf[5];
 
 assert(*ptr == '"' || *ptr == '\'');
 quote = *ptr++;
 str = g_string_new(NULL);
 
 while (*ptr != quote) {
 assert(*ptr);
 switch (*ptr) {
 case '\\':
 beg = ptr++;
 switch (*ptr++) {
 case '"':
 g_string_append_c(str, '"');
 break;
 case '\'':
 g_string_append_c(str, '\'');
 break;
 case '\\':
 g_string_append_c(str, '\\');
 break;
 case '/':
 g_string_append_c(str, '/');
 break;
  

[RFC PATCH v2 55/78] hw/display: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/display/cg3.c| 2 +-
 hw/display/cirrus_vga.c | 2 +-
 hw/display/tcx.c| 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/display/cg3.c b/hw/display/cg3.c
index 2e9656ae1c..53eb9831b2 100644
--- a/hw/display/cg3.c
+++ b/hw/display/cg3.c
@@ -199,65 +199,65 @@ static uint64_t cg3_reg_read(void *opaque, hwaddr addr, 
unsigned size)
 static void cg3_reg_write(void *opaque, hwaddr addr, uint64_t val,
   unsigned size)
 {
 CG3State *s = opaque;
 uint8_t regval;
 int i;
 
 trace_cg3_write(addr, val, size);
 switch (addr) {
 case CG3_REG_BT458_ADDR:
 s->dac_index = val;
 s->dac_state = 0;
 break;
 case CG3_REG_BT458_COLMAP:
 /* This register can be written to as either a long word or a byte */
 if (size == 1) {
 val <<= 24;
 }
 
 for (i = 0; i < size; i++) {
 regval = val >> 24;
 
 switch (s->dac_state) {
 case 0:
 s->r[s->dac_index] = regval;
 s->dac_state++;
 break;
 case 1:
 s->g[s->dac_index] = regval;
 s->dac_state++;
 break;
 case 2:
 s->b[s->dac_index] = regval;
 /* Index autoincrement */
 s->dac_index = (s->dac_index + 1) & 0xff;
-/* fall through */
+fallthrough;
 default:
 s->dac_state = 0;
 break;
 }
 val <<= 8;
 }
 s->full_update = 1;
 break;
 case CG3_REG_FBC_CTRL:
 s->regs[0] = val;
 break;
 case CG3_REG_FBC_STATUS:
 if (s->regs[1] & CG3_SR_PENDING_INT) {
 /* clear interrupt */
 s->regs[1] &= ~CG3_SR_PENDING_INT;
 qemu_irq_lower(s->irq);
 }
 break;
 case CG3_REG_FBC_CURSTART ... CG3_REG_SIZE - 1:
 s->regs[addr - 0x10] = val;
 break;
 default:
 qemu_log_mask(LOG_UNIMP,
   "cg3: Unimplemented register write "
   "reg 0x%" HWADDR_PRIx " size 0x%x value 0x%" PRIx64 "\n",
   addr, size, val);
 break;
 }
 }
diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c
index b80f98b6c4..f1513a084c 100644
--- a/hw/display/cirrus_vga.c
+++ b/hw/display/cirrus_vga.c
@@ -1319,97 +1319,97 @@ static int cirrus_vga_read_sr(CirrusVGAState * s)
 static void cirrus_vga_write_sr(CirrusVGAState * s, uint32_t val)
 {
 switch (s->vga.sr_index) {
 case 0x00:  // Standard VGA
 case 0x01:  // Standard VGA
 case 0x02:  // Standard VGA
 case 0x03:  // Standard VGA
 case 0x04:  // Standard VGA
 s->vga.sr[s->vga.sr_index] = val & sr_mask[s->vga.sr_index];
 if (s->vga.sr_index == 1)
 s->vga.update_retrace_info(&s->vga);
 break;
 case 0x06:  // Unlock Cirrus extensions
 val &= 0x17;
 if (val == 0x12) {
 s->vga.sr[s->vga.sr_index] = 0x12;
 } else {
 s->vga.sr[s->vga.sr_index] = 0x0f;
 }
 break;
 case 0x10:
 case 0x30:
 case 0x50:
 case 0x70:  // Graphics Cursor X
 case 0x90:
 case 0xb0:
 case 0xd0:
 case 0xf0:  // Graphics Cursor X
 s->vga.sr[0x10] = val;
 s->vga.hw_cursor_x = (val << 3) | (s->vga.sr_index >> 5);
 break;
 case 0x11:
 case 0x31:
 case 0x51:
 case 0x71:  // Graphics Cursor Y
 case 0x91:
 case 0xb1:
 case 0xd1:
 case 0xf1:  // Graphics Cursor Y
 s->vga.sr[0x11] = val;
 s->vga.hw_cursor_y = (val << 3) | (s->vga.sr_index >> 5);
 break;
 case 0x07:  // Extended Sequencer Mode
 cirrus_update_memory_access(s);
-/* fall through */
+fallthrough;
 case 0x08:  // EEPROM Control
 case 0x09:  // Scratch Register 0
 case 0x0a:  // Scratch Register 1
 case 0x0b:  // VCLK 0
 case 0x0c:  // VCLK 1
 case 0x0d:  // VCLK 2
 case 0x0e:  // VCLK 3
 case 0x0f:  // DRAM Control
 case 0x13:  // Graphics Cursor Pattern Address
 case 0x14:  // Scratch Register 2
 case 0x15:  // Scratch Register 3
 case 0x16:  // Performance Tuning Register
 case 0x18:  // Signature Generator Control
 case 0x19:  // S

[RFC PATCH v2 08/78] hw/block: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/block/dataplane/xen-block.c | 4 ++--
 hw/block/m25p80.c  | 2 +-
 hw/block/onenand.c | 2 +-
 hw/block/pflash_cfi01.c| 1 +
 hw/block/pflash_cfi02.c| 6 --
 5 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c
index 3b6f2b0aa2..1ae25a73b2 100644
--- a/hw/block/dataplane/xen-block.c
+++ b/hw/block/dataplane/xen-block.c
@@ -144,59 +144,59 @@ static void xen_block_complete_request(XenBlockRequest 
*request)
 /*
  * translate request into iovec + start offset
  * do sanity checks along the way
  */
 static int xen_block_parse_request(XenBlockRequest *request)
 {
 XenBlockDataPlane *dataplane = request->dataplane;
 size_t len;
 int i;
 
 switch (request->req.operation) {
 case BLKIF_OP_READ:
 break;
 case BLKIF_OP_FLUSH_DISKCACHE:
 request->presync = 1;
 if (!request->req.nr_segments) {
 return 0;
 }
-/* fall through */
+fallthrough;
 case BLKIF_OP_WRITE:
 break;
 case BLKIF_OP_DISCARD:
 return 0;
 default:
 error_report("error: unknown operation (%d)", request->req.operation);
 goto err;
 };
 
 if (request->req.operation != BLKIF_OP_READ &&
 !blk_is_writable(dataplane->blk)) {
 error_report("error: write req for ro device");
 goto err;
 }
 
 request->start = request->req.sector_number * dataplane->sector_size;
 for (i = 0; i < request->req.nr_segments; i++) {
 if (i == BLKIF_MAX_SEGMENTS_PER_REQUEST) {
 error_report("error: nr_segments too big");
 goto err;
 }
 if (request->req.seg[i].first_sect > request->req.seg[i].last_sect) {
 error_report("error: first > last sector");
 goto err;
 }
 if (request->req.seg[i].last_sect * dataplane->sector_size >=
 XEN_PAGE_SIZE) {
 error_report("error: page crossing");
 goto err;
 }
 
 len = (request->req.seg[i].last_sect -
request->req.seg[i].first_sect + 1) * dataplane->sector_size;
 request->size += len;
 }
 if (request->start + request->size > blk_getlength(dataplane->blk)) {
 error_report("error: access beyond end of file");
 goto err;
 }
 return 0;
@@ -257,63 +257,63 @@ static int xen_block_do_aio(XenBlockRequest *request);
 static void xen_block_complete_aio(void *opaque, int ret)
 {
 XenBlockRequest *request = opaque;
 XenBlockDataPlane *dataplane = request->dataplane;
 
 aio_context_acquire(dataplane->ctx);
 
 if (ret != 0) {
 error_report("%s I/O error",
  request->req.operation == BLKIF_OP_READ ?
  "read" : "write");
 request->aio_errors++;
 }
 
 request->aio_inflight--;
 if (request->presync) {
 request->presync = 0;
 xen_block_do_aio(request);
 goto done;
 }
 if (request->aio_inflight > 0) {
 goto done;
 }
 
 switch (request->req.operation) {
 case BLKIF_OP_READ:
 /* in case of failure request->aio_errors is increased */
 if (ret == 0) {
 xen_block_copy_request(request);
 }
 break;
 case BLKIF_OP_WRITE:
 case BLKIF_OP_FLUSH_DISKCACHE:
 default:
 break;
 }
 
 request->status = request->aio_errors ? BLKIF_RSP_ERROR : BLKIF_RSP_OKAY;
 
 switch (request->req.operation) {
 case BLKIF_OP_WRITE:
 case BLKIF_OP_FLUSH_DISKCACHE:
 if (!request->req.nr_segments) {
 break;
 }
-/* fall through */
+fallthrough;
 case BLKIF_OP_READ:
 if (request->status == BLKIF_RSP_OKAY) {
 block_acct_done(blk_get_stats(dataplane->blk), &request->acct);
 } else {
 block_acct_failed(blk_get_stats(dataplane->blk), &request->acct);
 }
 break;
 case BLKIF_OP_DISCARD:
 default:
 break;
 }
 
 xen_block_complete_request(request);
 
 if (dataplane->more_work) {
 qemu_bh_schedule(dataplane->bh);
 }
diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index afc3fdf4d6..523c34da71 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -1117,360 +1117,360 @@ static bool is_valid_aai_cmd(uint32_t cmd)
 static void decode_new_cmd(Flash *s, uint32_t value)
 {
 int i;
 
 s->cmd_in_progress = value;
 trace_m25p80_command_decoded(s, value);
 
 if (value != RESET_MEMORY) {
 s->reset_enable = false;
 }
 
 if (get_man(s) == MAN_SST && s->aai_enable && !is_valid_aai_cmd(value)) {
 qemu_log_mask(LOG_GUEST_ERROR,
   "M25P80: Invalid cmd within 

[RFC PATCH v2 14/78] util/error-report.c: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 util/error-report.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/error-report.c b/util/error-report.c
index 6e44a55732..acb66420de 100644
--- a/util/error-report.c
+++ b/util/error-report.c
@@ -353,36 +353,36 @@ static char *qemu_glog_domains;
 static void qemu_log_func(const gchar *log_domain,
   GLogLevelFlags log_level,
   const gchar *message,
   gpointer user_data)
 {
 switch (log_level & G_LOG_LEVEL_MASK) {
 case G_LOG_LEVEL_DEBUG:
 case G_LOG_LEVEL_INFO:
 /*
  * Use same G_MESSAGES_DEBUG logic as glib to enable/disable debug
  * messages
  */
 if (qemu_glog_domains == NULL) {
 break;
 }
 if (strcmp(qemu_glog_domains, "all") != 0 &&
   (log_domain == NULL || !strstr(qemu_glog_domains, log_domain))) {
 break;
 }
-/* Fall through */
+fallthrough;
 case G_LOG_LEVEL_MESSAGE:
 info_report("%s%s%s",
 log_domain ?: "", log_domain ? ": " : "", message);
 
 break;
 case G_LOG_LEVEL_WARNING:
 warn_report("%s%s%s",
 log_domain ?: "", log_domain ? ": " : "", message);
 break;
 case G_LOG_LEVEL_CRITICAL:
 case G_LOG_LEVEL_ERROR:
 error_report("%s%s%s",
  log_domain ?: "", log_domain ? ": " : "", message);
 break;
 }
 }
-- 
2.39.2




[RFC PATCH v2 32/78] target/m68k: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/m68k/op_helper.c |  3 ++-
 target/m68k/translate.c | 10 +-
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/target/m68k/op_helper.c b/target/m68k/op_helper.c
index 1ce850bbc5..65058b9e2f 100644
--- a/target/m68k/op_helper.c
+++ b/target/m68k/op_helper.c
@@ -285,147 +285,147 @@ static inline void do_stack_frame(CPUM68KState *env, 
uint32_t *sp,
 static void m68k_interrupt_all(CPUM68KState *env, int is_hw)
 {
 CPUState *cs = env_cpu(env);
 uint32_t sp;
 uint32_t vector;
 uint16_t sr, oldsr;
 
 if (!is_hw) {
 switch (cs->exception_index) {
 case EXCP_RTE:
 /* Return from an exception.  */
 m68k_rte(env);
 return;
 }
 }
 
 vector = cs->exception_index << 2;
 
 sr = env->sr | cpu_m68k_get_ccr(env);
 if (qemu_loglevel_mask(CPU_LOG_INT)) {
 static int count;
 qemu_log("INT %6d: %s(%#x) pc=%08x sp=%08x sr=%04x\n",
  ++count, m68k_exception_name(cs->exception_index),
  vector, env->pc, env->aregs[7], sr);
 }
 
 /*
  * MC68040UM/AD,  chapter 9.3.10
  */
 
 /* "the processor first make an internal copy" */
 oldsr = sr;
 /* "set the mode to supervisor" */
 sr |= SR_S;
 /* "suppress tracing" */
 sr &= ~SR_T;
 /* "sets the processor interrupt mask" */
 if (is_hw) {
 sr |= (env->sr & ~SR_I) | (env->pending_level << SR_I_SHIFT);
 }
 cpu_m68k_set_sr(env, sr);
 sp = env->aregs[7];
 
 if (!m68k_feature(env, M68K_FEATURE_UNALIGNED_DATA)) {
 sp &= ~1;
 }
 
 switch (cs->exception_index) {
 case EXCP_ACCESS:
 if (env->mmu.fault) {
 cpu_abort(cs, "DOUBLE MMU FAULT\n");
 }
 env->mmu.fault = true;
 /* push data 3 */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* push data 2 */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* push data 1 */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* write back 1 / push data 0 */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* write back 1 address */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* write back 2 data */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* write back 2 address */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* write back 3 data */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* write back 3 address */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, env->mmu.ar, MMU_KERNEL_IDX, 0);
 /* fault address */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, env->mmu.ar, MMU_KERNEL_IDX, 0);
 /* write back 1 status */
 sp -= 2;
 cpu_stw_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* write back 2 status */
 sp -= 2;
 cpu_stw_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* write back 3 status */
 sp -= 2;
 cpu_stw_mmuidx_ra(env, sp, 0, MMU_KERNEL_IDX, 0);
 /* special status word */
 sp -= 2;
 cpu_stw_mmuidx_ra(env, sp, env->mmu.ssw, MMU_KERNEL_IDX, 0);
 /* effective address */
 sp -= 4;
 cpu_stl_mmuidx_ra(env, sp, env->mmu.ar, MMU_KERNEL_IDX, 0);
 
 do_stack_frame(env, &sp, 7, oldsr, 0, env->pc);
 env->mmu.fault = false;
 if (qemu_loglevel_mask(CPU_LOG_INT)) {
 qemu_log(""
  "ssw:  %08x ea:   %08x sfc:  %ddfc: %d\n",
  env->mmu.ssw, env->mmu.ar, env->sfc, env->dfc);
 }
 break;
 
 case EXCP_ILLEGAL:
 do_stack_frame(env, &sp, 0, oldsr, 0, env->pc);
 break;
 
 case EXCP_ADDRESS:
 do_stack_frame(env, &sp, 2, oldsr, 0, env->pc);
 break;
 
 case EXCP_CHK:
 case EXCP_DIV0:
 case EXCP_TRACE:
 case EXCP_TRAPCC:
 do_stack_frame(env, &sp, 2, oldsr, env->mmu.ar, env->pc);
 break;
 
 case EXCP_SPURIOUS ... EXCP_INT_LEVEL_7:
 if (is_hw && (oldsr & SR_M)) {
 do_stack_frame(env, &sp, 0, oldsr, 0, env->pc);
 oldsr = sr;
 env->aregs[7] = sp;
 cpu_m68k_set_sr(env, sr & ~SR_M);
 sp = env->aregs[7];
 if (!m68k_feature(env, M68K_FEATURE_UNALIGNED_DATA)) {
 sp &= ~1;
 }
 do_stack_frame(env, &sp, 1, oldsr, 0, env->pc);
 break;
 }
-/* fall through */
+fallthrough;
 
 default:
 do_stack_frame(env, &sp, 0, oldsr, 0, env->pc);

[RFC PATCH 02/78] block: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 block/block-copy.c|  1 +
 block/file-posix.c|  1 +
 block/io.c|  1 +
 block/iscsi.c |  1 +
 block/qcow2-cluster.c |  5 -
 block/vhdx.c  | 17 +
 6 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/block/block-copy.c b/block/block-copy.c
index 1c60368d72..b4ceb6a079 100644
--- a/block/block-copy.c
+++ b/block/block-copy.c
@@ -473,78 +473,79 @@ static int coroutine_fn GRAPH_RDLOCK
 block_copy_do_copy(BlockCopyState *s, int64_t offset, int64_t bytes,
BlockCopyMethod *method, bool *error_is_read)
 {
 int ret;
 int64_t nbytes = MIN(offset + bytes, s->len) - offset;
 void *bounce_buffer = NULL;
 
 assert(offset >= 0 && bytes > 0 && INT64_MAX - offset >= bytes);
 assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
 assert(QEMU_IS_ALIGNED(bytes, s->cluster_size));
 assert(offset < s->len);
 assert(offset + bytes <= s->len ||
offset + bytes == QEMU_ALIGN_UP(s->len, s->cluster_size));
 assert(nbytes < INT_MAX);
 
 switch (*method) {
 case COPY_WRITE_ZEROES:
 ret = bdrv_co_pwrite_zeroes(s->target, offset, nbytes, s->write_flags &
 ~BDRV_REQ_WRITE_COMPRESSED);
 if (ret < 0) {
 trace_block_copy_write_zeroes_fail(s, offset, ret);
 *error_is_read = false;
 }
 return ret;
 
 case COPY_RANGE_SMALL:
 case COPY_RANGE_FULL:
 ret = bdrv_co_copy_range(s->source, offset, s->target, offset, nbytes,
  0, s->write_flags);
 if (ret >= 0) {
 /* Successful copy-range, increase chunk size.  */
 *method = COPY_RANGE_FULL;
 return 0;
 }
 
 trace_block_copy_copy_range_fail(s, offset, ret);
 *method = COPY_READ_WRITE;
 /* Fall through to read+write with allocated buffer */
+fallthrough;
 
 case COPY_READ_WRITE_CLUSTER:
 case COPY_READ_WRITE:
 /*
  * In case of failed copy_range request above, we may proceed with
  * buffered request larger than BLOCK_COPY_MAX_BUFFER.
  * Still, further requests will be properly limited, so don't care too
  * much. Moreover the most likely case (copy_range is unsupported for
  * the configuration, so the very first copy_range request fails)
  * is handled by setting large copy_size only after first successful
  * copy_range.
  */
 
 bounce_buffer = qemu_blockalign(s->source->bs, nbytes);
 
 ret = bdrv_co_pread(s->source, offset, nbytes, bounce_buffer, 0);
 if (ret < 0) {
 trace_block_copy_read_fail(s, offset, ret);
 *error_is_read = true;
 goto out;
 }
 
 ret = bdrv_co_pwrite(s->target, offset, nbytes, bounce_buffer,
  s->write_flags);
 if (ret < 0) {
 trace_block_copy_write_fail(s, offset, ret);
 *error_is_read = false;
 goto out;
 }
 
 out:
 qemu_vfree(bounce_buffer);
 break;
 
 default:
 abort();
 }
 
 return ret;
 }
diff --git a/block/file-posix.c b/block/file-posix.c
index 50e2b20d5c..31c7719da5 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -972,69 +972,70 @@ static int raw_check_lock_bytes(int fd, uint64_t perm, 
uint64_t shared_perm,
 static int raw_handle_perm_lock(BlockDriverState *bs,
 RawPermLockOp op,
 uint64_t new_perm, uint64_t new_shared,
 Error **errp)
 {
 BDRVRawState *s = bs->opaque;
 int ret = 0;
 Error *local_err = NULL;
 
 if (!s->use_lock) {
 return 0;
 }
 
 if (bdrv_get_flags(bs) & BDRV_O_INACTIVE) {
 return 0;
 }
 
 switch (op) {
 case RAW_PL_PREPARE:
 if ((s->perm | new_perm) == s->perm &&
 (s->shared_perm & new_shared) == s->shared_perm)
 {
 /*
  * We are going to unlock bytes, it should not fail. If it fail due
  * to some fs-dependent permission-unrelated reasons (which occurs
  * sometimes on NFS and leads to abort in bdrv_replace_child) we
  * can't prevent such errors by any check here. And we ignore them
  * anyway in ABORT and COMMIT.
  */
 return 0;
 }
 ret = raw_apply_lock_bytes(s, s->fd, s->perm | new_perm,
~s->shared_perm | ~new_shared,
false, errp);
 if (!ret) {
 ret = raw_check_lock_bytes(s->fd, new_perm, new_shared, errp);
 if (!ret) {
 return 0;

[RFC PATCH v2 18/78] ui/win32-kbd-hook.c: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 ui/win32-kbd-hook.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/ui/win32-kbd-hook.c b/ui/win32-kbd-hook.c
index 1ac237db9e..3c5c3fc597 100644
--- a/ui/win32-kbd-hook.c
+++ b/ui/win32-kbd-hook.c
@@ -18,59 +18,52 @@ static DWORD win32_grab;
 static LRESULT CALLBACK keyboard_hook_cb(int code, WPARAM wparam, LPARAM 
lparam)
 {
 if  (win32_window && code == HC_ACTION && win32_window == GetFocus()) {
 KBDLLHOOKSTRUCT *hooked = (KBDLLHOOKSTRUCT *)lparam;
 
 if (wparam != WM_KEYUP) {
 DWORD dwmsg = (hooked->flags << 24) |
   ((hooked->scanCode & 0xff) << 16) | 1;
 
 switch (hooked->vkCode) {
 case VK_CAPITAL:
-/* fall through */
 case VK_SCROLL:
-/* fall through */
 case VK_NUMLOCK:
-/* fall through */
 case VK_LSHIFT:
-/* fall through */
 case VK_RSHIFT:
-/* fall through */
 case VK_RCONTROL:
-/* fall through */
 case VK_LMENU:
-/* fall through */
 case VK_RMENU:
 break;
 
 case VK_LCONTROL:
 /*
  * When pressing AltGr, an extra VK_LCONTROL with a special
  * scancode with bit 9 set is sent. Let's ignore the extra
  * VK_LCONTROL, as that will make AltGr misbehave.
  */
 if (hooked->scanCode & 0x200) {
 return 1;
 }
 break;
 
 default:
 if (win32_grab) {
 SendMessage(win32_window, wparam, hooked->vkCode, dwmsg);
 return 1;
 }
 break;
 }
 
 } else {
 switch (hooked->vkCode) {
 case VK_LCONTROL:
 if (hooked->scanCode & 0x200) {
 return 1;
 }
 break;
 }
 }
 }
 
 return CallNextHookEx(NULL, code, wparam, lparam);
 }
-- 
2.39.2




[RFC PATCH 49/78] hw/arm: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/arm/omap1.c | 8 
 hw/arm/pxa2xx.c| 6 +++---
 hw/arm/stellaris.c | 1 +
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/hw/arm/omap1.c b/hw/arm/omap1.c
index d5438156ee..c54a4ec553 100644
--- a/hw/arm/omap1.c
+++ b/hw/arm/omap1.c
@@ -531,46 +531,46 @@ static struct omap_32khz_timer_s 
*omap_os_timer_init(MemoryRegion *memory,
 /* Ultra Low-Power Device Module */
 static uint64_t omap_ulpd_pm_read(void *opaque, hwaddr addr,
   unsigned size)
 {
 struct omap_mpu_state_s *s = opaque;
 uint16_t ret;
 
 if (size != 2) {
 return omap_badwidth_read16(opaque, addr);
 }
 
 switch (addr) {
 case 0x14: /* IT_STATUS */
 ret = s->ulpd_pm_regs[addr >> 2];
 s->ulpd_pm_regs[addr >> 2] = 0;
 qemu_irq_lower(qdev_get_gpio_in(s->ih[1], OMAP_INT_GAUGE_32K));
 return ret;
 
 case 0x18: /* Reserved */
 case 0x1c: /* Reserved */
 case 0x20: /* Reserved */
 case 0x28: /* Reserved */
 case 0x2c: /* Reserved */
 OMAP_BAD_REG(addr);
-/* fall through */
+fallthrough;
 case 0x00: /* COUNTER_32_LSB */
 case 0x04: /* COUNTER_32_MSB */
 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
 case 0x10: /* GAUGING_CTRL */
 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
 case 0x30: /* CLOCK_CTRL */
 case 0x34: /* SOFT_REQ */
 case 0x38: /* COUNTER_32_FIQ */
 case 0x3c: /* DPLL_CTRL */
 case 0x40: /* STATUS_REQ */
 /* XXX: check clk::usecount state for every clock */
 case 0x48: /* LOCL_TIME */
 case 0x4c: /* APLL_CTRL */
 case 0x50: /* POWER_CTRL */
 return s->ulpd_pm_regs[addr >> 2];
 }
 
 OMAP_BAD_REG(addr);
 return 0;
 }
@@ -600,120 +600,120 @@ static inline void omap_ulpd_req_update(struct 
omap_mpu_state_s *s,
 static void omap_ulpd_pm_write(void *opaque, hwaddr addr,
uint64_t value, unsigned size)
 {
 struct omap_mpu_state_s *s = opaque;
 int64_t now, ticks;
 int div, mult;
 static const int bypass_div[4] = { 1, 2, 4, 4 };
 uint16_t diff;
 
 if (size != 2) {
 omap_badwidth_write16(opaque, addr, value);
 return;
 }
 
 switch (addr) {
 case 0x00: /* COUNTER_32_LSB */
 case 0x04: /* COUNTER_32_MSB */
 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
 case 0x14: /* IT_STATUS */
 case 0x40: /* STATUS_REQ */
 OMAP_RO_REG(addr);
 break;
 
 case 0x10: /* GAUGING_CTRL */
 /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
 if ((s->ulpd_pm_regs[addr >> 2] ^ value) & 1) {
 now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
 
 if (value & 1)
 s->ulpd_gauge_start = now;
 else {
 now -= s->ulpd_gauge_start;
 
 /* 32-kHz ticks */
 ticks = muldiv64(now, 32768, NANOSECONDS_PER_SECOND);
 s->ulpd_pm_regs[0x00 >> 2] = (ticks >>  0) & 0x;
 s->ulpd_pm_regs[0x04 >> 2] = (ticks >> 16) & 0x;
 if (ticks >> 32)   /* OVERFLOW_32K */
 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 2;
 
 /* High frequency ticks */
 ticks = muldiv64(now, 1200, NANOSECONDS_PER_SECOND);
 s->ulpd_pm_regs[0x08 >> 2] = (ticks >>  0) & 0x;
 s->ulpd_pm_regs[0x0c >> 2] = (ticks >> 16) & 0x;
 if (ticks >> 32)   /* OVERFLOW_HI_FREQ */
 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 1;
 
 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 0;  /* IT_GAUGING */
 qemu_irq_raise(qdev_get_gpio_in(s->ih[1], OMAP_INT_GAUGE_32K));
 }
 }
 s->ulpd_pm_regs[addr >> 2] = value;
 break;
 
 case 0x18: /* Reserved */
 case 0x1c: /* Reserved */
 case 0x20: /* Reserved */
 case 0x28: /* Reserved */
 case 0x2c: /* Reserved */
 OMAP_BAD_REG(addr);
-/* fall through */
+fallthrough;
 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
 case 0x38: /* COUNTER_32_FIQ */
 case 0x48: /* LOCL_TIME */
 case 0x50: /* POWER_CTRL */
 s->ulpd_pm_regs[addr >> 2] = value;
 break;
 
 case 0x30: /* CLOCK_CTRL */
 diff = s->ulpd_pm_regs[addr >> 2] ^ value;
 s->ulpd_pm_regs[addr >> 2] = value & 0x3f;
 omap_ulpd_clk_update(s, diff, value);
 break;
 
 case 0x34: /* SOFT_REQ */
 diff = s->ulpd_pm_regs[addr >> 2] ^ value;
 s->ulpd_pm_regs[addr >> 2] = value & 0x1f;
 omap_ulpd_req_update(s, diff, value);
 break;
 
 case 0x3c: /* DPLL_CTRL */
 /* XXX: OM

Re: [RFC PATCH v2 71/78] hw/s390x: add fallthrough pseudo-keyword

2023-10-13 Thread David Hildenbrand

On 13.10.23 09:57, Emmanouil Pitsidianakis wrote:

In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---


Reviewed-by: David Hildenbrand 


See Rb's on the other two patches I was CCed in v1.

--
Cheers,

David / dhildenb




[RFC PATCH v2 46/78] disas: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 disas/hppa.c  | 4 ++--
 disas/m68k.c  | 2 +-
 disas/sh4.c   | 6 +++---
 disas/sparc.c | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/disas/hppa.c b/disas/hppa.c
index dcf9a47f34..1a2bdb8d39 100644
--- a/disas/hppa.c
+++ b/disas/hppa.c
@@ -1954,878 +1954,878 @@ int
 print_insn_hppa (bfd_vma memaddr, disassemble_info *info)
 {
   bfd_byte buffer[4];
   unsigned int insn, i;
 
   {
 int status =
   (*info->read_memory_func) (memaddr, buffer, sizeof (buffer), info);
 if (status != 0)
   {
(*info->memory_error_func) (status, memaddr, info);
return -1;
   }
   }
 
   insn = bfd_getb32 (buffer);
 
   for (i = 0; i < NUMOPCODES; ++i)
 {
   const struct pa_opcode *opcode = &pa_opcodes[i];
 
   if ((insn & opcode->mask) == opcode->match)
{
  const char *s;
 #ifndef BFD64
  if (opcode->arch == pa20w)
continue;
 #endif
  (*info->fprintf_func) (info->stream, "%s", opcode->name);
 
  if (!strchr ("cfCY?-+nHNZFIuv{", opcode->args[0]))
(*info->fprintf_func) (info->stream, " ");
  for (s = opcode->args; *s != '\0'; ++s)
{
  switch (*s)
{
case 'x':
  fput_reg (GET_FIELD (insn, 11, 15), info);
  break;
case 'a':
case 'b':
  fput_reg (GET_FIELD (insn, 6, 10), info);
  break;
case '^':
  fput_creg (GET_FIELD (insn, 6, 10), info);
  break;
case 't':
  fput_reg (GET_FIELD (insn, 27, 31), info);
  break;
 
  /* Handle floating point registers.  */
case 'f':
  switch (*++s)
{
case 't':
  fput_fp_reg (GET_FIELD (insn, 27, 31), info);
  break;
case 'T':
  if (GET_FIELD (insn, 25, 25))
fput_fp_reg_r (GET_FIELD (insn, 27, 31), info);
  else
fput_fp_reg (GET_FIELD (insn, 27, 31), info);
  break;
case 'a':
  if (GET_FIELD (insn, 25, 25))
fput_fp_reg_r (GET_FIELD (insn, 6, 10), info);
  else
fput_fp_reg (GET_FIELD (insn, 6, 10), info);
  break;
 
  /* 'fA' will not generate a space before the register
 name.  Normally that is fine.  Except that it
 causes problems with xmpyu which has no FP format
 completer.  */
case 'X':
  fputs_filtered (" ", info);
- /* FALLTHRU */
+ fallthrough;
 
case 'A':
  if (GET_FIELD (insn, 24, 24))
fput_fp_reg_r (GET_FIELD (insn, 6, 10), info);
  else
fput_fp_reg (GET_FIELD (insn, 6, 10), info);
  break;
case 'b':
  if (GET_FIELD (insn, 25, 25))
fput_fp_reg_r (GET_FIELD (insn, 11, 15), info);
  else
fput_fp_reg (GET_FIELD (insn, 11, 15), info);
  break;
case 'B':
  if (GET_FIELD (insn, 19, 19))
fput_fp_reg_r (GET_FIELD (insn, 11, 15), info);
  else
fput_fp_reg (GET_FIELD (insn, 11, 15), info);
  break;
case 'C':
  {
int reg = GET_FIELD (insn, 21, 22);
reg |= GET_FIELD (insn, 16, 18) << 2;
if (GET_FIELD (insn, 23, 23) != 0)
  fput_fp_reg_r (reg, info);
else
  fput_fp_reg (reg, info);
break;
  }
case 'i':
  {
int reg = GET_FIELD (insn, 6, 10);
 
reg |= (GET_FIELD (insn, 26, 26) << 4);
fput_fp_reg (reg, info);
break;
  }
case 'j':
  {
int reg = GET_FIELD (insn, 11, 15);
 
reg |= (GET_FIELD (insn, 26, 26) << 4);
fput_fp_reg (reg, info);
break;
  }
case 'k':
  

[RFC PATCH 48/75] hw/arm: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/arm/omap1.c | 8 
 hw/arm/pxa2xx.c| 5 +++--
 hw/arm/stellaris.c | 1 +
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/hw/arm/omap1.c b/hw/arm/omap1.c
index d5438156ee..c54a4ec553 100644
--- a/hw/arm/omap1.c
+++ b/hw/arm/omap1.c
@@ -531,46 +531,46 @@ static struct omap_32khz_timer_s 
*omap_os_timer_init(MemoryRegion *memory,
 /* Ultra Low-Power Device Module */
 static uint64_t omap_ulpd_pm_read(void *opaque, hwaddr addr,
   unsigned size)
 {
 struct omap_mpu_state_s *s = opaque;
 uint16_t ret;
 
 if (size != 2) {
 return omap_badwidth_read16(opaque, addr);
 }
 
 switch (addr) {
 case 0x14: /* IT_STATUS */
 ret = s->ulpd_pm_regs[addr >> 2];
 s->ulpd_pm_regs[addr >> 2] = 0;
 qemu_irq_lower(qdev_get_gpio_in(s->ih[1], OMAP_INT_GAUGE_32K));
 return ret;
 
 case 0x18: /* Reserved */
 case 0x1c: /* Reserved */
 case 0x20: /* Reserved */
 case 0x28: /* Reserved */
 case 0x2c: /* Reserved */
 OMAP_BAD_REG(addr);
-/* fall through */
+fallthrough;
 case 0x00: /* COUNTER_32_LSB */
 case 0x04: /* COUNTER_32_MSB */
 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
 case 0x10: /* GAUGING_CTRL */
 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
 case 0x30: /* CLOCK_CTRL */
 case 0x34: /* SOFT_REQ */
 case 0x38: /* COUNTER_32_FIQ */
 case 0x3c: /* DPLL_CTRL */
 case 0x40: /* STATUS_REQ */
 /* XXX: check clk::usecount state for every clock */
 case 0x48: /* LOCL_TIME */
 case 0x4c: /* APLL_CTRL */
 case 0x50: /* POWER_CTRL */
 return s->ulpd_pm_regs[addr >> 2];
 }
 
 OMAP_BAD_REG(addr);
 return 0;
 }
@@ -600,120 +600,120 @@ static inline void omap_ulpd_req_update(struct 
omap_mpu_state_s *s,
 static void omap_ulpd_pm_write(void *opaque, hwaddr addr,
uint64_t value, unsigned size)
 {
 struct omap_mpu_state_s *s = opaque;
 int64_t now, ticks;
 int div, mult;
 static const int bypass_div[4] = { 1, 2, 4, 4 };
 uint16_t diff;
 
 if (size != 2) {
 omap_badwidth_write16(opaque, addr, value);
 return;
 }
 
 switch (addr) {
 case 0x00: /* COUNTER_32_LSB */
 case 0x04: /* COUNTER_32_MSB */
 case 0x08: /* COUNTER_HIGH_FREQ_LSB */
 case 0x0c: /* COUNTER_HIGH_FREQ_MSB */
 case 0x14: /* IT_STATUS */
 case 0x40: /* STATUS_REQ */
 OMAP_RO_REG(addr);
 break;
 
 case 0x10: /* GAUGING_CTRL */
 /* Bits 0 and 1 seem to be confused in the OMAP 310 TRM */
 if ((s->ulpd_pm_regs[addr >> 2] ^ value) & 1) {
 now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
 
 if (value & 1)
 s->ulpd_gauge_start = now;
 else {
 now -= s->ulpd_gauge_start;
 
 /* 32-kHz ticks */
 ticks = muldiv64(now, 32768, NANOSECONDS_PER_SECOND);
 s->ulpd_pm_regs[0x00 >> 2] = (ticks >>  0) & 0x;
 s->ulpd_pm_regs[0x04 >> 2] = (ticks >> 16) & 0x;
 if (ticks >> 32)   /* OVERFLOW_32K */
 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 2;
 
 /* High frequency ticks */
 ticks = muldiv64(now, 1200, NANOSECONDS_PER_SECOND);
 s->ulpd_pm_regs[0x08 >> 2] = (ticks >>  0) & 0x;
 s->ulpd_pm_regs[0x0c >> 2] = (ticks >> 16) & 0x;
 if (ticks >> 32)   /* OVERFLOW_HI_FREQ */
 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 1;
 
 s->ulpd_pm_regs[0x14 >> 2] |= 1 << 0;  /* IT_GAUGING */
 qemu_irq_raise(qdev_get_gpio_in(s->ih[1], OMAP_INT_GAUGE_32K));
 }
 }
 s->ulpd_pm_regs[addr >> 2] = value;
 break;
 
 case 0x18: /* Reserved */
 case 0x1c: /* Reserved */
 case 0x20: /* Reserved */
 case 0x28: /* Reserved */
 case 0x2c: /* Reserved */
 OMAP_BAD_REG(addr);
-/* fall through */
+fallthrough;
 case 0x24: /* SETUP_ANALOG_CELL3_ULPD1 */
 case 0x38: /* COUNTER_32_FIQ */
 case 0x48: /* LOCL_TIME */
 case 0x50: /* POWER_CTRL */
 s->ulpd_pm_regs[addr >> 2] = value;
 break;
 
 case 0x30: /* CLOCK_CTRL */
 diff = s->ulpd_pm_regs[addr >> 2] ^ value;
 s->ulpd_pm_regs[addr >> 2] = value & 0x3f;
 omap_ulpd_clk_update(s, diff, value);
 break;
 
 case 0x34: /* SOFT_REQ */
 diff = s->ulpd_pm_regs[addr >> 2] ^ value;
 s->ulpd_pm_regs[addr >> 2] = value & 0x1f;
 omap_ulpd_req_update(s, diff, value);
 break;
 
 case 0x3c: /* DPLL_CTRL */
 /* XXX: OMAP310 TRM claims bit 3 is PLL_ENABLE, and bit 4 is
  * omitted altogether, probably a typo.  */
 /* This register has iden

[RFC PATCH 44/75] hw/dma: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/dma/omap_dma.c| 32 
 hw/dma/pxa2xx_dma.c  |  4 ++--
 hw/dma/sparc32_dma.c |  2 +-
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/hw/dma/omap_dma.c b/hw/dma/omap_dma.c
index 77797a67b5..dd43dbf3d2 100644
--- a/hw/dma/omap_dma.c
+++ b/hw/dma/omap_dma.c
@@ -1457,46 +1457,46 @@ static int omap_dma_sys_read(struct omap_dma_s *s, int 
offset,
 static uint64_t omap_dma_read(void *opaque, hwaddr addr, unsigned size)
 {
 struct omap_dma_s *s = opaque;
 int reg, ch;
 uint16_t ret;
 
 if (size != 2) {
 return omap_badwidth_read16(opaque, addr);
 }
 
 switch (addr) {
 case 0x300 ... 0x3fe:
 if (s->model <= omap_dma_3_1 || !s->omap_3_1_mapping_disabled) {
 if (omap_dma_3_1_lcd_read(&s->lcd_ch, addr, &ret))
 break;
 return ret;
 }
-/* Fall through. */
+fallthrough;
 case 0x000 ... 0x2fe:
 reg = addr & 0x3f;
 ch = (addr >> 6) & 0x0f;
 if (omap_dma_ch_reg_read(s, &s->ch[ch], reg, &ret))
 break;
 return ret;
 
 case 0x404 ... 0x4fe:
 if (s->model <= omap_dma_3_1)
 break;
-/* Fall through. */
+fallthrough;
 case 0x400:
 if (omap_dma_sys_read(s, addr, &ret))
 break;
 return ret;
 
 case 0xb00 ... 0xbfe:
 if (s->model == omap_dma_3_2 && s->omap_3_1_mapping_disabled) {
 if (omap_dma_3_2_lcd_read(&s->lcd_ch, addr, &ret))
 break;
 return ret;
 }
 break;
 }
 
 OMAP_BAD_REG(addr);
 return 0;
 }
@@ -1504,46 +1504,46 @@ static uint64_t omap_dma_read(void *opaque, hwaddr 
addr, unsigned size)
 static void omap_dma_write(void *opaque, hwaddr addr,
uint64_t value, unsigned size)
 {
 struct omap_dma_s *s = opaque;
 int reg, ch;
 
 if (size != 2) {
 omap_badwidth_write16(opaque, addr, value);
 return;
 }
 
 switch (addr) {
 case 0x300 ... 0x3fe:
 if (s->model <= omap_dma_3_1 || !s->omap_3_1_mapping_disabled) {
 if (omap_dma_3_1_lcd_write(&s->lcd_ch, addr, value))
 break;
 return;
 }
-/* Fall through.  */
+fallthrough;
 case 0x000 ... 0x2fe:
 reg = addr & 0x3f;
 ch = (addr >> 6) & 0x0f;
 if (omap_dma_ch_reg_write(s, &s->ch[ch], reg, value))
 break;
 return;
 
 case 0x404 ... 0x4fe:
 if (s->model <= omap_dma_3_1)
 break;
-/* fall through */
+fallthrough;
 case 0x400:
 if (omap_dma_sys_write(s, addr, value))
 break;
 return;
 
 case 0xb00 ... 0xbfe:
 if (s->model == omap_dma_3_2 && s->omap_3_1_mapping_disabled) {
 if (omap_dma_3_2_lcd_write(&s->lcd_ch, addr, value))
 break;
 return;
 }
 break;
 }
 
 OMAP_BAD_REG(addr);
 }
@@ -1702,155 +1702,155 @@ static void omap_dma_interrupts_4_update(struct 
omap_dma_s *s)
 static uint64_t omap_dma4_read(void *opaque, hwaddr addr,
unsigned size)
 {
 struct omap_dma_s *s = opaque;
 int irqn = 0, chnum;
 struct omap_dma_channel_s *ch;
 
 if (size == 1) {
 return omap_badwidth_read16(opaque, addr);
 }
 
 switch (addr) {
 case 0x00: /* DMA4_REVISION */
 return 0x40;
 
 case 0x14: /* DMA4_IRQSTATUS_L3 */
 irqn ++;
-/* fall through */
+fallthrough;
 case 0x10: /* DMA4_IRQSTATUS_L2 */
 irqn ++;
-/* fall through */
+fallthrough;
 case 0x0c: /* DMA4_IRQSTATUS_L1 */
 irqn ++;
-/* fall through */
+fallthrough;
 case 0x08: /* DMA4_IRQSTATUS_L0 */
 return s->irqstat[irqn];
 
 case 0x24: /* DMA4_IRQENABLE_L3 */
 irqn ++;
-/* fall through */
+fallthrough;
 case 0x20: /* DMA4_IRQENABLE_L2 */
 irqn ++;
-/* fall through */
+fallthrough;
 case 0x1c: /* DMA4_IRQENABLE_L1 */
 irqn ++;
-/* fall through */
+fallthrough;
 case 0x18: /* DMA4_IRQENABLE_L0 */
 return s->irqen[irqn];
 
 case 0x28: /* DMA4_SYSSTATUS */
 return 1;  /* RESETDONE */
 
 case 0x2c: /* DMA4_OCP_SYSCONFIG */
 return s->ocp;
 
 case 0x64: /* DMA4_CAPS_0 */
 return s->caps[0];
 case 0x6c: /* DMA4_CAPS_2 */
 return s->caps[2];
 case 0x70: /* DMA4_CAPS_3 */
 return s->caps[3];
 case 0x74: /* DMA4_CAPS_4 */
 return s->caps[4];
 
 case 0x78: /* DMA4_GCR */
 return s->gcr;
 
 case 0x80 ... 0xfff:
 addr -= 0x80;
 chnum = addr / 0x60;
 ch = s->ch + chnum;
 addr -= chnum * 0x60;
 break;
 
 default

[RFC PATCH 42/78] hw/i386: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 hw/i386/intel_iommu.c| 4 ++--
 hw/i386/kvm/xen_evtchn.c | 2 +-
 hw/i386/x86.c| 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 2c832ab68b..bdb2ea3ac5 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -2100,29 +2100,29 @@ static void 
vtd_context_device_invalidate(IntelIOMMUState *s,
 /* Context-cache invalidation
  * Returns the Context Actual Invalidation Granularity.
  * @val: the content of the CCMD_REG
  */
 static uint64_t vtd_context_cache_invalidate(IntelIOMMUState *s, uint64_t val)
 {
 uint64_t caig;
 uint64_t type = val & VTD_CCMD_CIRG_MASK;
 
 switch (type) {
 case VTD_CCMD_DOMAIN_INVL:
-/* Fall through */
+fallthrough;
 case VTD_CCMD_GLOBAL_INVL:
 caig = VTD_CCMD_GLOBAL_INVL_A;
 vtd_context_global_invalidate(s);
 break;
 
 case VTD_CCMD_DEVICE_INVL:
 caig = VTD_CCMD_DEVICE_INVL_A;
 vtd_context_device_invalidate(s, VTD_CCMD_SID(val), VTD_CCMD_FM(val));
 break;
 
 default:
 error_report_once("%s: invalid context: 0x%" PRIx64,
   __func__, val);
 caig = 0;
 }
 return caig;
 }
@@ -2513,34 +2513,34 @@ static bool vtd_process_wait_desc(IntelIOMMUState *s, 
VTDInvDesc *inv_desc)
 static bool vtd_process_context_cache_desc(IntelIOMMUState *s,
VTDInvDesc *inv_desc)
 {
 uint16_t sid, fmask;
 
 if ((inv_desc->lo & VTD_INV_DESC_CC_RSVD) || inv_desc->hi) {
 error_report_once("%s: invalid cc inv desc: hi=%"PRIx64", lo=%"PRIx64
   " (reserved nonzero)", __func__, inv_desc->hi,
   inv_desc->lo);
 return false;
 }
 switch (inv_desc->lo & VTD_INV_DESC_CC_G) {
 case VTD_INV_DESC_CC_DOMAIN:
 trace_vtd_inv_desc_cc_domain(
 (uint16_t)VTD_INV_DESC_CC_DID(inv_desc->lo));
-/* Fall through */
+fallthrough;
 case VTD_INV_DESC_CC_GLOBAL:
 vtd_context_global_invalidate(s);
 break;
 
 case VTD_INV_DESC_CC_DEVICE:
 sid = VTD_INV_DESC_CC_SID(inv_desc->lo);
 fmask = VTD_INV_DESC_CC_FM(inv_desc->lo);
 vtd_context_device_invalidate(s, sid, fmask);
 break;
 
 default:
 error_report_once("%s: invalid cc inv desc: hi=%"PRIx64", lo=%"PRIx64
   " (invalid type)", __func__, inv_desc->hi,
   inv_desc->lo);
 return false;
 }
 return true;
 }
diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c
index a731738411..d15e324f6e 100644
--- a/hw/i386/kvm/xen_evtchn.c
+++ b/hw/i386/kvm/xen_evtchn.c
@@ -2028,71 +2028,71 @@ static int find_be_port(XenEvtchnState *s, struct 
xenevtchn_handle *xc)
 int xen_be_evtchn_bind_interdomain(struct xenevtchn_handle *xc, uint32_t domid,
evtchn_port_t guest_port)
 {
 XenEvtchnState *s = xen_evtchn_singleton;
 XenEvtchnPort *gp;
 uint16_t be_port = 0;
 int ret;
 
 if (!s) {
 return -ENOTSUP;
 }
 
 if (!xc) {
 return -EFAULT;
 }
 
 if (domid != xen_domid) {
 return -ESRCH;
 }
 
 if (!valid_port(guest_port)) {
 return -EINVAL;
 }
 
 qemu_mutex_lock(&s->port_lock);
 
 /* The guest has to have an unbound port waiting for us to bind */
 gp = &s->port_table[guest_port];
 
 switch (gp->type) {
 case EVTCHNSTAT_interdomain:
 /* Allow rebinding after migration, preserve port # if possible */
 be_port = gp->type_val & ~PORT_INFO_TYPEVAL_REMOTE_QEMU;
 assert(be_port != 0);
 if (!s->be_handles[be_port]) {
 s->be_handles[be_port] = xc;
 xc->guest_port = guest_port;
 ret = xc->be_port = be_port;
 if (kvm_xen_has_cap(EVTCHN_SEND)) {
 assign_kernel_eventfd(gp->type, guest_port, xc->fd);
 }
 break;
 }
-/* fall through */
+fallthrough;
 
 case EVTCHNSTAT_unbound:
 be_port = find_be_port(s, xc);
 if (!be_port) {
 ret = -ENOSPC;
 goto out;
 }
 
 gp->type = EVTCHNSTAT_interdomain;
 gp->type_val = be_port | PORT_INFO_TYPEVAL_REMOTE_QEMU;
 xc->guest_port = guest_port;
 if (kvm_xen_has_cap(EVTCHN_SEND)) {
 assign_kernel_eventfd(gp->type, guest_port, xc->fd);
 }
 ret = be_port;
 break;
 
 default:
 ret = -EINVAL;
 break;
 }
 
  out:
 qemu_mutex_unlock(&s->port_lock);
 
 return ret;
 }
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index b3d054889b..c1fd0a966a 100644
--- a/hw/i386/x86.c
+++ b/hw/i

Re: [PATCH v3 01/13] migration: Create migrate_rdma()

2023-10-13 Thread Zhijian Li (Fujitsu)


On 12/10/2023 04:35, Juan Quintela wrote:
> Helper to say if we are doing a migration over rdma.
> 
> Reviewed-by: Peter Xu 
> Signed-off-by: Juan Quintela 

Reviewed-by: Li Zhijian 

> ---
>   migration/migration.h | 2 ++
>   migration/options.h   | 1 +
>   migration/migration.c | 1 +
>   migration/options.c   | 7 +++
>   migration/rdma.c  | 4 +++-
>   5 files changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/migration/migration.h b/migration/migration.h
> index cd5534337c..96260138d1 100644
> --- a/migration/migration.h
> +++ b/migration/migration.h
> @@ -469,6 +469,8 @@ struct MigrationState {
>* switchover has been received.
>*/
>   bool switchover_acked;
> +/* Is this a rdma migration */
> +bool rdma_migration;
>   };
>   
>   void migrate_set_state(int *state, int old_state, int new_state);
> diff --git a/migration/options.h b/migration/options.h
> index 045e2a41a2..a26fd1680b 100644
> --- a/migration/options.h
> +++ b/migration/options.h
> @@ -56,6 +56,7 @@ bool migrate_zero_copy_send(void);
>   
>   bool migrate_multifd_flush_after_each_section(void);
>   bool migrate_postcopy(void);
> +bool migrate_rdma(void);
>   bool migrate_tls(void);
>   
>   /* capabilities helpers */
> diff --git a/migration/migration.c b/migration/migration.c
> index 1c6c81ad49..4213c645c6 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -1451,6 +1451,7 @@ int migrate_init(MigrationState *s, Error **errp)
>   s->iteration_initial_bytes = 0;
>   s->threshold_size = 0;
>   s->switchover_acked = false;
> +s->rdma_migration = false;
>   /*
>* set mig_stats compression_counters memory to zero for a
>* new migration
> diff --git a/migration/options.c b/migration/options.c
> index 6bbfd4853d..da379e7f7a 100644
> --- a/migration/options.c
> +++ b/migration/options.c
> @@ -376,6 +376,13 @@ bool migrate_postcopy(void)
>   return migrate_postcopy_ram() || migrate_dirty_bitmaps();
>   }
>   
> +bool migrate_rdma(void)
> +{
> +MigrationState *s = migrate_get_current();
> +
> +return s->rdma_migration;
> +}
> +
>   bool migrate_tls(void)
>   {
>   MigrationState *s = migrate_get_current();
> diff --git a/migration/rdma.c b/migration/rdma.c
> index f6fc226c9b..f155f3e1c8 100644
> --- a/migration/rdma.c
> +++ b/migration/rdma.c
> @@ -4113,6 +4113,7 @@ static void rdma_accept_incoming_migration(void *opaque)
>   
>   void rdma_start_incoming_migration(const char *host_port, Error **errp)
>   {
> +MigrationState *s = migrate_get_current();
>   int ret;
>   RDMAContext *rdma;
>   
> @@ -4144,7 +4145,7 @@ void rdma_start_incoming_migration(const char 
> *host_port, Error **errp)
>   }
>   
>   trace_rdma_start_incoming_migration_after_rdma_listen();
> -
> +s->rdma_migration = true;
>   qemu_set_fd_handler(rdma->channel->fd, rdma_accept_incoming_migration,
>   NULL, (void *)(intptr_t)rdma);
>   return;
> @@ -4220,6 +4221,7 @@ void rdma_start_outgoing_migration(void *opaque,
>   trace_rdma_start_outgoing_migration_after_rdma_connect();
>   
>   s->to_dst_file = rdma_new_output(rdma);
> +s->rdma_migration = true;
>   migrate_fd_connect(s, NULL);
>   return;
>   return_path_err:

Re: [PATCH v3 10/13] migration/rdma: Check sooner if we are in postcopy for save_page()

2023-10-13 Thread Zhijian Li (Fujitsu)


On 12/10/2023 04:35, Juan Quintela wrote:
> Reviewed-by: Peter Xu 
> Signed-off-by: Juan Quintela 

Reviewed-by: Li Zhijian 


> ---
>   migration/rdma.c | 6 +-
>   1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/migration/rdma.c b/migration/rdma.c
> index d3bba05262..932d4eda9b 100644
> --- a/migration/rdma.c
> +++ b/migration/rdma.c
> @@ -3240,10 +3240,6 @@ static int qemu_rdma_save_page(QEMUFile *f, ram_addr_t 
> block_offset,
>   RDMAContext *rdma;
>   int ret;
>   
> -if (migration_in_postcopy()) {
> -return RAM_SAVE_CONTROL_NOT_SUPP;
> -}
> -
>   RCU_READ_LOCK_GUARD();
>   rdma = qatomic_rcu_read(&rioc->rdmaout);
>   
> @@ -3317,7 +3313,7 @@ err:
>   int rdma_control_save_page(QEMUFile *f, ram_addr_t block_offset,
>  ram_addr_t offset, size_t size)
>   {
> -if (!migrate_rdma()) {
> +if (!migrate_rdma() || migration_in_postcopy()) {
>   return RAM_SAVE_CONTROL_NOT_SUPP;
>   }
>   

[RFC PATCH 29/78] target/cris: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/cris/translate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/cris/translate.c b/target/cris/translate.c
index b3974ba0bb..bdd128db23 100644
--- a/target/cris/translate.c
+++ b/target/cris/translate.c
@@ -3061,94 +3061,94 @@ static void cris_tr_translate_insn(DisasContextBase 
*dcbase, CPUState *cs)
 static void cris_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
 {
 DisasContext *dc = container_of(dcbase, DisasContext, base);
 DisasJumpType is_jmp = dc->base.is_jmp;
 target_ulong npc = dc->pc;
 
 if (is_jmp == DISAS_NORETURN) {
 /* If we have a broken branch+delayslot sequence, it's too late. */
 assert(dc->delayed_branch != 1);
 return;
 }
 
 if (dc->clear_locked_irq) {
 t_gen_movi_env_TN(locked_irq, 0);
 }
 
 /* Broken branch+delayslot sequence.  */
 if (dc->delayed_branch == 1) {
 /* Set env->dslot to the size of the branch insn.  */
 t_gen_movi_env_TN(dslot, dc->pc - dc->ppc);
 cris_store_direct_jmp(dc);
 }
 
 cris_evaluate_flags(dc);
 
 /* Evaluate delayed branch destination and fold to another is_jmp case. */
 if (is_jmp == DISAS_DBRANCH) {
 if (dc->base.tb->flags & 7) {
 t_gen_movi_env_TN(dslot, 0);
 }
 
 switch (dc->jmp) {
 case JMP_DIRECT:
 npc = dc->jmp_pc;
 is_jmp = dc->cpustate_changed ? DISAS_UPDATE_NEXT : DISAS_TOO_MANY;
 break;
 
 case JMP_DIRECT_CC:
 /*
  * Use a conditional branch if either taken or not-taken path
  * can use goto_tb.  If neither can, then treat it as indirect.
  */
 if (likely(!dc->cpustate_changed)
 && (use_goto_tb(dc, dc->jmp_pc) || use_goto_tb(dc, npc))) {
 TCGLabel *not_taken = gen_new_label();
 
 tcg_gen_brcondi_tl(TCG_COND_EQ, env_btaken, 0, not_taken);
 gen_goto_tb(dc, 1, dc->jmp_pc);
 gen_set_label(not_taken);
 
 /* not-taken case handled below. */
 is_jmp = DISAS_TOO_MANY;
 break;
 }
 tcg_gen_movi_tl(env_btarget, dc->jmp_pc);
-/* fall through */
+fallthrough;
 
 case JMP_INDIRECT:
 tcg_gen_movcond_tl(TCG_COND_NE, env_pc,
env_btaken, tcg_constant_tl(0),
env_btarget, tcg_constant_tl(npc));
 is_jmp = dc->cpustate_changed ? DISAS_UPDATE : DISAS_JUMP;
 
 /*
  * We have now consumed btaken and btarget.  Hint to the
  * tcg compiler that the writeback to env may be dropped.
  */
 tcg_gen_discard_tl(env_btaken);
 tcg_gen_discard_tl(env_btarget);
 break;
 
 default:
 g_assert_not_reached();
 }
 }
 
 switch (is_jmp) {
 case DISAS_TOO_MANY:
 gen_goto_tb(dc, 0, npc);
 break;
 case DISAS_UPDATE_NEXT:
 tcg_gen_movi_tl(env_pc, npc);
-/* fall through */
+fallthrough;
 case DISAS_JUMP:
 tcg_gen_lookup_and_goto_ptr();
 break;
 case DISAS_UPDATE:
 /* Indicate that interrupts must be re-evaluated before the next TB. */
 tcg_gen_exit_tb(NULL, 0);
 break;
 default:
 g_assert_not_reached();
 }
 }
-- 
2.39.2




[RFC PATCH v2 28/78] target/avr: add fallthrough pseudo-keyword

2023-10-13 Thread Emmanouil Pitsidianakis
In preparation of raising -Wimplicit-fallthrough to 5, replace all
fall-through comments with the fallthrough attribute pseudo-keyword.

Signed-off-by: Emmanouil Pitsidianakis 
---
 target/avr/translate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/avr/translate.c b/target/avr/translate.c
index cdffa04519..2043677745 100644
--- a/target/avr/translate.c
+++ b/target/avr/translate.c
@@ -2753,37 +2753,37 @@ static void avr_tr_translate_insn(DisasContextBase 
*dcbase, CPUState *cs)
 static void avr_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
 {
 DisasContext *ctx = container_of(dcbase, DisasContext, base);
 bool nonconst_skip = canonicalize_skip(ctx);
 /*
  * Because we disable interrupts while env->skip is set,
  * we must return to the main loop to re-evaluate afterward.
  */
 bool force_exit = ctx->base.tb->flags & TB_FLAGS_SKIP;
 
 switch (ctx->base.is_jmp) {
 case DISAS_NORETURN:
 assert(!nonconst_skip);
 break;
 case DISAS_NEXT:
 case DISAS_TOO_MANY:
 case DISAS_CHAIN:
 if (!nonconst_skip && !force_exit) {
 /* Note gen_goto_tb checks singlestep.  */
 gen_goto_tb(ctx, 1, ctx->npc);
 break;
 }
 tcg_gen_movi_tl(cpu_pc, ctx->npc);
-/* fall through */
+fallthrough;
 case DISAS_LOOKUP:
 if (!force_exit) {
 tcg_gen_lookup_and_goto_ptr();
 break;
 }
-/* fall through */
+fallthrough;
 case DISAS_EXIT:
 tcg_gen_exit_tb(NULL, 0);
 break;
 default:
 g_assert_not_reached();
 }
 }
-- 
2.39.2




Re: [PATCH v3 04/13] migration/rdma: Remove all uses of RAM_CONTROL_HOOK

2023-10-13 Thread Zhijian Li (Fujitsu)


On 12/10/2023 04:35, Juan Quintela wrote:
> Instead of going trhough ram_control_load_hook(), call
> qemu_rdma_registration_handle() directly.
> 

s/trhough/through

Reviewed-by: Li Zhijian 


> Reviewed-by: Peter Xu 
> Signed-off-by: Juan Quintela 
> ---
>   migration/qemu-file.h |  1 -
>   migration/rdma.h  |  3 +++
>   migration/ram.c   |  5 -
>   migration/rdma.c  | 12 +++-
>   4 files changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/migration/qemu-file.h b/migration/qemu-file.h
> index 35e671a01e..14ff0d9cc4 100644
> --- a/migration/qemu-file.h
> +++ b/migration/qemu-file.h
> @@ -41,7 +41,6 @@ typedef int (QEMURamHookFunc)(QEMUFile *f, uint64_t flags, 
> void *data);
>*/
>   #define RAM_CONTROL_SETUP 0
>   #define RAM_CONTROL_ROUND 1
> -#define RAM_CONTROL_HOOK  2
>   #define RAM_CONTROL_FINISH3
>   #define RAM_CONTROL_BLOCK_REG 4
>   
> diff --git a/migration/rdma.h b/migration/rdma.h
> index c13b94c782..8bd277efb9 100644
> --- a/migration/rdma.h
> +++ b/migration/rdma.h
> @@ -24,10 +24,13 @@ void rdma_start_incoming_migration(const char *host_port, 
> Error **errp);
>   
>   
>   #ifdef CONFIG_RDMA
> +int qemu_rdma_registration_handle(QEMUFile *f);
>   int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags);
>   int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags);
>   #else
>   static inline
> +int qemu_rdma_registration_handle(QEMUFile *f) { return 0; }
> +static inline
>   int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags) { return 0; }
>   static inline
>   int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags) { return 0; }
> diff --git a/migration/ram.c b/migration/ram.c
> index 15bd4ad697..ee8bdcdc82 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -4072,7 +4072,10 @@ static int ram_load_precopy(QEMUFile *f)
>   }
>   break;
>   case RAM_SAVE_FLAG_HOOK:
> -ram_control_load_hook(f, RAM_CONTROL_HOOK, NULL);
> +ret = qemu_rdma_registration_handle(f);
> +if (ret < 0) {
> +qemu_file_set_error(f, ret);
> +}
>   break;
>   default:
>   error_report("Unknown combination of migration flags: 0x%x", 
> flags);
> diff --git a/migration/rdma.c b/migration/rdma.c
> index 99c0914a23..e533814599 100644
> --- a/migration/rdma.c
> +++ b/migration/rdma.c
> @@ -3522,7 +3522,7 @@ static int dest_ram_sort_func(const void *a, const void 
> *b)
>*
>* Keep doing this until the source tells us to stop.
>*/
> -static int qemu_rdma_registration_handle(QEMUFile *f)
> +int qemu_rdma_registration_handle(QEMUFile *f)
>   {
>   RDMAControlHeader reg_resp = { .len = sizeof(RDMARegisterResult),
>  .type = RDMA_CONTROL_REGISTER_RESULT,
> @@ -3534,7 +3534,7 @@ static int qemu_rdma_registration_handle(QEMUFile *f)
>};
>   RDMAControlHeader blocks = { .type = RDMA_CONTROL_RAM_BLOCKS_RESULT,
>.repeat = 1 };
> -QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f));
> +QIOChannelRDMA *rioc;
>   Error *err = NULL;
>   RDMAContext *rdma;
>   RDMALocalBlocks *local;
> @@ -3550,7 +3550,12 @@ static int qemu_rdma_registration_handle(QEMUFile *f)
>   int count = 0;
>   int i = 0;
>   
> +if (!migrate_rdma()) {
> +return 0;
> +}
> +
>   RCU_READ_LOCK_GUARD();
> +rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f));
>   rdma = qatomic_rcu_read(&rioc->rdmain);
>   
>   if (!rdma) {
> @@ -3841,9 +3846,6 @@ static int rdma_load_hook(QEMUFile *f, uint64_t flags, 
> void *data)
>   case RAM_CONTROL_BLOCK_REG:
>   return rdma_block_notification_handle(f, data);
>   
> -case RAM_CONTROL_HOOK:
> -return qemu_rdma_registration_handle(f);
> -
>   default:
>   /* Shouldn't be called with any other values */
>   abort();

  1   2   3   4   5   6   7   >