From 118bfd76c9c604588cb3f97811710576f58e5a76 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 7 Jul 2020 18:05:32 +0200 Subject: qdev: Use returned bool to check for qdev_realize() etc. failure Convert foo(..., &err); if (err) { ... } to if (!foo(..., &err)) { ... } for qdev_realize(), qdev_realize_and_unref(), qbus_realize() and their wrappers isa_realize_and_unref(), pci_realize_and_unref(), sysbus_realize(), sysbus_realize_and_unref(), usb_realize_and_unref(). Coccinelle script: @@ identifier fun = { isa_realize_and_unref, pci_realize_and_unref, qbus_realize, qdev_realize, qdev_realize_and_unref, sysbus_realize, sysbus_realize_and_unref, usb_realize_and_unref }; expression list args, args2; typedef Error; Error *err; @@ - fun(args, &err, args2); - if (err) + if (!fun(args, &err, args2)) { ... } Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error message "no position information". Nothing to convert there; skipped. Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by ARMSSE being used both as typedef and function-like macro there. Converted manually. A few line breaks tidied up manually. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Greg Kurz Message-Id: <20200707160613.848843-5-armbru@redhat.com> --- hw/char/serial-pci-multi.c | 3 +-- hw/char/serial-pci.c | 3 +-- hw/char/serial.c | 6 ++---- 3 files changed, 4 insertions(+), 8 deletions(-) (limited to 'hw/char') diff --git a/hw/char/serial-pci-multi.c b/hw/char/serial-pci-multi.c index 56f915e7c9..1328967461 100644 --- a/hw/char/serial-pci-multi.c +++ b/hw/char/serial-pci-multi.c @@ -106,8 +106,7 @@ static void multi_serial_pci_realize(PCIDevice *dev, Error **errp) for (i = 0; i < nports; i++) { s = pci->state + i; - qdev_realize(DEVICE(s), NULL, &err); - if (err != NULL) { + if (!qdev_realize(DEVICE(s), NULL, &err)) { error_propagate(errp, err); multi_serial_pci_exit(dev); return; diff --git a/hw/char/serial-pci.c b/hw/char/serial-pci.c index 298f3adba7..d22617426b 100644 --- a/hw/char/serial-pci.c +++ b/hw/char/serial-pci.c @@ -49,8 +49,7 @@ static void serial_pci_realize(PCIDevice *dev, Error **errp) SerialState *s = &pci->state; Error *err = NULL; - qdev_realize(DEVICE(s), NULL, &err); - if (err != NULL) { + if (!qdev_realize(DEVICE(s), NULL, &err)) { error_propagate(errp, err); return; } diff --git a/hw/char/serial.c b/hw/char/serial.c index 9eebcb27e7..e69096eace 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -991,8 +991,7 @@ static void serial_io_realize(DeviceState *dev, Error **errp) SerialState *s = &sio->serial; Error *local_err = NULL; - qdev_realize(DEVICE(s), NULL, &local_err); - if (local_err) { + if (!qdev_realize(DEVICE(s), NULL, &local_err)) { error_propagate(errp, local_err); return; } @@ -1098,8 +1097,7 @@ static void serial_mm_realize(DeviceState *dev, Error **errp) SerialState *s = &smm->serial; Error *local_err = NULL; - qdev_realize(DEVICE(s), NULL, &local_err); - if (local_err) { + if (!qdev_realize(DEVICE(s), NULL, &local_err)) { error_propagate(errp, local_err); return; } -- cgit v1.2.3-55-g7522