[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>