[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 03/46] qdev: Smooth error checking of qdev_realize() & friend
From: |
Markus Armbruster |
Subject: |
Re: [PATCH 03/46] qdev: Smooth error checking of qdev_realize() & friends |
Date: |
Thu, 25 Jun 2020 14:39:14 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) |
Markus Armbruster <armbru@redhat.com> writes:
> 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;
> identifier errp;
> @@
> - fun(args, &err, args2);
> - if (err) {
> + if (!fun(args, errp, args2)) {
> ... when != err
> - error_propagate(errp, err);
> ...
> }
Note that this rule is unsound: if err is read later on, we're screwed.
I checked manually it's not, but neglected to mention it in the commit
message. I'll do that in v2.
The manual checking isn't that bad, most of the time we immediately
return.
>
> @@
> 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)) {
> ...
> }
>
> Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
> ARMSSE being used both as typedef and function-like macro there.
> Convert manually.
>
> Eliminate error_propagate() that are now unnecessary. Delete @err
> that are now unused. Clean up whitespace.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
- Re: [PATCH 08/46] error: Avoid unnecessary error_propagate() after error_setg(), (continued)
- [PATCH 18/46] qemu-option: Smooth error checking manually, Markus Armbruster, 2020/06/24
- [PATCH 03/46] qdev: Smooth error checking of qdev_realize() & friends, Markus Armbruster, 2020/06/24
- [PATCH 09/46] error: Avoid error_propagate() after migrate_add_blocker(), Markus Armbruster, 2020/06/24
- [PATCH 12/46] qemu-option: Factor out helper find_default_by_name(), Markus Armbruster, 2020/06/24
- [PATCH 13/46] qemu-option: Simplify around find_default_by_name(), Markus Armbruster, 2020/06/24