Rebase qemu-android over upstream QEMU v2.7.0

This patch rebases the qemu-android source base
on top of a much more recent version of upstream
QEMU (previous version was 2.2.0).

It was created by doing the following:

- Look at the history of all changes in qemu-android
  over v2.2.0, and "clean it up" into a list of
  small opiniated patches to do one of the following:

    - port back fixes from upstream that happened
      after v2.2.0

    - provide bug-fixes / improvements required
      by the Android emulator (but not directly
      related for Android emulation).

    - add Android-specific features.

- Rebase the "clean patches stack" on top of
  QEMU v2.7.0 (i.e. 1dc33ed90bf). The end process
  ended up being one of this patch's parents,
  i.e. 41b9dc407

- Merge the latter with the 'theirs' strategy
  (favoring the new sources over the current ones).

- Manually adjust any required changes by
  comparing the state of both trees. Fix any
  remaining conflicts.

NOTE: This updates the git submodule for the dtc/
      sub-directory, you may need to run the
      following command in your work directory
      after pulling this change:

         git submodule update dtc

Change-Id: I783ab762a696c8345c37e5ce2c966349f3710073
diff --git a/android-qemu2-glue/config/linux-x86/config-host.h b/android-qemu2-glue/config/linux-x86/config-host.h
new file mode 100644
index 0000000..5de0e8b
--- /dev/null
+++ b/android-qemu2-glue/config/linux-x86/config-host.h
@@ -0,0 +1,72 @@
+/* Automatically generated by create_config - do not modify */
+#define CONFIG_QEMU_CONFDIR "/opt2/digit/repo/studio-dev/prebuilts/android-emulator-build/qemu-android-deps/linux-x86/etc/qemu"
+#define CONFIG_QEMU_DATADIR "/opt2/digit/repo/studio-dev/prebuilts/android-emulator-build/qemu-android-deps/linux-x86/share/qemu"
+#define CONFIG_QEMU_DOCDIR "/opt2/digit/repo/studio-dev/prebuilts/android-emulator-build/qemu-android-deps/linux-x86/share/doc/qemu"
+#define CONFIG_QEMU_MODDIR "/opt2/digit/repo/studio-dev/prebuilts/android-emulator-build/qemu-android-deps/linux-x86/lib/qemu"
+#define CONFIG_QEMU_LOCALSTATEDIR "/opt2/digit/repo/studio-dev/prebuilts/android-emulator-build/qemu-android-deps/linux-x86/var"
+#define CONFIG_QEMU_HELPERDIR "/opt2/digit/repo/studio-dev/prebuilts/android-emulator-build/qemu-android-deps/linux-x86/libexec"
+#define CONFIG_QEMU_LOCALEDIR "/opt2/digit/repo/studio-dev/prebuilts/android-emulator-build/qemu-android-deps/linux-x86/share/locale"
+#define HOST_I386 1
+#define CONFIG_POSIX 1
+#define CONFIG_LINUX 1
+#define CONFIG_SLIRP 1
+#define CONFIG_SMBD_COMMAND "/usr/sbin/smbd"
+#define CONFIG_AUDIO_DRIVERS \
+    &pa_audio_driver,\
+
+#define CONFIG_PA 1
+#define CONFIG_AUDIO_PT_INT 1
+#define CONFIG_BDRV_RW_WHITELIST\
+    NULL
+#define CONFIG_BDRV_RO_WHITELIST\
+    NULL
+#define CONFIG_VNC 1
+#define CONFIG_FNMATCH 1
+#define QEMU_VERSION "2.2.0"
+#define QEMU_PKGVERSION ""
+#define CONFIG_SDL 1
+#define CONFIG_SDLABI 2.0
+#define CONFIG_UTIMENSAT 1
+#define CONFIG_PIPE2 1
+#define CONFIG_ACCEPT4 1
+#define CONFIG_SPLICE 1
+#define CONFIG_EVENTFD 1
+#define CONFIG_FALLOCATE 1
+#define CONFIG_POSIX_FALLOCATE 1
+#define CONFIG_SYNC_FILE_RANGE 1
+#define CONFIG_FIEMAP 1
+#define CONFIG_DUP3 1
+#define CONFIG_PPOLL 1
+#define CONFIG_PRCTL_PR_SET_TIMERSLACK 1
+#define CONFIG_EPOLL 1
+#define CONFIG_EPOLL_CREATE1 1
+#define CONFIG_EPOLL_PWAIT 1
+#define CONFIG_SENDFILE 1
+#define CONFIG_TIMERFD 1
+#define CONFIG_INOTIFY 1
+#define CONFIG_INOTIFY1 1
+#define CONFIG_BYTESWAP_H 1
+#define CONFIG_VHOST_SCSI 1
+#define CONFIG_IOVEC 1
+#define CONFIG_PREADV 1
+#define CONFIG_FDT 1
+#define CONFIG_SIGNALFD 1
+#define CONFIG_FDATASYNC 1
+#define CONFIG_MADVISE 1
+#define CONFIG_POSIX_MADVISE 1
+#define CONFIG_SIGEV_THREAD_ID 1
+#define CONFIG_GLX 1
+#define CONFIG_ZERO_MALLOC 1
+#define CONFIG_QOM_CAST_DEBUG 1
+#define CONFIG_COROUTINE_BACKEND ucontext
+#define CONFIG_COROUTINE_POOL 1
+#define CONFIG_LINUX_MAGIC_H 1
+#define CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE 1
+#define CONFIG_HAS_ENVIRON 1
+#define CONFIG_CPUID_H 1
+#define CONFIG_TPM $(CONFIG_SOFTMMU)
+#define CONFIG_TPM_PASSTHROUGH 1
+#define CONFIG_TRACE_NOP 1
+#define CONFIG_TRACE_FILE trace
+#define HOST_DSOSUF ".so"
+#define CONFIG_ANDROID 1
diff --git a/android-qemu2-glue/main.cpp b/android-qemu2-glue/main.cpp
old mode 100644
new mode 100755
diff --git a/android-qemu2-glue/scripts/gen-acpi-hex-files.bash b/android-qemu2-glue/scripts/gen-acpi-hex-files.bash
new file mode 100644
index 0000000..0220824
--- /dev/null
+++ b/android-qemu2-glue/scripts/gen-acpi-hex-files.bash
@@ -0,0 +1,66 @@
+#!/usr/bin/bash
+
+set -e
+export LANG=C
+export LC_ALL=C
+
+PROGDIR=$(dirname "$0")
+
+die () {
+    echo "ERROR: $@"
+    exit 1
+}
+
+TOPDIR=$(cd "$PROGDIR"/../.. && pwd -P 2>/dev/null || true)
+if [ -z "$TOPDIR" ]; then
+    die "Could not find top-level qemu-android source directory"
+fi
+
+run () {
+    echo "COMMAND: $@"
+    "$@"
+}
+
+find_program () {
+    which $1 2>/dev/null || true
+}
+
+if [ -z "$IASL" ]; then
+    IASL=$(find_program iasl)
+    if [ -z "$IASL" ]; then
+        die "'iasl' command-line tool is not installed!"
+    fi
+fi
+
+if [ -z "$PYTHON" ]; then
+    PYTHON=$(find_program python)
+    if [ -z "$PYTHON" ]; then
+        die "'python' interpreter is not installed!"
+    fi
+fi
+
+if [ -z "$CPP" ]; then
+    CPP=$(find_program cpp)
+    if [ -z "$CPP" ]; then
+        die "'cpp' pre-processor is not installed!"
+    fi
+fi
+
+# $1: target file (e.g. hw/i386/acpi-dsdt.hex.generated)
+# $2: source file (e.g. hw/i386/acpi-dsdt.dsl)
+# $3:
+generate_hex () {
+    local prefix=${1%%.generated}
+    local dst=/tmp/$2
+    local dstdir=$(dirname "$dst")
+    prefix=${prefix%%.hex}
+    mkdir -p $dstdir
+    $CPP -x c -P -I $TOPDIR -I $TOPDIR/include -I $TOPDIR/hw/i386 $2 -o $dst.i.orig
+    $PYTHON $TOPDIR/scripts/acpi_extract_preprocess.py $dst.i.orig > $dst.i
+    $IASL -Pn -vs -l -tc -p $prefix $dst.i
+    $PYTHON $TOPDIR/scripts/acpi_extract.py $prefix.lst > $prefix.off
+    cat $prefix.off > $1
+    rm -f $prefix.aml $prefix.hex $prefix.lst $prefix.off
+}
+
+generate_hex hw/i386/acpi-dsdt.hex.generated hw/i386/acpi-dsdt.dsl
diff --git a/audio/coreaudio.c b/audio/coreaudio.c
index 4ac6754..9ef76c4 100644
--- a/audio/coreaudio.c
+++ b/audio/coreaudio.c
@@ -455,7 +455,7 @@
 {
     OSStatus status;
     int err;
-    const char *typ = "playback";
+    const char *typ = isInput ? "record" : "playback";
     AudioValueRange frameRange;
     CoreaudioConf *conf = drv_opaque;
 
@@ -473,7 +473,7 @@
     status = coreaudio_get_voice(&core->deviceID, isInput);
     if (status != kAudioHardwareNoError) {
         coreaudio_logerr2 (status, typ,
-                           "Could not get default output Device\n");
+                           "Could not get default %s device\n", typ);
         return -1;
     }
     if (core->deviceID == kAudioDeviceUnknown) {
@@ -938,7 +938,7 @@
     .pcm_ops        = &coreaudio_pcm_ops,
     .can_be_default = 1,
     .max_voices_out = 1,
-    .max_voices_in  = 0,
+    .max_voices_in  = 1,
     .voice_size_out = sizeof (coreaudioVoiceOut),
     .voice_size_in  = sizeof (coreaudioVoiceIn),
 };
diff --git a/block.c b/block.c
index 30d64e6..8efa999 100644
--- a/block.c
+++ b/block.c
@@ -1042,6 +1042,7 @@
 
     ret = strstart(filename, "json:", &filename);
     assert(ret);
+    (void)ret;
 
     options_obj = qobject_from_json(filename);
     if (!options_obj) {
diff --git a/exec.c b/exec.c
index 8858d8b..62b4d46 100644
--- a/exec.c
+++ b/exec.c
@@ -2318,12 +2318,16 @@
 
     n = dummy_section(&d->map, as, &io_mem_unassigned);
     assert(n == PHYS_SECTION_UNASSIGNED);
+    (void)n;
     n = dummy_section(&d->map, as, &io_mem_notdirty);
     assert(n == PHYS_SECTION_NOTDIRTY);
+    (void)n;
     n = dummy_section(&d->map, as, &io_mem_rom);
     assert(n == PHYS_SECTION_ROM);
+    (void)n;
     n = dummy_section(&d->map, as, &io_mem_watch);
     assert(n == PHYS_SECTION_WATCH);
+    (void)n;
 
     d->phys_map  = (PhysPageEntry) { .ptr = PHYS_MAP_NODE_NIL, .skip = 1 };
     d->as = as;
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 311af6d..e31d30c 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -712,6 +712,7 @@
     rc = snprintf(buffer, sizeof(buffer), "%04x:%02x:%02x.%d",
                   addr->domain, addr->bus, addr->slot, addr->function);
     assert(rc == sizeof(buffer) - 1);
+    (void)rc;
 
     visit_type_str(v, name, &p, errp);
 }
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index c0f560b..838f4a7 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -128,7 +128,8 @@
 static void sysbus_mmio_map_common(SysBusDevice *dev, int n, hwaddr addr,
                                    bool may_overlap, int priority)
 {
-    assert(n >= 0 && n < dev->num_mmio);
+    assert(n >= 0);
+    assert(n < dev->num_mmio);
 
     if (dev->mmio[n].addr == addr) {
         /* ??? region already mapped here.  */
diff --git a/hw/i386/acpi-dsdt-goldfish.dsl b/hw/i386/acpi-dsdt-goldfish.dsl
new file mode 100644
index 0000000..7976c6f
--- /dev/null
+++ b/hw/i386/acpi-dsdt-goldfish.dsl
@@ -0,0 +1,126 @@
+/*
+** Copyright (c) 2015, Intel Corporation
+**
+** This software is licensed under the terms of the GNU General Public
+** License version 2, as published by the Free Software Foundation, and
+** may be copied, distributed, and modified under those terms.
+**
+** 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.
+*/
+
+/****************************************************************
+ * Android-specific virtual hardware (goldfish devices)
+ ****************************************************************/
+
+#include "hw/acpi/goldfish_defs.h"
+
+Scope(\_SB) {
+
+    /* Battery */
+    Device(GFBY) {
+        Name(_HID, "GFSH0001")
+        Name(_STR, Unicode("goldfish battery"))
+        Name(_CRS, ResourceTemplate() {
+            Memory32Fixed(ReadWrite,
+                GF_BATTERY_IOMEM_BASE,
+                GF_BATTERY_IOMEM_SIZE
+                )
+            Interrupt(, Edge, ActiveHigh) {
+                GF_BATTERY_IRQ
+            }
+        })
+    }
+
+    /* Events */
+    Device(GFEV) {
+        Name(_HID, "GFSH0002")
+        Name(_STR, Unicode("goldfish events"))
+        Name(_CRS, ResourceTemplate() {
+            Memory32Fixed(ReadWrite,
+                GF_EVENTS_IOMEM_BASE,
+                GF_EVENTS_IOMEM_SIZE
+                )
+            Interrupt(, Edge, ActiveHigh) {
+                GF_EVENTS_IRQ
+            }
+        })
+    }
+
+    /* Pipe */
+    Device(GFPP) {
+        Name(_HID, "GFSH0003")
+        Name(_STR, Unicode("android pipe"))
+        Name(_CRS, ResourceTemplate() {
+            Memory32Fixed(ReadWrite,
+                GF_PIPE_IOMEM_BASE,
+                GF_PIPE_IOMEM_SIZE
+                )
+            Interrupt(, Edge, ActiveHigh) {
+                GF_PIPE_IRQ
+            }
+        })
+    }
+
+    /* Framebuffer */
+    Device(GFFB) {
+        Name(_HID, "GFSH0004")
+        Name(_STR, Unicode("goldfish framebuffer"))
+        Name(_CRS, ResourceTemplate() {
+            Memory32Fixed(ReadWrite,
+                GF_FB_IOMEM_BASE,
+                GF_FB_IOMEM_SIZE
+                )
+            Interrupt(, Edge, ActiveHigh) {
+                GF_FB_IRQ
+            }
+        })
+    }
+
+    /* Audio */
+    Device(GFAU) {
+        Name(_HID, "GFSH0005")
+        Name(_STR, Unicode("goldfish audio"))
+        Name(_CRS, ResourceTemplate() {
+            Memory32Fixed(ReadWrite,
+                GF_AUDIO_IOMEM_BASE,
+                GF_AUDIO_IOMEM_SIZE
+                )
+            Interrupt(, Edge, ActiveHigh) {
+                GF_AUDIO_IRQ
+            }
+        })
+    }
+
+    /* Sync */
+    Device(GFSK) {
+        Name(_HID, "GFSH0006")
+        Name(_STR, Unicode("goldfish sync"))
+        Name(_CRS, ResourceTemplate() {
+            Memory32Fixed(ReadWrite,
+                GF_SYNC_IOMEM_BASE,
+                GF_SYNC_IOMEM_SIZE
+                )
+            Interrupt(, Edge, ActiveHigh) {
+                GF_SYNC_IRQ
+                }
+        })
+    }
+
+    /* RTC */
+    Device(GFRT) {
+        Name(_HID, "GFSH0007")
+        Name(_STR, Unicode("goldfish rtc"))
+        Name(_CRS, ResourceTemplate() {
+            Memory32Fixed(ReadWrite,
+                GF_RTC_IOMEM_BASE,
+                GF_RTC_IOMEM_SIZE
+                )
+            Interrupt(, Edge, ActiveHigh) {
+                GF_RTC_IRQ
+            }
+        })
+    }
+}
diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index 8238fbc..f92e972 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -929,6 +929,7 @@
 
     r = kvm_device_pci_deassign(kvm_state, dev->dev_id);
     assert(r == 0);
+    (void)r;
 }
 
 /* The pci config space got updated. Check if irq numbers have changed
diff --git a/hw/misc/goldfish_pipe.c b/hw/misc/goldfish_pipe.c
old mode 100644
new mode 100755
diff --git a/hw/misc/pci-testdev.c b/hw/misc/pci-testdev.c
index 7d59902..abfc2df 100644
--- a/hw/misc/pci-testdev.c
+++ b/hw/misc/pci-testdev.c
@@ -279,6 +279,7 @@
         }
         r = event_notifier_init(&test->notifier, 0);
         assert(r >= 0);
+        (void)r;
         test->hasnotifier = true;
     }
 }
diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c
index bab4dbf..390c297 100644
--- a/hw/net/eepro100.c
+++ b/hw/net/eepro100.c
@@ -572,6 +572,7 @@
         int r = pci_add_capability(&s->dev, PCI_CAP_ID_PM,
                                    cfg_offset, PCI_PM_SIZEOF);
         assert(r >= 0);
+        (void)r;
         pci_set_word(pci_conf + cfg_offset + PCI_PM_PMC, 0x7e21);
 #if 0 /* TODO: replace dummy code for power management emulation. */
         /* TODO: Power Management Control / Status. */
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 01f1351..b8cf936 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -507,9 +507,11 @@
         if (i < n->curr_queues) {
             r = peer_attach(n, i);
             assert(!r);
+            (void)r;
         } else {
             r = peer_detach(n, i);
             assert(!r);
+            (void)r;
         }
     }
 }
diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
index 90f6943..d67d83c 100644
--- a/hw/net/vmxnet3.c
+++ b/hw/net/vmxnet3.c
@@ -1517,6 +1517,7 @@
     s->event_int_idx =
         VMXNET3_READ_DRV_SHARED8(d, s->drv_shmem, devRead.intrConf.eventIntrIdx);
     assert(vmxnet3_verify_intx(s, s->event_int_idx));
+    (void)vmxnet3_verify_intx;
     VMW_CFPRN("Events interrupt line is %u", s->event_int_idx);
 
     s->auto_int_masking =
diff --git a/hw/pci/msi.c b/hw/pci/msi.c
index a87b227..c328a6c 100644
--- a/hw/pci/msi.c
+++ b/hw/pci/msi.c
@@ -315,6 +315,7 @@
     MSIMessage msg;
 
     assert(vector < nr_vectors);
+    (void)nr_vectors;
     if (msi_is_masked(dev, vector)) {
         assert(flags & PCI_MSI_FLAGS_MASKBIT);
         pci_long_test_and_set_mask(
diff --git a/hw/pci/msix.c b/hw/pci/msix.c
index 0ec1cb1..ab457b0 100644
--- a/hw/pci/msix.c
+++ b/hw/pci/msix.c
@@ -110,6 +110,7 @@
         msg = msix_get_message(dev, vector);
         ret = dev->msix_vector_use_notifier(dev, vector, msg);
         assert(ret >= 0);
+        (void)ret;
     }
 }
 
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 24fae16..32d9df4 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -2433,6 +2433,7 @@
         s = snprintf(slot, sizeof slot, ":%02x.%x",
                      PCI_SLOT(t->devfn), PCI_FUNC(t->devfn));
         assert(s == slot_len);
+        (void)s;
         memcpy(p, slot, slot_len);
     }
 
diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index 99cfb45..2c29af1 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -417,6 +417,7 @@
 
     assert(port_type == PCI_EXP_TYPE_DOWNSTREAM ||
            port_type == PCI_EXP_TYPE_ROOT_PORT);
+    (void)port_type;
 
     PCIE_DEV_PRINTF(dev, "reset\n");
 
diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c
index 048ce6a..6f87e3c 100644
--- a/hw/pci/pcie_aer.c
+++ b/hw/pci/pcie_aer.c
@@ -702,6 +702,7 @@
         };
         int ret = pcie_aer_inject_error(dev, &header_log_overflow);
         assert(!ret);
+        (void)ret;
     }
     return 0;
 }
diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c
index df205cd..dbaf4d4 100644
--- a/hw/scsi/lsi53c895a.c
+++ b/hw/scsi/lsi53c895a.c
@@ -549,6 +549,7 @@
     pci_dev = PCI_DEVICE(s);
     dev = s->current->req->dev;
     assert(dev);
+    (void)dev;
 
     count = s->dbc;
     if (count > s->current->dma_len)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 836a155..edae532 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -1422,6 +1422,7 @@
     memset(mode_changeable, 0, inlen + 2);
     changeable_len = mode_sense_page(s, page, &p, 1);
     assert(changeable_len == len);
+    (void)changeable_len;
 
     /* Check that unchangeable bits are the same as what MODE SENSE
      * would return.
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index ce57ef6..db64574 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -188,6 +188,7 @@
     uint32_t n = virtio_get_queue_index(req->vq) - 2;
 
     assert(n < vs->conf.num_queues);
+    (void)vs;
     qemu_put_be32s(f, &n);
     qemu_put_virtqueue_element(f, &req->elem);
 }
@@ -214,7 +215,9 @@
     scsi_req_ref(sreq);
     req->sreq = sreq;
     if (req->sreq->cmd.mode != SCSI_XFER_NONE) {
-        assert(req->sreq->cmd.mode == req->mode);
+        if (!(req->sreq->cmd.mode == req->mode)) {
+            abort();
+        }
     }
     return req;
 }
diff --git a/hw/scsi/vmw_pvscsi.c b/hw/scsi/vmw_pvscsi.c
index 5116f4a..d6a91e1 100644
--- a/hw/scsi/vmw_pvscsi.c
+++ b/hw/scsi/vmw_pvscsi.c
@@ -957,6 +957,7 @@
     size_t bytes_arrived = s->curr_cmd_data_cntr * sizeof(uint32_t);
 
     assert(bytes_arrived < sizeof(s->curr_cmd_data));
+    (void)bytes_arrived;
     s->curr_cmd_data[s->curr_cmd_data_cntr++] = value;
 
     pvscsi_do_command_processing(s);
@@ -1179,6 +1180,7 @@
 
     assert(QTAILQ_EMPTY(&s->pending_queue));
     assert(QTAILQ_EMPTY(&s->completion_queue));
+    (void)s;
 }
 
 static int
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 188f954..a0b9c37 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -3668,6 +3668,7 @@
         xhci_get_flag(xhci, XHCI_FLAG_FORCE_PCIE_ENDCAP)) {
         ret = pcie_endpoint_cap_init(dev, 0xa0);
         assert(ret >= 0);
+        (void)ret;
     }
 
     if (xhci->msix != ON_OFF_AUTO_OFF) {
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 3d0c807..0b7f8f9 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -578,6 +578,7 @@
 
         r = vhost_verify_ring_mappings(dev, start_addr, size);
         assert(r >= 0);
+        (void)r;
     }
 
     if (!dev->log_enabled) {
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 755f921..75697fc 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -747,6 +747,7 @@
 
     ret = kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, n, irqfd->virq);
     assert(ret == 0);
+    (void)ret;
 }
 
 static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 74c085c..db90a31 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -1089,6 +1089,7 @@
      * silently failing to migrate this state)
      */
     assert(k->has_variable_vring_alignment);
+    (void)k;
 
     vdev->vq[n].vring.align = align;
     virtio_queue_update_rings(vdev, n);
diff --git a/include/ui/pixel_ops.h b/include/ui/pixel_ops.h
index d390adf..44b7a6f 100644
--- a/include/ui/pixel_ops.h
+++ b/include/ui/pixel_ops.h
@@ -43,11 +43,11 @@
 static inline unsigned int rgb_to_pixel32(unsigned int r, unsigned int g,
                                           unsigned int b)
 {
-    return (r << 16) | (g << 8) | b;
+    return (r << 16) | (g << 8) | b | 0xFF000000;
 }
 
 static inline unsigned int rgb_to_pixel32bgr(unsigned int r, unsigned int g,
                                              unsigned int b)
 {
-    return (b << 16) | (g << 8) | r;
+    return (b << 16) | (g << 8) | r | 0xFF000000;
 }
diff --git a/include/ui/qemu-pixman.h b/include/ui/qemu-pixman.h
index d24e351..3a19649 100644
--- a/include/ui/qemu-pixman.h
+++ b/include/ui/qemu-pixman.h
@@ -18,6 +18,8 @@
 
 #include <stdbool.h>
 
+#include <stdbool.h>
+
 /*
  * pixman image formats are defined to be native endian,
  * that means host byte order on qemu.  So we go define
diff --git a/kvm-all.c b/kvm-all.c
index 150aa20..8de8f71 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1051,6 +1051,7 @@
     trace_kvm_irqchip_commit_routes();
     ret = kvm_vm_ioctl(s, KVM_SET_GSI_ROUTING, s->irq_routes);
     assert(ret == 0);
+    (void)ret;
 }
 
 static void kvm_add_routing_entry(KVMState *s,
diff --git a/net/dump.c b/net/dump.c
index 89a149b..219d8d0 100644
--- a/net/dump.c
+++ b/net/dump.c
@@ -202,6 +202,7 @@
 
         ret = net_hub_id_for_client(peer, &id);
         assert(ret == 0); /* peer must be on a hub */
+        (void)ret;
 
         snprintf(def_file, sizeof(def_file), "qemu-vlan%d.pcap", id);
         file = def_file;
diff --git a/qemu-char.c b/qemu-char.c
index 9fb023d..71a78bc 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -900,6 +900,7 @@
      */
     IOWatchPoll *iwp = io_watch_poll_from_source(source);
     assert(iwp->src == NULL);
+    (void)iwp;
 }
 
 static GSourceFuncs io_watch_poll_funcs = {
diff --git a/qemu-options.def b/qemu-options.def
index 3822c5b..f187141 100644
--- a/qemu-options.def
+++ b/qemu-options.def
@@ -894,3 +894,4 @@
 
 #endif  // CONFIG_ANDROID
 
+
diff --git a/qemu-options.hx b/qemu-options.hx
index 92705ac..1b0e6a0 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -190,8 +190,8 @@
 qemu-system-i386 -global ide-drive.physical_block_size=4096 -drive file=file,if=ide,index=0,media=disk
 @end example
 
-In particular, you can use this to set driver properties for devices which are 
-created automatically by the machine model. To create a device which is not 
+In particular, you can use this to set driver properties for devices which are
+created automatically by the machine model. To create a device which is not
 created automatically and set properties on it, use -@option{device}.
 
 -global @var{driver}.@var{prop}=@var{value} is shorthand for -global
@@ -4072,3 +4072,4 @@
 STEXI
 @end table
 ETEXI
+
diff --git a/qobject/qdict.c b/qobject/qdict.c
index 60f158c..6d66255 100644
--- a/qobject/qdict.c
+++ b/qobject/qdict.c
@@ -656,11 +656,13 @@
 
         snprintf_ret = snprintf(indexstr, 32, "%u", i);
         assert(snprintf_ret < 32);
+        (void)snprintf_ret;
 
         subqobj = qdict_get(src, indexstr);
 
         snprintf_ret = snprintf(prefix, 32, "%u.", i);
         assert(snprintf_ret < 32);
+        (void)snprintf_ret;
 
         /* Overflow is the same as positive non-zero results */
         is_subqdict = qdict_count_prefixed_entries(src, prefix);
diff --git a/target-arm/helper.c b/target-arm/helper.c
index bdb842c..addd042 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -4334,6 +4334,7 @@
     ctx_cmps = extract32(cpu->dbgdidr, 20, 4);
 
     assert(ctx_cmps <= brps);
+    (void)ctx_cmps;
 
     /* The DBGDIDR and ID_AA64DFR0_EL1 define various properties
      * of the debug registers such as number of breakpoints;
@@ -5418,6 +5419,7 @@
         }
         /* assert our permissions are not too lax (stricter is fine) */
         assert((r->access & ~mask) == 0);
+        (void)mask;
     }
 
     /* Check that the register definition has enough info to handle
diff --git a/target-mips/msa_helper.c b/target-mips/msa_helper.c
index 1fdb0d9..a8d8d09 100644
--- a/target-mips/msa_helper.c
+++ b/target-mips/msa_helper.c
@@ -91,7 +91,7 @@
 {
     wr_t *pwd = &(env->active_fpu.fpr[wd].wr);
     wr_t *pws = &(env->active_fpu.fpr[ws].wr);
-    wr_t wx, *pwx = &wx;
+    wr_t wx = {}, *pwx = &wx;
     uint32_t i;
 
     switch (df) {
@@ -1130,7 +1130,7 @@
     wr_t *pwd = &(env->active_fpu.fpr[wd].wr);                      \
     wr_t *pws = &(env->active_fpu.fpr[ws].wr);                      \
     wr_t *pwt = &(env->active_fpu.fpr[wt].wr);                      \
-    wr_t wx, *pwx = &wx;                                            \
+    wr_t wx = {}, *pwx = &wx;                                       \
     uint32_t i;                                                     \
     switch (df) {                                                   \
     case DF_BYTE:                                                   \
@@ -3395,7 +3395,7 @@
 void helper_msa_ffint_s_df(CPUMIPSState *env, uint32_t df, uint32_t wd,
                            uint32_t ws)
 {
-    wr_t wx, *pwx = &wx;
+    wr_t wx = {}, *pwx = &wx;
     wr_t *pwd = &(env->active_fpu.fpr[wd].wr);
     wr_t *pws = &(env->active_fpu.fpr[ws].wr);
     uint32_t i;
@@ -3425,7 +3425,7 @@
 void helper_msa_ffint_u_df(CPUMIPSState *env, uint32_t df, uint32_t wd,
                            uint32_t ws)
 {
-    wr_t wx, *pwx = &wx;
+    wr_t wx = {}, *pwx = &wx;
     wr_t *pwd = &(env->active_fpu.fpr[wd].wr);
     wr_t *pws = &(env->active_fpu.fpr[ws].wr);
     uint32_t i;
diff --git a/util/iov.c b/util/iov.c
index 74e6ca8..dc12bab 100644
--- a/util/iov.c
+++ b/util/iov.c
@@ -575,6 +575,7 @@
     assert(qiov->size >= bytes);
     total = iov_discard_back(qiov->iov, &niov, bytes);
     assert(total == bytes);
+    (void)total;
 
     qiov->niov = niov;
     qiov->size -= bytes;
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 3467dc2..135242a 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -933,6 +933,7 @@
 
     opts = opts_parse(list, params, permit_abbrev, true, NULL);
     assert(opts);
+    (void)opts;
 }
 
 typedef struct OptsFromQDictState {
@@ -959,12 +960,14 @@
         n = snprintf(buf, sizeof(buf), "%" PRId64,
                      qint_get_int(qobject_to_qint(obj)));
         assert(n < sizeof(buf));
+        (void)n;
         value = buf;
         break;
     case QTYPE_QFLOAT:
         n = snprintf(buf, sizeof(buf), "%.17g",
                      qfloat_get_double(qobject_to_qfloat(obj)));
         assert(n < sizeof(buf));
+        (void)n;
         value = buf;
         break;
     case QTYPE_QBOOL:
diff --git a/vl.c b/vl.c
index f22ca8f..653f2fc 100755
--- a/vl.c
+++ b/vl.c
@@ -4996,10 +4996,16 @@
         return 1;
     }
 
-    default_drive(default_cdrom, snapshot, machine_class->block_default_type, 2,
-                  CDROM_OPTS);
-    default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS);
-    default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS);
+    if (!default_drive(default_cdrom, snapshot,
+                       machine_class->block_default_type, 2, CDROM_OPTS)) {
+        return 1;
+    }
+    if (!default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS)) {
+        return 1;
+    }
+    if (!default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS)) {
+        return 1;
+    }
 
     parse_numa_opts(machine_class);
 
@@ -5039,7 +5045,7 @@
     if (watchdog) {
         i = select_watchdog(watchdog);
         if (i > 0)
-            exit (i == 1 ? 1 : 0);
+            return (i == 1 ? 1 : 0);
     }
 
     machine_register_compat_props(current_machine);