Skip to contentSkip to conversation

Clean up some hw_error() misuse

PATCH Superseded Markus Armbruster 6 participants 28 messages Dec 17, 2015 Arm Samsung Exynos

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#27 lore raw

PATCH v2 13/13 xen-hvm: Mark inappropriate error handling FIXME

In reply to Markus Armbruster
---
 xen-hvm.c | 7 +++++++
 1 file changed, 7 insertions(+)
xen-hvm.c +7 -0
index 3d78a0c..2a93390 100644
@@ -240,6 +240,7 @@ static void xen_ram_init(PCMachineState *pcms,
 
 void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr)
 {
+    /* FIXME caller ram_block_add() wants error_setg() on failure */
     unsigned long nr_pfn;
     xen_pfn_t *pfn_list;
     int i;
@@ -1192,6 +1193,12 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data)
 int xen_hvm_init(PCMachineState *pcms,
                  MemoryRegion **ram_memory)
 {
+    /*
+     * FIXME Returns -1 without cleaning up on some errors (harmless
+     * as long as the caller exit()s on error), dies with hw_error()
+     * on others.  hw_error() isn't approprate here.  Should probably
+     * simply exit() on all errors.
+     */
     int i, rc;
     xen_pfn_t ioreq_pfn;
     xen_pfn_t bufioreq_pfn;
Signature · 1 line
2.4.3
#0 lore raw

v2 cover Clean up some hw_error() misuse

I intend to take this through my tree, but I'm certainly fine with maintainers picking up their parts if that makes their job easier. Just be clear about it.

v2:
* PATCH 1: Supply missing exit() [Thomas]
* PATCH 2: Improve commit message [Peter]
* PATCH 3: Fix up error message [Peter]
* PATCH 6: New, to unbreak the next patch [Peter]

Markus Armbruster (13):
hw: Don't use hw_error() for machine initialization errors
omap: Don't use hw_error() in device init() methods
arm_mptimer: Don't use hw_error() in realize() method
etraxfs_eth: Don't use hw_error() in init() method
raven: Mark use of hw_error() in realize() FIXME
error: Don't append a newline when printing the error hint hw/arm/virt: Fix property "gic-version" error handling
sysbus: Don't use hw_error() in machine_init_done_notifiers
isa: Trivially convert remaining PCI-ISA bridges to realize()
isa: Clean up error handling around isa_bus_new()
isa: Clean up inappropriate hw_error()
audio: Clean up inappropriate and unreachable use of hw_error()
xen-hvm: Mark inappropriate error handling FIXME

 audio/audio.c             | 11 ++---------
 hw/alpha/dp264.c          | 11 ++++++-----
 hw/alpha/typhoon.c        |  3 ++-
 hw/arm/highbank.c         |  6 ++++--
 hw/arm/virt.c             |  5 ++---
 hw/char/exynos4210_uart.c |  9 ++++++---
 hw/core/platform-bus.c    | 25 ++++++++++++-------------
 hw/gpio/omap_gpio.c       | 19 +++++++++++++++----
 hw/i2c/omap_i2c.c         |  8 ++++++--
 hw/i386/pc_piix.c         |  3 ++-
 hw/intc/omap_intc.c       | 10 +++++++---
 hw/isa/i82378.c           |  5 ++++-
 hw/isa/isa-bus.c          | 15 ++-------------
 hw/isa/lpc_ich9.c         | 11 +++++++----
 hw/isa/piix4.c            |  6 ++++--
 hw/isa/vt82c686.c         |  5 ++++-
 hw/m68k/an5206.c          |  4 +++-
 hw/mips/mips_jazz.c       |  2 +-
 hw/mips/mips_r4k.c        |  2 +-
 hw/net/etraxfs_eth.c      |  4 +++-
 hw/pci-host/piix.c        |  6 ++++--
 hw/pci-host/prep.c        |  6 ++++--
 hw/ppc/mac_newworld.c     | 11 ++++++-----
 hw/ppc/mac_oldworld.c     | 16 +++++++++-------
 hw/ppc/prep.c             | 11 +++++++----
 hw/sparc64/sun4u.c        | 12 ++++++------
 hw/timer/arm_mptimer.c    |  5 +++--
 hw/unicore32/puv3.c       | 10 +++++++---
 include/hw/isa/isa.h      |  2 +-
 qdev-monitor.c            |  2 ++
 util/error.c              |  2 +-
 util/qemu-option.c        |  4 ++--
 xen-hvm.c                 |  7 +++++++
 33 files changed, 152 insertions(+), 106 deletions(-)
Signature · 1 line
2.4.3
#11 lore raw

PATCH v2 6/13 error: Don't append a newline when printing the error hint

Since commit 50b7b00, we have error_append_hint() to conveniently accumulate Error member @hint. error_report_err() prints it with a newline appended. Consequently, users of error_append_hint() need to know whether theirs is the final line of the hint to decide whether it needs a newline. Not a nice interface.

Change error_report_err() to print just the hint, and the (still few) users of error_append_hint() to add the required newline.

---
 qdev-monitor.c     | 2 ++
 util/error.c       | 2 +-
 util/qemu-option.c | 4 ++--
 3 files changed, 5 insertions(+), 3 deletions(-)
qdev-monitor.c +2 -0
index a35098f..30936df 100644
@@ -304,6 +304,7 @@ static void qbus_list_bus(DeviceState *dev, Error **errp)
         error_append_hint(errp, "%s\"%s\"", sep, child->name);
         sep = ", ";
     }
+    error_append_hint(errp, "\n");
 }
 
 static void qbus_list_dev(BusState *bus, Error **errp)
@@ -321,6 +322,7 @@ static void qbus_list_dev(BusState *bus, Error **errp)
         }
         sep = ", ";
     }
+    error_append_hint(errp, "\n");
 }
 
 static BusState *qbus_find_bus(DeviceState *dev, char *elem)
util/error.c +1 -1
index 80c89a2..9b27c45 100644
@@ -204,7 +204,7 @@ void error_report_err(Error *err)
 {
     error_report("%s", error_get_pretty(err));
     if (err->hint) {
-        error_printf_unless_qmp("%s\n", err->hint->str);
+        error_printf_unless_qmp("%s", err->hint->str);
     }
     error_free(err);
 }
util/qemu-option.c +2 -2
index a50ecea..a2d593a 100644
@@ -206,7 +206,7 @@ void parse_option_size(const char *name, const char *value,
         default:
             error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name, "a size");
             error_append_hint(errp, "You may use k, M, G or T suffixes for "
-                    "kilobytes, megabytes, gigabytes and terabytes.");
+                    "kilobytes, megabytes, gigabytes and terabytes.\n");
             return;
         }
     } else {
@@ -647,7 +647,7 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
             error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id",
                        "an identifier");
             error_append_hint(errp, "Identifiers consist of letters, digits, "
-                              "'-', '.', '_', starting with a letter.");
+                              "'-', '.', '_', starting with a letter.\n");
             return NULL;
         }
         opts = qemu_opts_find(list, id);
Signature · 1 line
2.4.3
#17 lore raw

PATCH v2 9/13 isa: Trivially convert remaining PCI-ISA bridges to realize()

In reply to Markus Armbruster

These are "ICH9-LPC" and "ebus".

Cc "Michael S. Tsirkin" <[email protected]>
Cc Mark Cave-Ayland <[email protected]>
---
 hw/isa/lpc_ich9.c  | 5 ++---
 hw/sparc64/sun4u.c | 6 ++----
 2 files changed, 4 insertions(+), 7 deletions(-)
hw/isa/lpc_ich9.c +2 -3
index 1ffc803..8e58449 100644
@@ -602,7 +602,7 @@ static void ich9_lpc_initfn(Object *obj)
     ich9_lpc_add_properties(lpc);
 }
 
-static int ich9_lpc_init(PCIDevice *d)
+static void ich9_lpc_realize(PCIDevice *d, Error **errp)
 {
     ICH9LPCState *lpc = ICH9_LPC_DEVICE(d);
     ISABus *isa_bus;
@@ -628,7 +628,6 @@ static int ich9_lpc_init(PCIDevice *d)
     memory_region_add_subregion_overlap(pci_address_space_io(d),
                                         ICH9_RST_CNT_IOPORT, &lpc->rst_cnt_mem,
                                         1);
-    return 0;
 }
 
 static void ich9_device_plug_cb(HotplugHandler *hotplug_dev,
@@ -706,7 +705,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data)
 
     set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
     dc->reset = ich9_lpc_reset;
-    k->init = ich9_lpc_init;
+    k->realize = ich9_lpc_realize;
     dc->vmsd = &vmstate_ich9_lpc;
     dc->props = ich9_lpc_properties;
     k->config_write = ich9_lpc_config_write;
hw/sparc64/sun4u.c +2 -4
index d6b929c..c37e8b0 100644
@@ -593,8 +593,7 @@ pci_ebus_init(PCIBus *bus, int devfn, qemu_irq *irqs)
     return isa_bus;
 }
 
-static int
-pci_ebus_init1(PCIDevice *pci_dev)
+static void pci_ebus_realize(PCIDevice *pci_dev, Error **errp)
 {
     EbusState *s = DO_UPCAST(EbusState, pci_dev, pci_dev);
 
@@ -614,14 +613,13 @@ pci_ebus_init1(PCIDevice *pci_dev)
     memory_region_init_alias(&s->bar1, OBJECT(s), "bar1", get_system_io(),
                              0, 0x4000);
     pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_SPACE_IO, &s->bar1);
-    return 0;
 }
 
 static void ebus_class_init(ObjectClass *klass, void *data)
 {
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = pci_ebus_init1;
+    k->realize = pci_ebus_realize;
     k->vendor_id = PCI_VENDOR_ID_SUN;
     k->device_id = PCI_DEVICE_ID_SUN_EBUS;
     k->revision = 0x01;
Signature · 1 line
2.4.3
#21 lore raw

PATCH v2 11/13 isa: Clean up inappropriate hw_error()

In reply to Markus Armbruster

isa_bus_irqs(), isa_create() and isa_try_create() call hw_error() when passed a null bus. Use of hw_error() has always been questionable, because these are used only during machine initialization, and printing CPU registers isn't useful there.

Since the previous commit, passing a null bus is a programming error. Drop the hw_error() and simply let it crash.

Cc Richard Henderson <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc "Hervé Poussineau" <[email protected]>
Cc Aurelien Jarno <[email protected]>
Cc Mark Cave-Ayland <[email protected]>
---
 hw/isa/isa-bus.c | 11 -----------
 1 file changed, 11 deletions(-)
hw/isa/isa-bus.c +0 -11
index af6ffd6..630054c 100644
@@ -63,9 +63,6 @@ ISABus *isa_bus_new(DeviceState *dev, MemoryRegion* address_space,
 
 void isa_bus_irqs(ISABus *bus, qemu_irq *irqs)
 {
-    if (!bus) {
-        hw_error("Can't set isa irqs with no isa bus present.");
-    }
     bus->irqs = irqs;
 }
 
@@ -137,10 +134,6 @@ ISADevice *isa_create(ISABus *bus, const char *name)
 {
     DeviceState *dev;
 
-    if (!bus) {
-        hw_error("Tried to create isa device %s with no isa bus present.",
-                 name);
-    }
     dev = qdev_create(BUS(bus), name);
     return ISA_DEVICE(dev);
 }
@@ -149,10 +142,6 @@ ISADevice *isa_try_create(ISABus *bus, const char *name)
 {
     DeviceState *dev;
 
-    if (!bus) {
-        hw_error("Tried to create isa device %s with no isa bus present.",
-                 name);
-    }
     dev = qdev_try_create(BUS(bus), name);
     return ISA_DEVICE(dev);
 }
Signature · 1 line
2.4.3
#19 lore raw

PATCH v2 10/13 isa: Clean up error handling around isa_bus_new()

In reply to Markus Armbruster

We can have at most one ISA bus. If you try to create another one, isa_bus_new() complains to stderr and returns null.

isa_bus_new() is called in two contexts, machine's init() and device's realize() methods. Since complaining to stderr is not proper in the latter context, convert isa_bus_new() to Error.

Machine's init():

* mips_jazz_init(), called from the init() methods of machines "magnum" and "pica"

* mips_r4k_init(), the init() method of machine "mips"

* pc_init1() called from the init() methods of non-q35 PC machines

* typhoon_init(), called from clipper_init(), the init() method of machine "clipper"

These callers always create the first ISA bus, hence isa_bus_new() can't fail. Simply pass &error_abort.

Device's realize():

* i82378_realize(), of PCI device "i82378"

* ich9_lpc_realize(), of PCI device "ICH9-LPC"

* pci_ebus_realize(), of PCI device "ebus"

* piix3_realize(), of PCI device "pci-piix3", abstract parent of "PIIX3" and "PIIX3-xen"

* piix4_realize(), of PCI device "PIIX4"

* vt82c686b_realize(), of PCI device "VT82C686B"

Propagate the error. Note that these devices are typically created only by machine init() methods with qdev_init_nofail() or similar. If we screwed up and created an ISA bus before that call, we now give up right away. Before, we'd hobble on, and typically die in isa_bus_irqs(). Similar if someone finds a way to hot-plug one of these critters.

Cc Richard Henderson <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc "Hervé Poussineau" <[email protected]>
Cc Aurelien Jarno <[email protected]>
Cc Mark Cave-Ayland <[email protected]>
---
 hw/alpha/typhoon.c   | 3 ++-
 hw/i386/pc_piix.c    | 3 ++-
 hw/isa/i82378.c      | 5 ++++-
 hw/isa/isa-bus.c     | 4 ++--
 hw/isa/lpc_ich9.c    | 6 +++++-
 hw/isa/piix4.c       | 6 ++++--
 hw/isa/vt82c686.c    | 5 ++++-
 hw/mips/mips_jazz.c  | 2 +-
 hw/mips/mips_r4k.c   | 2 +-
 hw/pci-host/piix.c   | 6 ++++--
 hw/sparc64/sun4u.c   | 6 ++++--
 include/hw/isa/isa.h | 2 +-
 12 files changed, 34 insertions(+), 16 deletions(-)
hw/alpha/typhoon.c +2 -1
index 421162e..35dc8a5 100644
@@ -920,7 +920,8 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus **isa_bus,
     {
         qemu_irq *isa_irqs;
 
-        *isa_bus = isa_bus_new(NULL, get_system_memory(), &s->pchip.reg_io);
+        *isa_bus = isa_bus_new(NULL, get_system_memory(), &s->pchip.reg_io,
+                               &error_abort);
         isa_irqs = i8259_init(*isa_bus,
                               qemu_allocate_irq(typhoon_set_isa_irq, s, 0));
         isa_bus_irqs(*isa_bus, isa_irqs);
hw/i386/pc_piix.c +2 -1
index 2e41efe..48fdad4 100644
@@ -200,7 +200,8 @@ static void pc_init1(MachineState *machine,
     } else {
         pci_bus = NULL;
         i440fx_state = NULL;
-        isa_bus = isa_bus_new(NULL, get_system_memory(), system_io);
+        isa_bus = isa_bus_new(NULL, get_system_memory(), system_io,
+                              &error_abort);
         no_hpet = 1;
     }
     isa_bus_irqs(isa_bus, gsi);
hw/isa/i82378.c +4 -1
index d4c8306..3793c6f 100644
@@ -75,7 +75,10 @@ static void i82378_realize(PCIDevice *pci, Error **errp)
     pci_config_set_interrupt_pin(pci_conf, 1); /* interrupt pin 0 */
 
     isabus = isa_bus_new(dev, get_system_memory(),
-                         pci_address_space_io(pci));
+                         pci_address_space_io(pci), errp);
+    if (!isabus) {
+        return;
+    }
 
     /* This device has:
        2 82C59 (irq)
hw/isa/isa-bus.c +2 -2
index 43e0cd8..af6ffd6 100644
@@ -44,10 +44,10 @@ static const TypeInfo isa_bus_info = {
 };
 
 ISABus *isa_bus_new(DeviceState *dev, MemoryRegion* address_space,
-                    MemoryRegion *address_space_io)
+                    MemoryRegion *address_space_io, Error **errp)
 {
     if (isabus) {
-        fprintf(stderr, "Can't create a second ISA bus\n");
+        error_setg(errp, "Can't create a second ISA bus");
         return NULL;
     }
     if (!dev) {
hw/isa/lpc_ich9.c +5 -1
index 8e58449..ed9907d 100644
@@ -607,7 +607,11 @@ static void ich9_lpc_realize(PCIDevice *d, Error **errp)
     ICH9LPCState *lpc = ICH9_LPC_DEVICE(d);
     ISABus *isa_bus;
 
-    isa_bus = isa_bus_new(DEVICE(d), get_system_memory(), get_system_io());
+    isa_bus = isa_bus_new(DEVICE(d), get_system_memory(), get_system_io(),
+                          errp);
+    if (!isa_bus) {
+        return;
+    }
 
     pci_set_long(d->wmask + ICH9_LPC_PMBASE,
                  ICH9_LPC_PMBASE_BASE_ADDRESS_MASK);
hw/isa/piix4.c +4 -2
index 2c59e91..644cfd9 100644
@@ -90,8 +90,10 @@ static void piix4_realize(PCIDevice *dev, Error **errp)
 {
     PIIX4State *d = PIIX4_PCI_DEVICE(dev);
 
-    isa_bus_new(DEVICE(d), pci_address_space(dev),
-                pci_address_space_io(dev));
+    if (!isa_bus_new(DEVICE(d), pci_address_space(dev),
+                     pci_address_space_io(dev), errp)) {
+        return;
+    }
     piix4_dev = &d->dev;
     qemu_register_reset(piix4_reset, d);
 }
hw/isa/vt82c686.c +4 -1
index 252e1d7..6c2190b 100644
@@ -440,7 +440,10 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
     int i;
 
     isa_bus = isa_bus_new(DEVICE(d), get_system_memory(),
-                          pci_address_space_io(d));
+                          pci_address_space_io(d), errp);
+    if (!isa_bus) {
+        return;
+    }
 
     pci_conf = d->config;
     pci_config_set_prog_interface(pci_conf, 0x0);
hw/mips/mips_jazz.c +1 -1
index 1ab885b..1cfbaa6 100644
@@ -219,7 +219,7 @@ static void mips_jazz_init(MachineState *machine,
     memory_region_init(isa_mem, NULL, "isa-mem", 0x01000000);
     memory_region_add_subregion(address_space, 0x90000000, isa_io);
     memory_region_add_subregion(address_space, 0x91000000, isa_mem);
-    isa_bus = isa_bus_new(NULL, isa_mem, isa_io);
+    isa_bus = isa_bus_new(NULL, isa_mem, isa_io, &error_abort);
 
     /* ISA devices */
     i8259 = i8259_init(isa_bus, env->irq[4]);
hw/mips/mips_r4k.c +1 -1
index af10da1..2d4e038 100644
@@ -272,7 +272,7 @@ void mips_r4k_init(MachineState *machine)
     memory_region_init(isa_mem, NULL, "isa-mem", 0x01000000);
     memory_region_add_subregion(get_system_memory(), 0x14000000, isa_io);
     memory_region_add_subregion(get_system_memory(), 0x10000000, isa_mem);
-    isa_bus = isa_bus_new(NULL, isa_mem, get_system_io());
+    isa_bus = isa_bus_new(NULL, isa_mem, get_system_io(), &error_abort);
 
     /* The PIC is attached to the MIPS CPU INT0 pin */
     i8259 = i8259_init(isa_bus, env->irq[2]);
hw/pci-host/piix.c +4 -2
index 715208b..775b4bd 100644
@@ -651,8 +651,10 @@ static void piix3_realize(PCIDevice *dev, Error **errp)
 {
     PIIX3State *d = PIIX3_PCI_DEVICE(dev);
 
-    isa_bus_new(DEVICE(d), get_system_memory(),
-                pci_address_space_io(dev));
+    if (!isa_bus_new(DEVICE(d), get_system_memory(),
+                     pci_address_space_io(dev), errp)) {
+        return;
+    }
 
     memory_region_init_io(&d->rcr_mem, OBJECT(dev), &rcr_ops, d,
                           "piix3-reset-control", 1);
hw/sparc64/sun4u.c +4 -2
index c37e8b0..6c7596b 100644
@@ -597,8 +597,10 @@ static void pci_ebus_realize(PCIDevice *pci_dev, Error **errp)
 {
     EbusState *s = DO_UPCAST(EbusState, pci_dev, pci_dev);
 
-    isa_bus_new(DEVICE(pci_dev), get_system_memory(),
-                pci_address_space_io(pci_dev));
+    if (!isa_bus_new(DEVICE(pci_dev), get_system_memory(),
+                     pci_address_space_io(pci_dev), errp)) {
+        return;
+    }
 
     pci_dev->config[0x04] = 0x06; // command = bus master, pci mem
     pci_dev->config[0x05] = 0x00;
include/hw/isa/isa.h +1 -1
index d758b39..de3cd3d 100644
@@ -59,7 +59,7 @@ struct ISADevice {
 };
 
 ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space,
-                    MemoryRegion *address_space_io);
+                    MemoryRegion *address_space_io, Error **errp);
 void isa_bus_irqs(ISABus *bus, qemu_irq *irqs);
 qemu_irq isa_get_irq(ISADevice *dev, int isairq);
 void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq);
Signature · 1 line
2.4.3
#26 lore raw

PATCH v2 12/13 audio: Clean up inappropriate and unreachable use of hw_error()

In reply to Markus Armbruster

audio_init() should not use hw_error(), because dumping CPU registers is unhelpful there, and aborting is wrong, because it can be called called from an audio device's realize() method.

The two uses of hw_error() come from commit 0d9acba:

* When qemu_new_timer() fails. It couldn't fail back then, and it can't fail now. Drop the unreachable error handling.

* When no_audio_driver can't be initialized. It couldn't fail back then, and it can't fail now. Replace the error handling by an assertion.

---
 audio/audio.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
audio/audio.c +2 -9
index 5be4b15..9b855ed 100644
@@ -1806,9 +1806,6 @@ static void audio_init (void)
     atexit (audio_atexit);
 
     s->ts = timer_new_ns(QEMU_CLOCK_VIRTUAL, audio_timer, s);
-    if (!s->ts) {
-        hw_error("Could not create audio timer\n");
-    }
 
     audio_process_options ("AUDIO", audio_options);
 
@@ -1859,12 +1856,8 @@ static void audio_init (void)
 
     if (!done) {
         done = !audio_driver_init (s, &no_audio_driver);
-        if (!done) {
-            hw_error("Could not initialize audio subsystem\n");
-        }
-        else {
-            dolog ("warning: Using timer based audio emulation\n");
-        }
+        assert(done);
+        dolog ("warning: Using timer based audio emulation\n");
     }
 
     if (conf.period.hertz <= 0) {
Signature · 1 line
2.4.3
#4 lore raw

PATCH v2 2/13 omap: Don't use hw_error() in device init() methods

In reply to Markus Armbruster

Device init() methods aren't supposed to call hw_error(), they should report the error and fail cleanly. Do that.

The errors are all device misconfiguration. All callers use qdev_init_nofail(), so this patch merely converts hw_error() crashes into &error_abort crashes. Improvement, because now it crashes closer to where the misconfiguration bug would be, and a few more bad examples of hw_error() use are gone.

---
 hw/gpio/omap_gpio.c | 19 +++++++++++++++----
 hw/i2c/omap_i2c.c   |  8 ++++++--
 hw/intc/omap_intc.c | 10 +++++++---
 3 files changed, 28 insertions(+), 9 deletions(-)
hw/gpio/omap_gpio.c +15 -4
index 3c53898..1e0654b 100644
@@ -21,6 +21,7 @@
 #include "hw/hw.h"
 #include "hw/arm/omap.h"
 #include "hw/sysbus.h"
+#include "qemu/error-report.h"
 
 struct omap_gpio_s {
     qemu_irq irq;
@@ -700,8 +701,17 @@ static int omap2_gpio_init(SysBusDevice *sbd)
     int i;
 
     if (!s->iclk) {
-        hw_error("omap2-gpio: iclk not connected\n");
+        error_report("omap2-gpio: iclk not connected");
+        return -1;
     }
+
+    for (i = 0; i < s->modulecount; i++) {
+        if (!s->fclk[i]) {
+            error_report("omap2-gpio: fclk%d not connected", i);
+            return -1;
+        }
+    }
+
     if (s->mpu_model < omap3430) {
         s->modulecount = (s->mpu_model < omap2430) ? 4 : 5;
         memory_region_init_io(&s->iomem, OBJECT(s), &omap2_gpif_top_ops, s,
@@ -710,15 +720,15 @@ static int omap2_gpio_init(SysBusDevice *sbd)
     } else {
         s->modulecount = 6;
     }
+
     s->modules = g_new0(struct omap2_gpio_s, s->modulecount);
     s->handler = g_new0(qemu_irq, s->modulecount * 32);
     qdev_init_gpio_in(dev, omap2_gpio_set, s->modulecount * 32);
     qdev_init_gpio_out(dev, s->handler, s->modulecount * 32);
+
     for (i = 0; i < s->modulecount; i++) {
         struct omap2_gpio_s *m = &s->modules[i];
-        if (!s->fclk[i]) {
-            hw_error("omap2-gpio: fclk%d not connected\n", i);
-        }
+
         m->revision = (s->mpu_model < omap3430) ? 0x18 : 0x25;
         m->handler = &s->handler[i * 32];
         sysbus_init_irq(sbd, &m->irq[0]); /* mpu irq */
@@ -728,6 +738,7 @@ static int omap2_gpio_init(SysBusDevice *sbd)
                               "omap.gpio-module", 0x1000);
         sysbus_init_mmio(sbd, &m->iomem);
     }
+
     return 0;
 }
 
hw/i2c/omap_i2c.c +6 -2
index b6f544a..8b0b146 100644
@@ -20,6 +20,7 @@
 #include "hw/i2c/i2c.h"
 #include "hw/arm/omap.h"
 #include "hw/sysbus.h"
+#include "qemu/error-report.h"
 
 #define TYPE_OMAP_I2C "omap_i2c"
 #define OMAP_I2C(obj) OBJECT_CHECK(OMAPI2CState, (obj), TYPE_OMAP_I2C)
@@ -449,12 +450,15 @@ static int omap_i2c_init(SysBusDevice *sbd)
     OMAPI2CState *s = OMAP_I2C(dev);
 
     if (!s->fclk) {
-        hw_error("omap_i2c: fclk not connected\n");
+        error_report("omap_i2c: fclk not connected");
+        return -1;
     }
     if (s->revision >= OMAP2_INTR_REV && !s->iclk) {
         /* Note that OMAP1 doesn't have a separate interface clock */
-        hw_error("omap_i2c: iclk not connected\n");
+        error_report("omap_i2c: iclk not connected");
+        return -1;
     }
+
     sysbus_init_irq(sbd, &s->irq);
     sysbus_init_irq(sbd, &s->drq[0]);
     sysbus_init_irq(sbd, &s->drq[1]);
hw/intc/omap_intc.c +7 -3
index e9b38a3..07b6272 100644
@@ -20,6 +20,7 @@
 #include "hw/hw.h"
 #include "hw/arm/omap.h"
 #include "hw/sysbus.h"
+#include "qemu/error-report.h"
 
 /* Interrupt Handlers */
 struct omap_intr_handler_bank_s {
@@ -367,7 +368,8 @@ static int omap_intc_init(SysBusDevice *sbd)
     struct omap_intr_handler_s *s = OMAP_INTC(dev);
 
     if (!s->iclk) {
-        hw_error("omap-intc: clk not connected\n");
+        error_report("omap-intc: clk not connected");
+        return -1;
     }
     s->nbanks = 1;
     sysbus_init_irq(sbd, &s->parent_intr[0]);
@@ -608,10 +610,12 @@ static int omap2_intc_init(SysBusDevice *sbd)
     struct omap_intr_handler_s *s = OMAP_INTC(dev);
 
     if (!s->iclk) {
-        hw_error("omap2-intc: iclk not connected\n");
+        error_report("omap2-intc: iclk not connected");
+        return -1;
     }
     if (!s->fclk) {
-        hw_error("omap2-intc: fclk not connected\n");
+        error_report("omap2-intc: fclk not connected");
+        return -1;
     }
     s->level_only = 1;
     s->nbanks = 3;
Signature · 1 line
2.4.3
#9 lore raw

PATCH v2 4/13 etraxfs_eth: Don't use hw_error() in init() method

In reply to Markus Armbruster

Device init() methods aren't supposed to call hw_error(), they should report the error and fail cleanly. Do that.

---
 hw/net/etraxfs_eth.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/net/etraxfs_eth.c +3 -1
index d600275..b562ac9 100644
@@ -26,6 +26,7 @@
 #include "hw/sysbus.h"
 #include "net/net.h"
 #include "hw/cris/etraxfs.h"
+#include "qemu/error-report.h"
 
 #define D(x)
 
@@ -589,7 +590,8 @@ static int fs_eth_init(SysBusDevice *sbd)
     ETRAXFSEthState *s = ETRAX_FS_ETH(dev);
 
     if (!s->dma_out || !s->dma_in) {
-        hw_error("Unconnected ETRAX-FS Ethernet MAC.\n");
+        error_report("Unconnected ETRAX-FS Ethernet MAC");
+        return -1;
     }
 
     s->dma_out->client.push = eth_tx_push;
Signature · 1 line
2.4.3
#10 lore raw

PATCH v2 5/13 raven: Mark use of hw_error() in realize() FIXME

In reply to Markus Armbruster

Device realize() methods aren't supposed to call hw_error(), they should set an error and fail cleanly. Blindly doing that would be easy enough, but then realize() would fail without undoing its side effects. Just mark it FIXME for now.

---
 hw/pci-host/prep.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/pci-host/prep.c +4 -2
index da88cb3..f434596 100644
@@ -326,6 +326,7 @@ static void raven_realize(PCIDevice *d, Error **errp)
             }
         }
         if (bios_size < 0 || bios_size > BIOS_SIZE) {
+            /* FIXME should error_setg() */
             hw_error("qemu: could not load bios image '%s'\n", s->bios_name);
         }
         g_free(filename);
@@ -355,8 +356,9 @@ static void raven_class_init(ObjectClass *klass, void *data)
     dc->desc = "PReP Host Bridge - Motorola Raven";
     dc->vmsd = &vmstate_raven;
     /*
-     * PCI-facing part of the host bridge, not usable without the
-     * host-facing part, which can't be device_add'ed, yet.
+     * Reason: PCI-facing part of the host bridge, not usable without
+     * the host-facing part, which can't be device_add'ed, yet.
+     * Reason: realize() method uses hw_error().
      */
     dc->cannot_instantiate_with_device_add_yet = true;
 }
Signature · 1 line
2.4.3
#15 lore raw

PATCH v2 8/13 sysbus: Don't use hw_error() in machine_init_done_notifiers

In reply to Markus Armbruster

platform_bus_map_irq() and platform_bus_map_mmio() use hw_error() to fail. They run in machine_init_done_notifiers, via platform_bus_init_notify() and link_sysbus_device(). Printing CPU registers is not helpful there.

Replace hw_error() by error_report(); exit(1). If these are programming errors, it should be replaced by an assertion instead.

While there, observe that both functions always return 0, and link_sysbus_device() ignores the return value. Change them to void.

---
 hw/core/platform-bus.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
hw/core/platform-bus.c +12 -13
index 70e0518..aa55d01 100644
@@ -21,6 +21,7 @@
 
 #include "hw/platform-bus.h"
 #include "exec/address-spaces.h"
+#include "qemu/error-report.h"
 #include "sysemu/sysemu.h"
 
 
@@ -106,31 +107,29 @@ static void plaform_bus_refresh_irqs(PlatformBusDevice *pbus)
     pbus->done_gathering = true;
 }
 
-static int platform_bus_map_irq(PlatformBusDevice *pbus, SysBusDevice *sbdev,
-                                int n)
+static void platform_bus_map_irq(PlatformBusDevice *pbus, SysBusDevice *sbdev,
+                                 int n)
 {
     int max_irqs = pbus->num_irqs;
     int irqn;
 
     if (sysbus_is_irq_connected(sbdev, n)) {
         /* IRQ is already mapped, nothing to do */
-        return 0;
+        return;
     }
 
     irqn = find_first_zero_bit(pbus->used_irqs, max_irqs);
     if (irqn >= max_irqs) {
-        hw_error("Platform Bus: Can not fit IRQ line");
-        return -1;
+        error_report("Platform Bus: Can not fit IRQ line");
+        exit(1);
     }
 
     set_bit(irqn, pbus->used_irqs);
     sysbus_connect_irq(sbdev, n, pbus->irqs[irqn]);
-
-    return 0;
 }
 
-static int platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev,
-                                 int n)
+static void platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev,
+                                  int n)
 {
     MemoryRegion *sbdev_mr = sysbus_mmio_get_region(sbdev, n);
     uint64_t size = memory_region_size(sbdev_mr);
@@ -140,7 +139,7 @@ static int platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev,
 
     if (memory_region_is_mapped(sbdev_mr)) {
         /* Region is already mapped, nothing to do */
-        return 0;
+        return;
     }
 
     /*
@@ -155,13 +154,13 @@ static int platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev,
     }
 
     if (!found_region) {
-        hw_error("Platform Bus: Can not fit MMIO region of size %"PRIx64, size);
+        error_report("Platform Bus: Can not fit MMIO region of size %"PRIx64,
+                     size);
+        exit(1);
     }
 
     /* Map the device's region into our Platform Bus MMIO space */
     memory_region_add_subregion(&pbus->mmio, off, sbdev_mr);
-
-    return 0;
 }
 
 /*
Signature · 1 line
2.4.3
#8 lore raw

PATCH v2 3/13 arm_mptimer: Don't use hw_error() in realize() method

In reply to Markus Armbruster

Device realize() methods aren't supposed to call hw_error(), they should set an error and fail cleanly. Do that.

---
 hw/timer/arm_mptimer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/timer/arm_mptimer.c +3 -2
index 3e59c2a..5dfab66 100644
@@ -220,8 +220,9 @@ static void arm_mptimer_realize(DeviceState *dev, Error **errp)
     int i;
 
     if (s->num_cpu < 1 || s->num_cpu > ARM_MPTIMER_MAX_CPUS) {
-        hw_error("%s: num-cpu must be between 1 and %d\n",
-                 __func__, ARM_MPTIMER_MAX_CPUS);
+        error_setg(errp, "num-cpu must be between 1 and %d",
+                   ARM_MPTIMER_MAX_CPUS);
+        return;
     }
     /* We implement one timer block per CPU, and expose multiple MMIO regions:
      *  * region 0 is "timer for this core"
Signature · 1 line
2.4.3
#1 lore raw

PATCH v2 1/13 hw: Don't use hw_error() for machine initialization errors

In reply to Markus Armbruster

Printing CPU registers is not helpful during machine initialization. Moreover, these are straightforward configuration or "can get resources" errors, so dumping core isn't appropriate either. Replace hw_error() by error_report(); exit(1). Matches how we report these errors in other machine initializations.

---
 hw/alpha/dp264.c          | 11 ++++++-----
 hw/arm/highbank.c         |  6 ++++--
 hw/char/exynos4210_uart.c |  9 ++++++---
 hw/m68k/an5206.c          |  4 +++-
 hw/ppc/mac_newworld.c     | 11 ++++++-----
 hw/ppc/mac_oldworld.c     | 16 +++++++++-------
 hw/ppc/prep.c             | 11 +++++++----
 hw/unicore32/puv3.c       | 10 +++++++---
 8 files changed, 48 insertions(+), 30 deletions(-)
hw/alpha/dp264.c +6 -5
index 27bdaa1..38b85ba 100644
@@ -11,6 +11,7 @@
 #include "hw/loader.h"
 #include "hw/boards.h"
 #include "alpha_sys.h"
+#include "qemu/error-report.h"
 #include "sysemu/sysemu.h"
 #include "hw/timer/mc146818rtc.h"
 #include "hw/ide.h"
@@ -104,14 +105,14 @@ static void clipper_init(MachineState *machine)
     palcode_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,
                                 bios_name ? bios_name : "palcode-clipper");
     if (palcode_filename == NULL) {
-        hw_error("no palcode provided\n");
+        error_report("no palcode provided");
         exit(1);
     }
     size = load_elf(palcode_filename, cpu_alpha_superpage_to_phys,
                     NULL, &palcode_entry, &palcode_low, &palcode_high,
                     0, EM_ALPHA, 0);
     if (size < 0) {
-        hw_error("could not load palcode '%s'\n", palcode_filename);
+        error_report("could not load palcode '%s'", palcode_filename);
         exit(1);
     }
     g_free(palcode_filename);
@@ -131,7 +132,7 @@ static void clipper_init(MachineState *machine)
                         NULL, &kernel_entry, &kernel_low, &kernel_high,
                         0, EM_ALPHA, 0);
         if (size < 0) {
-            hw_error("could not load kernel '%s'\n", kernel_filename);
+            error_report("could not load kernel '%s'", kernel_filename);
             exit(1);
         }
 
@@ -148,8 +149,8 @@ static void clipper_init(MachineState *machine)
 
             initrd_size = get_image_size(initrd_filename);
             if (initrd_size < 0) {
-                hw_error("could not load initial ram disk '%s'\n",
-                         initrd_filename);
+                error_report("could not load initial ram disk '%s'",
+                             initrd_filename);
                 exit(1);
             }
 
hw/arm/highbank.c +4 -2
index 85ae69e..1dd5170 100644
@@ -320,11 +320,13 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id)
         sysboot_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
         if (sysboot_filename != NULL) {
             if (load_image_targphys(sysboot_filename, 0xfff88000, 0x8000) < 0) {
-                hw_error("Unable to load %s\n", bios_name);
+                error_report("Unable to load %s", bios_name);
+                exit(1);
             }
             g_free(sysboot_filename);
         } else {
-           hw_error("Unable to find %s\n", bios_name);
+            error_report("Unable to find %s", bios_name);
+            exit(1);
         }
     }
 
hw/char/exynos4210_uart.c +6 -3
index 215f962..2736b37 100644
@@ -20,6 +20,7 @@
  */
 
 #include "hw/sysbus.h"
+#include "qemu/error-report.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/char.h"
 
@@ -595,15 +596,17 @@ DeviceState *exynos4210_uart_create(hwaddr addr,
 
     if (!chr) {
         if (channel >= MAX_SERIAL_PORTS) {
-            hw_error("Only %d serial ports are supported by QEMU.\n",
-                     MAX_SERIAL_PORTS);
+            error_report("Only %d serial ports are supported by QEMU",
+                         MAX_SERIAL_PORTS);
+            exit(1);
         }
         chr = serial_hds[channel];
         if (!chr) {
             snprintf(label, ARRAY_SIZE(label), "%s%d", chr_name, channel);
             chr = qemu_chr_new(label, "null", NULL);
             if (!(chr)) {
-                hw_error("Can't assign serial port to UART%d.\n", channel);
+                error_report("Can't assign serial port to UART%d", channel);
+                exit(1);
             }
         }
     }
hw/m68k/an5206.c +3 -1
index c1dea17..8d9ccaa 100644
@@ -12,6 +12,7 @@
 #include "hw/loader.h"
 #include "elf.h"
 #include "exec/address-spaces.h"
+#include "qemu/error-report.h"
 #include "sysemu/qtest.h"
 
 #define KERNEL_LOAD_ADDR 0x10000
@@ -39,7 +40,8 @@ static void an5206_init(MachineState *machine)
     }
     cpu = cpu_m68k_init(cpu_model);
     if (!cpu) {
-        hw_error("Unable to find m68k CPU definition\n");
+        error_report("Unable to find m68k CPU definition");
+        exit(1);
     }
     env = &cpu->env;
 
hw/ppc/mac_newworld.c +6 -5
index 1b9a573..ca3d6a8 100644
@@ -62,6 +62,7 @@
 #include "hw/ide.h"
 #include "hw/loader.h"
 #include "elf.h"
+#include "qemu/error-report.h"
 #include "sysemu/kvm.h"
 #include "kvm_ppc.h"
 #include "hw/usb.h"
@@ -226,7 +227,7 @@ static void ppc_core99_init(MachineState *machine)
         bios_size = -1;
     }
     if (bios_size < 0 || bios_size > BIOS_SIZE) {
-        hw_error("qemu: could not load PowerPC bios '%s'\n", bios_name);
+        error_report("could not load PowerPC bios '%s'", bios_name);
         exit(1);
     }
 
@@ -252,7 +253,7 @@ static void ppc_core99_init(MachineState *machine)
                                               kernel_base,
                                               ram_size - kernel_base);
         if (kernel_size < 0) {
-            hw_error("qemu: could not load kernel '%s'\n", kernel_filename);
+            error_report("could not load kernel '%s'", kernel_filename);
             exit(1);
         }
         /* load initrd */
@@ -261,8 +262,8 @@ static void ppc_core99_init(MachineState *machine)
             initrd_size = load_image_targphys(initrd_filename, initrd_base,
                                               ram_size - initrd_base);
             if (initrd_size < 0) {
-                hw_error("qemu: could not load initial ram disk '%s'\n",
-                         initrd_filename);
+                error_report("could not load initial ram disk '%s'",
+                             initrd_filename);
                 exit(1);
             }
             cmdline_base = round_page(initrd_base + initrd_size);
@@ -344,7 +345,7 @@ static void ppc_core99_init(MachineState *machine)
             break;
 #endif /* defined(TARGET_PPC64) */
         default:
-            hw_error("Bus model not supported on mac99 machine\n");
+            error_report("Bus model not supported on mac99 machine");
             exit(1);
         }
     }
hw/ppc/mac_oldworld.c +9 -7
index 21eaf0e..c3f9fe3 100644
@@ -38,6 +38,7 @@
 #include "hw/ide.h"
 #include "hw/loader.h"
 #include "elf.h"
+#include "qemu/error-report.h"
 #include "sysemu/kvm.h"
 #include "kvm_ppc.h"
 #include "sysemu/block-backend.h"
@@ -153,7 +154,7 @@ static void ppc_heathrow_init(MachineState *machine)
         bios_size = -1;
     }
     if (bios_size < 0 || bios_size > BIOS_SIZE) {
-        hw_error("qemu: could not load PowerPC bios '%s'\n", bios_name);
+        error_report("could not load PowerPC bios '%s'", bios_name);
         exit(1);
     }
 
@@ -178,8 +179,7 @@ static void ppc_heathrow_init(MachineState *machine)
                                               kernel_base,
                                               ram_size - kernel_base);
         if (kernel_size < 0) {
-            hw_error("qemu: could not load kernel '%s'\n",
-                      kernel_filename);
+            error_report("could not load kernel '%s'", kernel_filename);
             exit(1);
         }
         /* load initrd */
@@ -188,8 +188,8 @@ static void ppc_heathrow_init(MachineState *machine)
             initrd_size = load_image_targphys(initrd_filename, initrd_base,
                                               ram_size - initrd_base);
             if (initrd_size < 0) {
-                hw_error("qemu: could not load initial ram disk '%s'\n",
-                         initrd_filename);
+                error_report("could not load initial ram disk '%s'",
+                             initrd_filename);
                 exit(1);
             }
             cmdline_base = round_page(initrd_base + initrd_size);
@@ -246,7 +246,8 @@ static void ppc_heathrow_init(MachineState *machine)
                 ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT];
             break;
         default:
-            hw_error("Bus model not supported on OldWorld Mac machine\n");
+            error_report("Bus model not supported on OldWorld Mac machine");
+            exit(1);
         }
     }
 
@@ -259,7 +260,8 @@ static void ppc_heathrow_init(MachineState *machine)
 
     /* init basic PC hardware */
     if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) {
-        hw_error("Only 6xx bus is supported on heathrow machine\n");
+        error_report("Only 6xx bus is supported on heathrow machine");
+        exit(1);
     }
     pic = heathrow_pic_init(&pic_mem, 1, heathrow_irqs);
     pci_bus = pci_grackle_init(0xfec00000, pic,
hw/ppc/prep.c +7 -4
index 5ad28f7..0e102fc 100644
@@ -33,6 +33,7 @@
 #include "hw/pci/pci_host.h"
 #include "hw/ppc/ppc.h"
 #include "hw/boards.h"
+#include "qemu/error-report.h"
 #include "qemu/log.h"
 #include "hw/ide.h"
 #include "hw/loader.h"
@@ -532,7 +533,7 @@ static void ppc_prep_init(MachineState *machine)
         kernel_size = load_image_targphys(kernel_filename, kernel_base,
                                           ram_size - kernel_base);
         if (kernel_size < 0) {
-            hw_error("qemu: could not load kernel '%s'\n", kernel_filename);
+            error_report("could not load kernel '%s'", kernel_filename);
             exit(1);
         }
         /* load initrd */
@@ -541,8 +542,9 @@ static void ppc_prep_init(MachineState *machine)
             initrd_size = load_image_targphys(initrd_filename, initrd_base,
                                               ram_size - initrd_base);
             if (initrd_size < 0) {
-                hw_error("qemu: could not load initial ram disk '%s'\n",
-                          initrd_filename);
+                error_report("could not load initial ram disk '%s'",
+                             initrd_filename);
+                exit(1);
             }
         } else {
             initrd_base = 0;
@@ -569,7 +571,8 @@ static void ppc_prep_init(MachineState *machine)
     }
 
     if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) {
-        hw_error("Only 6xx bus is supported on PREP machine\n");
+        error_report("Only 6xx bus is supported on PREP machine");
+        exit(1);
     }
 
     dev = qdev_create(NULL, "raven-pcihost");
hw/unicore32/puv3.c +7 -3
index 91117b2..1968202 100644
@@ -17,6 +17,7 @@
 #include "hw/boards.h"
 #include "hw/loader.h"
 #include "hw/i386/pc.h"
+#include "qemu/error-report.h"
 #include "sysemu/qtest.h"
 
 #undef DEBUG_PUV3
@@ -95,7 +96,8 @@ static void puv3_load_kernel(const char *kernel_filename)
     size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR,
             KERNEL_MAX_SIZE);
     if (size < 0) {
-        hw_error("Load kernel error: '%s'\n", kernel_filename);
+        error_report("Load kernel error: '%s'", kernel_filename);
+        exit(1);
     }
 
     /* cheat curses that we have a graphic console, only under ocd console */
@@ -112,7 +114,8 @@ static void puv3_init(MachineState *machine)
     UniCore32CPU *cpu;
 
     if (initrd_filename) {
-        hw_error("Please use kernel built-in initramdisk.\n");
+        error_report("Please use kernel built-in initramdisk");
+        exit(1);
     }
 
     if (!cpu_model) {
@@ -121,7 +124,8 @@ static void puv3_init(MachineState *machine)
 
     cpu = uc32_cpu_init(cpu_model);
     if (!cpu) {
-        hw_error("Unable to find CPU definition\n");
+        error_report("Unable to find CPU definition");
+        exit(1);
     }
     env = &cpu->env;
 
Signature · 1 line
2.4.3
#14 lore raw

PATCH v2 7/13 hw/arm/virt: Fix property "gic-version" error handling

In reply to Markus Armbruster

virt_set_gic_version() calls exit(1) when passed an invalid property value. Property setters are not supposed to do that. Screwed up in commit b92ad39. Harmless, because the property belongs to a machine. Set an error object instead.

---
 hw/arm/virt.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
hw/arm/virt.c +2 -3
index 9c6792c..2a120dd 100644
@@ -1126,9 +1126,8 @@ static void virt_set_gic_version(Object *obj, const char *value, Error **errp)
     } else if (!strcmp(value, "host")) {
         vms->gic_version = 0; /* Will probe later */
     } else {
-        error_report("Invalid gic-version option value");
-        error_printf("Allowed gic-version values are: 3, 2, host\n");
-        exit(1);
+        error_setg(errp, "Invalid gic-version value");
+        error_append_hint(errp, "Valid values are: 3, 2, host\n");
     }
 }
 
Signature · 1 line
2.4.3
Reviewed-by on v2 9/13
#18 lore raw

Re: [Qemu-devel] [PATCH v2 09/13] isa: Trivially convert remaining PCI-ISA bridges to realize()

In reply to Markus Armbruster
Quoted 6 lines · Markus Armbruster

These are "ICH9-LPC" and "ebus".

Cc "Michael S. Tsirkin" <[email protected]>
Cc Mark Cave-Ayland <[email protected]>
Quoted 67 lines
---
 hw/isa/lpc_ich9.c  | 5 ++---
 hw/sparc64/sun4u.c | 6 ++----
 2 files changed, 4 insertions(+), 7 deletions(-)
hw/isa/lpc_ich9.c +2 -3
index 1ffc803..8e58449 100644
@@ -602,7 +602,7 @@ static void ich9_lpc_initfn(Object *obj)
     ich9_lpc_add_properties(lpc);
 }
 
-static int ich9_lpc_init(PCIDevice *d)
+static void ich9_lpc_realize(PCIDevice *d, Error **errp)
 {
     ICH9LPCState *lpc = ICH9_LPC_DEVICE(d);
     ISABus *isa_bus;
@@ -628,7 +628,6 @@ static int ich9_lpc_init(PCIDevice *d)
     memory_region_add_subregion_overlap(pci_address_space_io(d),
                                         ICH9_RST_CNT_IOPORT, &lpc->rst_cnt_mem,
                                         1);
-    return 0;
 }
 
 static void ich9_device_plug_cb(HotplugHandler *hotplug_dev,
@@ -706,7 +705,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data)
 
     set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
     dc->reset = ich9_lpc_reset;
-    k->init = ich9_lpc_init;
+    k->realize = ich9_lpc_realize;
     dc->vmsd = &vmstate_ich9_lpc;
     dc->props = ich9_lpc_properties;
     k->config_write = ich9_lpc_config_write;
hw/sparc64/sun4u.c +2 -4
index d6b929c..c37e8b0 100644
@@ -593,8 +593,7 @@ pci_ebus_init(PCIBus *bus, int devfn, qemu_irq *irqs)
     return isa_bus;
 }
 
-static int
-pci_ebus_init1(PCIDevice *pci_dev)
+static void pci_ebus_realize(PCIDevice *pci_dev, Error **errp)
 {
     EbusState *s = DO_UPCAST(EbusState, pci_dev, pci_dev);
 
@@ -614,14 +613,13 @@ pci_ebus_init1(PCIDevice *pci_dev)
     memory_region_init_alias(&s->bar1, OBJECT(s), "bar1", get_system_io(),
                              0, 0x4000);
     pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_SPACE_IO, &s->bar1);
-    return 0;
 }
 
 static void ebus_class_init(ObjectClass *klass, void *data)
 {
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = pci_ebus_init1;
+    k->realize = pci_ebus_realize;
     k->vendor_id = PCI_VENDOR_ID_SUN;
     k->device_id = PCI_DEVICE_ID_SUN_EBUS;
     k->revision = 0x01;
Signature · 1 line
2.4.3
#22 lore raw

Re: [Qemu-devel] [PATCH v2 11/13] isa: Clean up inappropriate hw_error()

In reply to Markus Armbruster
Quoted 8 lines · Markus Armbruster

isa_bus_irqs(), isa_create() and isa_try_create() call hw_error() when passed a null bus. Use of hw_error() has always been questionable, because these are used only during machine initialization, and printing CPU registers isn't useful there.

Since the previous commit, passing a null bus is a programming error. Drop the hw_error() and simply let it crash.

Quoted 7 lines
Cc Richard Henderson <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc "Hervé Poussineau" <[email protected]>
Cc Aurelien Jarno <[email protected]>
Cc Mark Cave-Ayland <[email protected]>

I'd prefer an assert just in case.

Quoted 42 lines
---
 hw/isa/isa-bus.c | 11 -----------
 1 file changed, 11 deletions(-)
hw/isa/isa-bus.c +0 -11
index af6ffd6..630054c 100644
@@ -63,9 +63,6 @@ ISABus *isa_bus_new(DeviceState *dev, MemoryRegion* address_space,
 
 void isa_bus_irqs(ISABus *bus, qemu_irq *irqs)
 {
-    if (!bus) {
-        hw_error("Can't set isa irqs with no isa bus present.");
-    }
     bus->irqs = irqs;
 }
 
@@ -137,10 +134,6 @@ ISADevice *isa_create(ISABus *bus, const char *name)
 {
     DeviceState *dev;
 
-    if (!bus) {
-        hw_error("Tried to create isa device %s with no isa bus present.",
-                 name);
-    }
     dev = qdev_create(BUS(bus), name);
     return ISA_DEVICE(dev);
 }
@@ -149,10 +142,6 @@ ISADevice *isa_try_create(ISABus *bus, const char *name)
 {
     DeviceState *dev;
 
-    if (!bus) {
-        hw_error("Tried to create isa device %s with no isa bus present.",
-                 name);
-    }
     dev = qdev_try_create(BUS(bus), name);
     return ISA_DEVICE(dev);
 }
Signature · 1 line
2.4.3
Reviewed-by on v2 10/13
#20 lore raw

Re: [Qemu-devel] [PATCH v2 10/13] isa: Clean up error handling around isa_bus_new()

In reply to Markus Armbruster
Quoted 44 lines · Markus Armbruster

We can have at most one ISA bus. If you try to create another one, isa_bus_new() complains to stderr and returns null.

isa_bus_new() is called in two contexts, machine's init() and device's realize() methods. Since complaining to stderr is not proper in the latter context, convert isa_bus_new() to Error.

Machine's init():

* mips_jazz_init(), called from the init() methods of machines "magnum" and "pica"

* mips_r4k_init(), the init() method of machine "mips"

* pc_init1() called from the init() methods of non-q35 PC machines

* typhoon_init(), called from clipper_init(), the init() method of machine "clipper"

These callers always create the first ISA bus, hence isa_bus_new() can't fail. Simply pass &error_abort.

Device's realize():

* i82378_realize(), of PCI device "i82378"

* ich9_lpc_realize(), of PCI device "ICH9-LPC"

* pci_ebus_realize(), of PCI device "ebus"

* piix3_realize(), of PCI device "pci-piix3", abstract parent of "PIIX3" and "PIIX3-xen"

* piix4_realize(), of PCI device "PIIX4"

* vt82c686b_realize(), of PCI device "VT82C686B"

Propagate the error. Note that these devices are typically created only by machine init() methods with qdev_init_nofail() or similar. If we screwed up and created an ISA bus before that call, we now give up right away. Before, we'd hobble on, and typically die in isa_bus_irqs(). Similar if someone finds a way to hot-plug one of these critters.

Quoted 8 lines
Cc Richard Henderson <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc "Hervé Poussineau" <[email protected]>
Cc Aurelien Jarno <[email protected]>
Cc Mark Cave-Ayland <[email protected]>
Quoted 201 lines
---
 hw/alpha/typhoon.c   | 3 ++-
 hw/i386/pc_piix.c    | 3 ++-
 hw/isa/i82378.c      | 5 ++++-
 hw/isa/isa-bus.c     | 4 ++--
 hw/isa/lpc_ich9.c    | 6 +++++-
 hw/isa/piix4.c       | 6 ++++--
 hw/isa/vt82c686.c    | 5 ++++-
 hw/mips/mips_jazz.c  | 2 +-
 hw/mips/mips_r4k.c   | 2 +-
 hw/pci-host/piix.c   | 6 ++++--
 hw/sparc64/sun4u.c   | 6 ++++--
 include/hw/isa/isa.h | 2 +-
 12 files changed, 34 insertions(+), 16 deletions(-)
hw/alpha/typhoon.c +2 -1
index 421162e..35dc8a5 100644
@@ -920,7 +920,8 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus **isa_bus,
     {
         qemu_irq *isa_irqs;
 
-        *isa_bus = isa_bus_new(NULL, get_system_memory(), &s->pchip.reg_io);
+        *isa_bus = isa_bus_new(NULL, get_system_memory(), &s->pchip.reg_io,
+                               &error_abort);
         isa_irqs = i8259_init(*isa_bus,
                               qemu_allocate_irq(typhoon_set_isa_irq, s, 0));
         isa_bus_irqs(*isa_bus, isa_irqs);
hw/i386/pc_piix.c +2 -1
index 2e41efe..48fdad4 100644
@@ -200,7 +200,8 @@ static void pc_init1(MachineState *machine,
     } else {
         pci_bus = NULL;
         i440fx_state = NULL;
-        isa_bus = isa_bus_new(NULL, get_system_memory(), system_io);
+        isa_bus = isa_bus_new(NULL, get_system_memory(), system_io,
+                              &error_abort);
         no_hpet = 1;
     }
     isa_bus_irqs(isa_bus, gsi);
hw/isa/i82378.c +4 -1
index d4c8306..3793c6f 100644
@@ -75,7 +75,10 @@ static void i82378_realize(PCIDevice *pci, Error **errp)
     pci_config_set_interrupt_pin(pci_conf, 1); /* interrupt pin 0 */
 
     isabus = isa_bus_new(dev, get_system_memory(),
-                         pci_address_space_io(pci));
+                         pci_address_space_io(pci), errp);
+    if (!isabus) {
+        return;
+    }
 
     /* This device has:
        2 82C59 (irq)
hw/isa/isa-bus.c +2 -2
index 43e0cd8..af6ffd6 100644
@@ -44,10 +44,10 @@ static const TypeInfo isa_bus_info = {
 };
 
 ISABus *isa_bus_new(DeviceState *dev, MemoryRegion* address_space,
-                    MemoryRegion *address_space_io)
+                    MemoryRegion *address_space_io, Error **errp)
 {
     if (isabus) {
-        fprintf(stderr, "Can't create a second ISA bus\n");
+        error_setg(errp, "Can't create a second ISA bus");
         return NULL;
     }
     if (!dev) {
hw/isa/lpc_ich9.c +5 -1
index 8e58449..ed9907d 100644
@@ -607,7 +607,11 @@ static void ich9_lpc_realize(PCIDevice *d, Error **errp)
     ICH9LPCState *lpc = ICH9_LPC_DEVICE(d);
     ISABus *isa_bus;
 
-    isa_bus = isa_bus_new(DEVICE(d), get_system_memory(), get_system_io());
+    isa_bus = isa_bus_new(DEVICE(d), get_system_memory(), get_system_io(),
+                          errp);
+    if (!isa_bus) {
+        return;
+    }
 
     pci_set_long(d->wmask + ICH9_LPC_PMBASE,
                  ICH9_LPC_PMBASE_BASE_ADDRESS_MASK);
hw/isa/piix4.c +4 -2
index 2c59e91..644cfd9 100644
@@ -90,8 +90,10 @@ static void piix4_realize(PCIDevice *dev, Error **errp)
 {
     PIIX4State *d = PIIX4_PCI_DEVICE(dev);
 
-    isa_bus_new(DEVICE(d), pci_address_space(dev),
-                pci_address_space_io(dev));
+    if (!isa_bus_new(DEVICE(d), pci_address_space(dev),
+                     pci_address_space_io(dev), errp)) {
+        return;
+    }
     piix4_dev = &d->dev;
     qemu_register_reset(piix4_reset, d);
 }
hw/isa/vt82c686.c +4 -1
index 252e1d7..6c2190b 100644
@@ -440,7 +440,10 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
     int i;
 
     isa_bus = isa_bus_new(DEVICE(d), get_system_memory(),
-                          pci_address_space_io(d));
+                          pci_address_space_io(d), errp);
+    if (!isa_bus) {
+        return;
+    }
 
     pci_conf = d->config;
     pci_config_set_prog_interface(pci_conf, 0x0);
hw/mips/mips_jazz.c +1 -1
index 1ab885b..1cfbaa6 100644
@@ -219,7 +219,7 @@ static void mips_jazz_init(MachineState *machine,
     memory_region_init(isa_mem, NULL, "isa-mem", 0x01000000);
     memory_region_add_subregion(address_space, 0x90000000, isa_io);
     memory_region_add_subregion(address_space, 0x91000000, isa_mem);
-    isa_bus = isa_bus_new(NULL, isa_mem, isa_io);
+    isa_bus = isa_bus_new(NULL, isa_mem, isa_io, &error_abort);
 
     /* ISA devices */
     i8259 = i8259_init(isa_bus, env->irq[4]);
hw/mips/mips_r4k.c +1 -1
index af10da1..2d4e038 100644
@@ -272,7 +272,7 @@ void mips_r4k_init(MachineState *machine)
     memory_region_init(isa_mem, NULL, "isa-mem", 0x01000000);
     memory_region_add_subregion(get_system_memory(), 0x14000000, isa_io);
     memory_region_add_subregion(get_system_memory(), 0x10000000, isa_mem);
-    isa_bus = isa_bus_new(NULL, isa_mem, get_system_io());
+    isa_bus = isa_bus_new(NULL, isa_mem, get_system_io(), &error_abort);
 
     /* The PIC is attached to the MIPS CPU INT0 pin */
     i8259 = i8259_init(isa_bus, env->irq[2]);
hw/pci-host/piix.c +4 -2
index 715208b..775b4bd 100644
@@ -651,8 +651,10 @@ static void piix3_realize(PCIDevice *dev, Error **errp)
 {
     PIIX3State *d = PIIX3_PCI_DEVICE(dev);
 
-    isa_bus_new(DEVICE(d), get_system_memory(),
-                pci_address_space_io(dev));
+    if (!isa_bus_new(DEVICE(d), get_system_memory(),
+                     pci_address_space_io(dev), errp)) {
+        return;
+    }
 
     memory_region_init_io(&d->rcr_mem, OBJECT(dev), &rcr_ops, d,
                           "piix3-reset-control", 1);
hw/sparc64/sun4u.c +4 -2
index c37e8b0..6c7596b 100644
@@ -597,8 +597,10 @@ static void pci_ebus_realize(PCIDevice *pci_dev, Error **errp)
 {
     EbusState *s = DO_UPCAST(EbusState, pci_dev, pci_dev);
 
-    isa_bus_new(DEVICE(pci_dev), get_system_memory(),
-                pci_address_space_io(pci_dev));
+    if (!isa_bus_new(DEVICE(pci_dev), get_system_memory(),
+                     pci_address_space_io(pci_dev), errp)) {
+        return;
+    }
 
     pci_dev->config[0x04] = 0x06; // command = bus master, pci mem
     pci_dev->config[0x05] = 0x00;
include/hw/isa/isa.h +1 -1
index d758b39..de3cd3d 100644
@@ -59,7 +59,7 @@ struct ISADevice {
 };
 
 ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space,
-                    MemoryRegion *address_space_io);
+                    MemoryRegion *address_space_io, Error **errp);
 void isa_bus_irqs(ISABus *bus, qemu_irq *irqs);
 qemu_irq isa_get_irq(ISADevice *dev, int isairq);
 void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq);
Signature · 1 line
2.4.3
#23 lore raw

Re: [Qemu-devel] [PATCH v2 11/13] isa: Clean up inappropriate hw_error()

In reply to Michael S. Tsirkin
Quoted 17 lines · Michael S. Tsirkin
Quoted 8 lines · Markus Armbruster

isa_bus_irqs(), isa_create() and isa_try_create() call hw_error() when passed a null bus. Use of hw_error() has always been questionable, because these are used only during machine initialization, and printing CPU registers isn't useful there.

Since the previous commit, passing a null bus is a programming error. Drop the hw_error() and simply let it crash.

Quoted 7 lines
Cc Richard Henderson <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc "Hervé Poussineau" <[email protected]>
Cc Aurelien Jarno <[email protected]>
Cc Mark Cave-Ayland <[email protected]>
Quoted 1 line

I'd prefer an assert just in case.

I understand "prefer", I don't understand "just in case" :)

Adding an assertion here merely converts one kind of crash into another.

Doesn't make anything safer, not even just in case something happens we thought was impossible.

Does print a message before crashing that some developers may find useful.

Might make our belief that null can't happen a bit more explicit.

My own preference is not to assert the blatantly obvious. However, I'm certainly willing to defer to a maintainer's or reviewer's preference, within reason. For what it's worth:

    $ scripts/get_maintainer.pl -f hw/isa/isa-bus.c 
    get_maintainer.pl: No maintainers found, printing recent contributors.
    get_maintainer.pl: Do not blindly cc: them on patches!  Use common sense.
    "Hervé Poussineau" <[email protected]> (commit_signer:4/6=67%)
    Markus Armbruster <[email protected]> (commit_signer:3/6=50%)
    Leon Alrae <[email protected]> (commit_signer:2/6=33%)
    Paolo Bonzini <[email protected]> (commit_signer:2/6=33%)
    Dave Airlie <[email protected]> (commit_signer:1/6=17%)

Considering all of the above, do you want me to add the assertions?

#5 lore raw

Re: [Qemu-devel] [PATCH v2 02/13] omap: Don't use hw_error() in device init() methods

In reply to Markus Armbruster

hw/gpio/omap_gpio.c static int omap2_gpio_init(SysBusDevice *sbd)

Quoted 31 lines · Markus Armbruster

Device init() methods aren't supposed to call hw_error(), they should report the error and fail cleanly. Do that.

The errors are all device misconfiguration. All callers use qdev_init_nofail(), so this patch merely converts hw_error() crashes into &error_abort crashes. Improvement, because now it crashes closer to where the misconfiguration bug would be, and a few more bad examples of hw_error() use are gone.

---
 hw/gpio/omap_gpio.c | 19 +++++++++++++++----
 hw/i2c/omap_i2c.c   |  8 ++++++--
 hw/intc/omap_intc.c | 10 +++++++---
 3 files changed, 28 insertions(+), 9 deletions(-)
hw/gpio/omap_gpio.c +1 -0
index 3c53898..1e0654b 100644
@@ -21,6 +21,7 @@
 #include "hw/hw.h"
 #include "hw/arm/omap.h"
 #include "hw/sysbus.h"
+#include "qemu/error-report.h"
 
 struct omap_gpio_s {
     qemu_irq irq;
@@ -700,8 +701,17 @@ static int omap2_gpio_init(SysBusDevice *sbd)

What about omap_gpio_init() ? There is also a hw_error in there!

hw/gpio/omap_gpio.c static int omap2_gpio_init(SysBusDevice *sbd) · line 708

Quoted 9 lines
hw/gpio/omap_gpio.c +4 -1
     int i;
 
     if (!s->iclk) {
-        hw_error("omap2-gpio: iclk not connected\n");
+        error_report("omap2-gpio: iclk not connected");
+        return -1;
     }
+
+    for (i = 0; i < s->modulecount; i++) {

You're now using modulecount here -^

hw/gpio/omap_gpio.c static int omap2_gpio_init(SysBusDevice *sbd) · line 716

Quoted 8 lines
hw/gpio/omap_gpio.c +6 -0
+        if (!s->fclk[i]) {
+            error_report("omap2-gpio: fclk%d not connected", i);
+            return -1;
+        }
+    }
+
     if (s->mpu_model < omap3430) {
         s->modulecount = (s->mpu_model < omap2430) ? 4 : 5;

... but it is initialized just here. So I think it is wrong that you moved the "!s->fclk[i]" before that.

hw/gpio/omap_gpio.c static int omap2_gpio_init(SysBusDevice *sbd) · line 728

Quoted 11 lines
hw/gpio/omap_gpio.c +2 -0
         memory_region_init_io(&s->iomem, OBJECT(s), &omap2_gpif_top_ops, s,
@@ -710,15 +720,15 @@ static int omap2_gpio_init(SysBusDevice *sbd)
     } else {
         s->modulecount = 6;
     }
+
     s->modules = g_new0(struct omap2_gpio_s, s->modulecount);
     s->handler = g_new0(qemu_irq, s->modulecount * 32);
     qdev_init_gpio_in(dev, omap2_gpio_set, s->modulecount * 32);
     qdev_init_gpio_out(dev, s->handler, s->modulecount * 32);
+

Unrelated whitespace changes?

Quoted 10 lines
hw/gpio/omap_gpio.c +1 -3
     for (i = 0; i < s->modulecount; i++) {
         struct omap2_gpio_s *m = &s->modules[i];
-        if (!s->fclk[i]) {
-            hw_error("omap2-gpio: fclk%d not connected\n", i);
-        }
+
         m->revision = (s->mpu_model < omap3430) ? 0x18 : 0x25;
         m->handler = &s->handler[i * 32];
         sysbus_init_irq(sbd, &m->irq[0]); /* mpu irq */

hw/gpio/omap_gpio.c static int omap2_gpio_init(SysBusDevice *sbd) · line 741

Quoted 4 lines
hw/gpio/omap_gpio.c +1 -0
@@ -728,6 +738,7 @@ static int omap2_gpio_init(SysBusDevice *sbd)
                               "omap.gpio-module", 0x1000);
         sysbus_init_mmio(sbd, &m->iomem);
     }
+

dito.

Thomas

Reviewed-by on v2 8/13
#16 lore raw

Re: [Qemu-devel] [PATCH v2 08/13] sysbus: Don't use hw_error() in machine_init_done_notifiers

In reply to Markus Armbruster
Quoted 8 lines · Markus Armbruster

platform_bus_map_irq() and platform_bus_map_mmio() use hw_error() to fail. They run in machine_init_done_notifiers, via platform_bus_init_notify() and link_sysbus_device(). Printing CPU registers is not helpful there.

Replace hw_error() by error_report(); exit(1). If these are programming errors, it should be replaced by an assertion instead.

Quoted 8 lines

While there, observe that both functions always return 0, and link_sysbus_device() ignores the return value. Change them to void.

---
 hw/core/platform-bus.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
#24 lore raw

Re: [Qemu-devel] [PATCH v2 11/13] isa: Clean up inappropriate hw_error()

In reply to Markus Armbruster
Quoted 19 lines · Markus Armbruster
Quoted 17 lines · Michael S. Tsirkin
Quoted 15 lines · Markus Armbruster

isa_bus_irqs(), isa_create() and isa_try_create() call hw_error() when passed a null bus. Use of hw_error() has always been questionable, because these are used only during machine initialization, and printing CPU registers isn't useful there.

Since the previous commit, passing a null bus is a programming error. Drop the hw_error() and simply let it crash.

Cc Richard Henderson <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc "Hervé Poussineau" <[email protected]>
Cc Aurelien Jarno <[email protected]>
Cc Mark Cave-Ayland <[email protected]>
Quoted 3 lines
Quoted 1 line

I'd prefer an assert just in case.

I understand "prefer", I don't understand "just in case" :)

To make debugging a bit less painful in case we missed something.

Quoted 18 lines

Adding an assertion here merely converts one kind of crash into another.

Doesn't make anything safer, not even just in case something happens we thought was impossible.

Does print a message before crashing that some developers may find useful.

Might make our belief that null can't happen a bit more explicit.

My own preference is not to assert the blatantly obvious. However, I'm certainly willing to defer to a maintainer's or reviewer's preference, within reason. For what it's worth:

    $ scripts/get_maintainer.pl -f hw/isa/isa-bus.c 
    get_maintainer.pl: No maintainers found, printing recent contributors.
    get_maintainer.pl: Do not blindly cc: them on patches!  Use common sense.
Quoted 7 lines
    "Hervé Poussineau" <[email protected]> (commit_signer:4/6=67%)
    Markus Armbruster <[email protected]> (commit_signer:3/6=50%)
    Leon Alrae <[email protected]> (commit_signer:2/6=33%)
    Paolo Bonzini <[email protected]> (commit_signer:2/6=33%)
    Dave Airlie <[email protected]> (commit_signer:1/6=17%)

Considering all of the above, do you want me to add the assertions?

Only in case you want my Reviewed-by.

Signature · 1 line
MST
Reviewed-by on v2 1/13
#2 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v2 01/13] hw: Don't use hw_error() for machine initialization errors

In reply to Markus Armbruster
Quoted 12 lines · Markus Armbruster

Printing CPU registers is not helpful during machine initialization. Moreover, these are straightforward configuration or "can get resources" errors, so dumping core isn't appropriate either. Replace hw_error() by error_report(); exit(1). Matches how we report these errors in other machine initializations.

Quoted 11 lines
---
 hw/alpha/dp264.c          | 11 ++++++-----
 hw/arm/highbank.c         |  6 ++++--
 hw/char/exynos4210_uart.c |  9 ++++++---
 hw/m68k/an5206.c          |  4 +++-
 hw/ppc/mac_newworld.c     | 11 ++++++-----
 hw/ppc/mac_oldworld.c     | 16 +++++++++-------
 hw/ppc/prep.c             | 11 +++++++----
 hw/unicore32/puv3.c       | 10 +++++++---
 8 files changed, 48 insertions(+), 30 deletions(-)
#6 lore raw

Re: [Qemu-devel] [PATCH v2 02/13] omap: Don't use hw_error() in device init() methods

In reply to Thomas Huth
Quoted 18 lines · Thomas Huth

hw/gpio/omap_gpio.c static int omap2_gpio_init(SysBusDevice *sbd) · line 708

Quoted 5 lines · Markus Armbruster

Device init() methods aren't supposed to call hw_error(), they should report the error and fail cleanly. Do that.

hw/gpio/omap_gpio.c +2 -0
+
+    for (i = 0; i < s->modulecount; i++) {

You're now using modulecount here -^

hw/gpio/omap_gpio.c static int omap2_gpio_init(SysBusDevice *sbd) · line 716

Quoted 8 lines
hw/gpio/omap_gpio.c +6 -0
+        if (!s->fclk[i]) {
+            error_report("omap2-gpio: fclk%d not connected", i);
+            return -1;
+        }
+    }
+
     if (s->mpu_model < omap3430) {
         s->modulecount = (s->mpu_model < omap2430) ? 4 : 5;
Quoted 2 lines

... but it is initialized just here. So I think it is wrong that you moved the "!s->fclk[i]" before that.

Thanks for reviewing this patch more carefully than I did :-)

-- PMM

#7 lore raw

Re: [Qemu-devel] [PATCH v2 02/13] omap: Don't use hw_error() in device init() methods

In reply to Thomas Huth
Quoted 29 lines · Thomas Huth
Quoted 28 lines · Markus Armbruster

Device init() methods aren't supposed to call hw_error(), they should report the error and fail cleanly. Do that.

The errors are all device misconfiguration. All callers use qdev_init_nofail(), so this patch merely converts hw_error() crashes into &error_abort crashes. Improvement, because now it crashes closer to where the misconfiguration bug would be, and a few more bad examples of hw_error() use are gone.

---
 hw/gpio/omap_gpio.c | 19 +++++++++++++++----
 hw/i2c/omap_i2c.c   |  8 ++++++--
 hw/intc/omap_intc.c | 10 +++++++---
 3 files changed, 28 insertions(+), 9 deletions(-)
hw/gpio/omap_gpio.c +1 -0
index 3c53898..1e0654b 100644
@@ -21,6 +21,7 @@
 #include "hw/hw.h"
 #include "hw/arm/omap.h"
 #include "hw/sysbus.h"
+#include "qemu/error-report.h"
 
Quoted 5 lines

hw/gpio/omap_gpio.c static int omap2_gpio_init(SysBusDevice *sbd)

Quoted 3 lines
hw/gpio/omap_gpio.c +0 -0
 struct omap_gpio_s {
     qemu_irq irq;
@@ -700,8 +701,17 @@ static int omap2_gpio_init(SysBusDevice *sbd)

What about omap_gpio_init() ? There is also a hw_error in there!

Missed in the noise... I'll include it in v3.

Quoted 21 lines

hw/gpio/omap_gpio.c static int omap2_gpio_init(SysBusDevice *sbd) · line 708

Quoted 9 lines
hw/gpio/omap_gpio.c +4 -1
     int i;
 
     if (!s->iclk) {
-        hw_error("omap2-gpio: iclk not connected\n");
+        error_report("omap2-gpio: iclk not connected");
+        return -1;
     }
+
+    for (i = 0; i < s->modulecount; i++) {

You're now using modulecount here -^

hw/gpio/omap_gpio.c static int omap2_gpio_init(SysBusDevice *sbd) · line 716

Quoted 8 lines
hw/gpio/omap_gpio.c +6 -0
+        if (!s->fclk[i]) {
+            error_report("omap2-gpio: fclk%d not connected", i);
+            return -1;
+        }
+    }
+
     if (s->mpu_model < omap3430) {
         s->modulecount = (s->mpu_model < omap2430) ? 4 : 5;
Quoted 2 lines

... but it is initialized just here. So I think it is wrong that you moved the "!s->fclk[i]" before that.

Hand me the brown paperbag...

I still like to move it, because checking properties before modifying the VM is good practice. But I do need to move the computation of modulecount, too.

Quoted 14 lines

hw/gpio/omap_gpio.c static int omap2_gpio_init(SysBusDevice *sbd) · line 728

Quoted 11 lines
hw/gpio/omap_gpio.c +2 -0
         memory_region_init_io(&s->iomem, OBJECT(s), &omap2_gpif_top_ops, s,
@@ -710,15 +720,15 @@ static int omap2_gpio_init(SysBusDevice *sbd)
     } else {
         s->modulecount = 6;
     }
+
     s->modules = g_new0(struct omap2_gpio_s, s->modulecount);
     s->handler = g_new0(qemu_irq, s->modulecount * 32);
     qdev_init_gpio_in(dev, omap2_gpio_set, s->modulecount * 32);
     qdev_init_gpio_out(dev, s->handler, s->modulecount * 32);
+

Unrelated whitespace changes?

Quoted 16 lines
Quoted 10 lines
hw/gpio/omap_gpio.c +1 -3
     for (i = 0; i < s->modulecount; i++) {
         struct omap2_gpio_s *m = &s->modules[i];
-        if (!s->fclk[i]) {
-            hw_error("omap2-gpio: fclk%d not connected\n", i);
-        }
+
         m->revision = (s->mpu_model < omap3430) ? 0x18 : 0x25;
         m->handler = &s->handler[i * 32];
         sysbus_init_irq(sbd, &m->irq[0]); /* mpu irq */

hw/gpio/omap_gpio.c static int omap2_gpio_init(SysBusDevice *sbd) · line 741

Quoted 4 lines
hw/gpio/omap_gpio.c +1 -0
@@ -728,6 +738,7 @@ static int omap2_gpio_init(SysBusDevice *sbd)
                               "omap.gpio-module", 0x1000);
         sysbus_init_mmio(sbd, &m->iomem);
     }
+

dito.

I wouldn't call them unrelated; I'm touching this code. But if they're unwelcome, I'm happy to drop them :)

Thanks for catching my mistakes!

Reviewed-by on v2 6/13
#12 lore raw

Re: [Qemu-devel] [PATCH v2 06/13] error: Don't append a newline when printing the error hint

In reply to Markus Armbruster
Quoted 9 lines · Markus Armbruster

Since commit 50b7b00, we have error_append_hint() to conveniently accumulate Error member @hint. error_report_err() prints it with a newline appended. Consequently, users of error_append_hint() need to know whether theirs is the final line of the hint to decide whether it needs a newline. Not a nice interface.

Change error_report_err() to print just the hint, and the (still few) users of error_append_hint() to add the required newline.

Quoted 7 lines
---
 qdev-monitor.c     | 2 ++
 util/error.c       | 2 +-
 util/qemu-option.c | 4 ++--
 3 files changed, 5 insertions(+), 3 deletions(-)

Would also be worth squashing this in:

include/qapi/error.h +2 -0
index 1480f59..007dc94 100644
@@ -142,6 +142,8 @@ ErrorClass error_get_class(const Error *err);
  * If @errp is anything else, *@errp must be NULL.
  * The new error's class is ERROR_CLASS_GENERIC_ERROR, and its
  * human-readable error message is made from printf-style @fmt, ...
+ * @fmt should be limited to one line, and should not include trailing
+ * punctuation or newline (to provide more text, see error_append_hint()).
  */
 #define error_setg(errp, fmt, ...)                              \
     error_setg_internal((errp), __FILE__, __LINE__, __func__,   \
@@ -198,7 +200,8 @@ void error_propagate(Error **dst_errp, Error

*local_err);

/**
* Append a printf-style human-readable explanation to an existing error.
- * May be called multiple times, and safe if @errp is NULL.
+ * May be called multiple times, and safe if @errp is NULL. Caller is
+ * responsible for providing a trailing newline when the hint is complete. */
void error_append_hint(Error **errp, const char *fmt, ...)

     GCC_FMT_ATTR(2, 3);
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#13 lore raw

Re: [Qemu-devel] [PATCH v2 06/13] error: Don't append a newline when printing the error hint

Quoted 43 lines · Eric Blake
Quoted 9 lines · Markus Armbruster

Since commit 50b7b00, we have error_append_hint() to conveniently accumulate Error member @hint. error_report_err() prints it with a newline appended. Consequently, users of error_append_hint() need to know whether theirs is the final line of the hint to decide whether it needs a newline. Not a nice interface.

Change error_report_err() to print just the hint, and the (still few) users of error_append_hint() to add the required newline.

Quoted 7 lines
---
 qdev-monitor.c     | 2 ++
 util/error.c       | 2 +-
 util/qemu-option.c | 4 ++--
 3 files changed, 5 insertions(+), 3 deletions(-)

Would also be worth squashing this in:

include/qapi/error.h +4 -1
index 1480f59..007dc94 100644
@@ -142,6 +142,8 @@ ErrorClass error_get_class(const Error *err);
  * If @errp is anything else, *@errp must be NULL.
  * The new error's class is ERROR_CLASS_GENERIC_ERROR, and its
  * human-readable error message is made from printf-style @fmt, ...
+ * @fmt should be limited to one line, and should not include trailing
+ * punctuation or newline (to provide more text, see error_append_hint()).
  */
 #define error_setg(errp, fmt, ...)                              \
     error_setg_internal((errp), __FILE__, __LINE__, __func__,   \
@@ -198,7 +200,8 @@ void error_propagate(Error **dst_errp, Error
 *local_err);
 
 /**
  * Append a printf-style human-readable explanation to an existing error.
- * May be called multiple times, and safe if @errp is NULL.
+ * May be called multiple times, and safe if @errp is NULL.  Caller is
+ * responsible for providing a trailing newline when the hint is complete.
  */
 void error_append_hint(Error **errp, const char *fmt, ...)
Quoted 1 line
     GCC_FMT_ATTR(2, 3);

I got something similar but more comprehensive in my next series.

Quoted 1 line

Thanks!

Reviewed-by on v2 1/13
#3 lore raw

Re: [Qemu-arm] [PATCH v2 01/13] hw: Don't use hw_error() for machine initialization errors

In reply to Markus Armbruster
Quoted 12 lines · Markus Armbruster

Printing CPU registers is not helpful during machine initialization. Moreover, these are straightforward configuration or "can get resources" errors, so dumping core isn't appropriate either. Replace hw_error() by error_report(); exit(1). Matches how we report these errors in other machine initializations.

Quoted 10 lines
---
  hw/alpha/dp264.c          | 11 ++++++-----
  hw/arm/highbank.c         |  6 ++++--
  hw/char/exynos4210_uart.c |  9 ++++++---
  hw/m68k/an5206.c          |  4 +++-
  hw/ppc/mac_newworld.c     | 11 ++++++-----
  hw/ppc/mac_oldworld.c     | 16 +++++++++-------
  hw/ppc/prep.c             | 11 +++++++----
  hw/unicore32/puv3.c       | 10 +++++++---
  8 files changed, 48 insertions(+), 30 deletions(-)

r~

Reviewed-by
#25 lore raw

Re: [Qemu-devel] [PATCH v2 11/13] isa: Clean up inappropriate hw_error()

In reply to Markus Armbruster
Quoted 28 lines · Markus Armbruster
Quoted 17 lines · Michael S. Tsirkin
Quoted 8 lines · Markus Armbruster

isa_bus_irqs(), isa_create() and isa_try_create() call hw_error() when passed a null bus. Use of hw_error() has always been questionable, because these are used only during machine initialization, and printing CPU registers isn't useful there.

Since the previous commit, passing a null bus is a programming error. Drop the hw_error() and simply let it crash.

Quoted 7 lines
Cc Richard Henderson <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc "Hervé Poussineau" <[email protected]>
Cc Aurelien Jarno <[email protected]>
Cc Mark Cave-Ayland <[email protected]>
Quoted 1 line

I'd prefer an assert just in case.

I understand "prefer", I don't understand "just in case" :)

Adding an assertion here merely converts one kind of crash into another.

Doesn't make anything safer, not even just in case something happens we thought was impossible.

Quoted 8 lines

Does print a message before crashing that some developers may find useful.

Might make our belief that null can't happen a bit more explicit.

My own preference is not to assert the blatantly obvious. However, I'm certainly willing to defer to a maintainer's or reviewer's preference, within reason. For what it's worth:

I'm not a fan of sprinkling obvious assertions everywhere either. I think the patch is fine as-is.

r~