qemu/hw/virtio
Markus Armbruster 297a3646c2 qapi: Replace uncommon use of the error API by the common one
We commonly use the error API like this:

    err = NULL;
    foo(..., &err);
    if (err) {
        goto out;
    }
    bar(..., &err);

Every error source is checked separately.  The second function is only
called when the first one succeeds.  Both functions are free to pass
their argument to error_set().  Because error_set() asserts no error
has been set, this effectively means they must not be called with an
error set.

The qapi-generated code uses the error API differently:

    // *errp was initialized to NULL somewhere up the call chain
    frob(..., errp);
    gnat(..., errp);

Errors accumulate in *errp: first error wins, subsequent errors get
dropped.  To make this work, the second function does nothing when
called with an error set.  Requires non-null errp, or else the second
function can't see the first one fail.

This usage has also bled into visitor tests, and two device model
object property getters rtc_get_date() and balloon_stats_get_all().

With the "accumulate" technique, you need fewer error checks in
callers, and buy that with an error check in every callee.  Can be
nice.

However, mixing the two techniques is confusing.  You can't use the
"accumulate" technique with functions designed for the "check
separately" technique.  You can use the "check separately" technique
with functions designed for the "accumulate" technique, but then
error_set() can't catch you setting an error more than once.

Standardize on the "check separately" technique for now, because it's
overwhelmingly prevalent.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2014-05-15 14:00:46 -04:00
..
dataplane dataplane: fix shadowed return value 2014-01-22 13:48:18 +01:00
Makefile.objs
vhost.c
virtio-balloon.c qapi: Replace uncommon use of the error API by the common one 2014-05-15 14:00:46 -04:00
virtio-bus.c virtio-bus: cleanup plug/unplug interface 2013-12-09 21:46:48 +01:00
virtio-mmio.c virtio-bus: remove vdev field 2013-12-09 21:46:48 +01:00
virtio-pci.c qom: Add check() argument to object_property_add_link() 2014-03-19 22:23:13 +01:00
virtio-pci.h virtio-pci: remove vdev field 2013-12-09 21:46:48 +01:00
virtio-rng.c virtio-rng: Avoid default_backend refcount leak 2014-03-19 22:23:47 +01:00
virtio.c virtio: allow mapping up to max queue size 2014-05-12 12:07:21 +03:00