[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 03/44] qdev: Use returned bool to check for qdev_realize()
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
Re: [PATCH v2 03/44] qdev: Use returned bool to check for qdev_realize() etc. failure |
Date: |
Thu, 2 Jul 2020 21:57:44 +0300 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 |
02.07.2020 18:49, Markus Armbruster wrote:
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<armbru@redhat.com>
Sorry me, reviewing this patch with help of script:
#!/usr/bin/env python3
import sys
import re
with open(sys.argv[1]) as f:
patch = f.read()
regex = re.compile(r'^- *(?P<func_call>(?P<func>\w+)\(.*, &(?P<err>\w+)\));\n'
r'^- *if \((?P=err)( != NULL)?\) \{\n'
r'^\+ *if \(!(?P=func_call)\) \{$', flags=re.MULTILINE)
for chunk in re.split('^@', patch, flags=re.MULTILINE):
filtered = regex.sub('OK', chunk)
if re.search('^[+-][^+-]', filtered, flags=re.MULTILINE):
print(re.sub('^', ' ', '@' + chunk, flags=re.MULTILINE))
funcs = set()
for m in regex.finditer(patch):
funcs.add(m.group('func'))
print()
for func in funcs:
print(func)
====
output:
@@ -34,9 +34,7 @@ static void virtio_gpu_pci_base_realize(VirtIOPCIProxy
*vpci_dev, Error **errp)
Error *local_error = NULL;
virtio_pci_force_virtio_1(vpci_dev);
- qdev_realize(vdev, BUS(&vpci_dev->bus), &local_error);
-
- if (local_error) {
+ if (!qdev_realize(vdev, BUS(&vpci_dev->bus), &local_error)) {
error_propagate(errp, local_error);
return;
}
diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c
index 67f409e106..0fc00fee1f 100644
--- a/hw/display/virtio-vga.c
+++ b/hw/display/virtio-vga.c
@@ -444,15 +444,13 @@ static void realize_event_facility(DeviceState *dev, Error **errp)
SCLPEventFacility *event_facility = EVENT_FACILITY(dev);
Error *local_err = NULL;
- qdev_realize(DEVICE(&event_facility->quiesce),
- BUS(&event_facility->sbus), &local_err);
- if (local_err) {
+ if (!qdev_realize(DEVICE(&event_facility->quiesce),
+ BUS(&event_facility->sbus), &local_err)) {
error_propagate(errp, local_err);
return;
}
- qdev_realize(DEVICE(&event_facility->cpu_hotplug),
- BUS(&event_facility->sbus), &local_err);
- if (local_err) {
+ if (!qdev_realize(DEVICE(&event_facility->cpu_hotplug),
+ BUS(&event_facility->sbus), &local_err)) {
error_propagate(errp, local_err);
qdev_unrealize(DEVICE(&event_facility->quiesce));
return;
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index 142e52a8ff..0517901024 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
usb_realize_and_unref
sysbus_realize
sysbus_realize_and_unref
qdev_realize
qdev_realize_and_unref
===
So, the remaning non-matching seems correct, and all found functions seems to
have corresponding semantics:
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
--
Best regards,
Vladimir
- [PATCH v2 01/44] error: Improve examples in error.h's big comment, (continued)
- [PATCH v2 01/44] error: Improve examples in error.h's big comment, Markus Armbruster, 2020/07/02
- [PATCH v2 08/44] qemu-option: Factor out helper find_default_by_name(), Markus Armbruster, 2020/07/02
- [PATCH v2 21/44] qom: Use error_reportf_err() instead of g_printerr() in examples, Markus Armbruster, 2020/07/02
- [PATCH v2 05/44] virtio-crypto-pci: Tidy up virtio_crypto_pci_realize(), Markus Armbruster, 2020/07/02
- [PATCH v2 24/44] qom: Don't handle impossible object_property_get_link() failure, Markus Armbruster, 2020/07/02
- [PATCH v2 28/44] qom: Use returned bool to check for failure, Coccinelle part, Markus Armbruster, 2020/07/02
- [PATCH v2 03/44] qdev: Use returned bool to check for qdev_realize() etc. failure, Markus Armbruster, 2020/07/02
- [PATCH v2 29/44] qom: Use returned bool to check for failure, manual part, Markus Armbruster, 2020/07/02
- [PATCH v2 17/44] qapi: Use returned bool to check for failure, Coccinelle part, Markus Armbruster, 2020/07/02
- [PATCH v2 20/44] s390x/pci: Fix harmless mistake in zpci's property fid's setter, Markus Armbruster, 2020/07/02
- [PATCH v2 36/44] error: Eliminate error_propagate() manually, Markus Armbruster, 2020/07/02
- [PATCH v2 25/44] qom: Use return values to check for error where that's simpler, Markus Armbruster, 2020/07/02