From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64847C47404 for ; Fri, 11 Oct 2019 17:31:08 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 36C0A21D56 for ; Fri, 11 Oct 2019 17:31:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 36C0A21D56 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIyks-0001PG-T2 for qemu-devel@archiver.kernel.org; Fri, 11 Oct 2019 13:31:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36422) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIxQx-0006IF-K1 for qemu-devel@nongnu.org; Fri, 11 Oct 2019 12:06:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iIxQv-0004UE-N8 for qemu-devel@nongnu.org; Fri, 11 Oct 2019 12:06:27 -0400 Received: from relay.sw.ru ([185.231.240.75]:48094) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iIxQv-0004GB-Eb for qemu-devel@nongnu.org; Fri, 11 Oct 2019 12:06:25 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iIxQj-0003XG-VY; Fri, 11 Oct 2019 19:06:14 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Subject: [RFC v5 053/126] virtio: introduce ERRP_AUTO_PROPAGATE Date: Fri, 11 Oct 2019 19:04:39 +0300 Message-Id: <20191011160552.22907-54-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191011160552.22907-1-vsementsov@virtuozzo.com> References: <20191011160552.22907-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , vsementsov@virtuozzo.com, "Michael S. Tsirkin" , armbru@redhat.com, Greg Kurz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases. If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are: 1. No need of explicit error_propagate call 2. No need of explicit local_err variable: use errp directly 3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate) This commit (together with its neighbors) was generated by for f in $(git grep -l errp \*.[ch]); do \ spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \ --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \ done; then fix a bit of compilation problems: coccinelle for some reason leaves several f() { ... goto out; ... out: } patterns, with "out:" at function end. then ./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)" (auto-msg was a file with this commit message) Still, for backporting it may be more comfortable to use only the first command and then do one huge commit. Reported-by: Kevin Wolf Reported-by: Greg Kurz Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/virtio/virtio-balloon.c | 35 ++++++++++++++++------------------- hw/virtio/virtio-bus.c | 17 +++++++---------- hw/virtio/virtio-pci.c | 2 ++ hw/virtio/virtio-rng-pci.c | 7 +++---- hw/virtio/virtio.c | 19 ++++++++----------- 5 files changed, 36 insertions(+), 44 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 40b04f5180..eaee19df71 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -229,40 +229,38 @@ static void balloon_stats_poll_cb(void *opaque) static void balloon_stats_get_all(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { - Error *err = NULL; + ERRP_AUTO_PROPAGATE(); VirtIOBalloon *s = opaque; int i; - visit_start_struct(v, name, NULL, 0, &err); - if (err) { - goto out; + visit_start_struct(v, name, NULL, 0, errp); + if (*errp) { + return; } - visit_type_int(v, "last-update", &s->stats_last_update, &err); - if (err) { + visit_type_int(v, "last-update", &s->stats_last_update, errp); + if (*errp) { goto out_end; } - visit_start_struct(v, "stats", NULL, 0, &err); - if (err) { + visit_start_struct(v, "stats", NULL, 0, errp); + if (*errp) { goto out_end; } for (i = 0; i < VIRTIO_BALLOON_S_NR; i++) { - visit_type_uint64(v, balloon_stat_names[i], &s->stats[i], &err); - if (err) { + visit_type_uint64(v, balloon_stat_names[i], &s->stats[i], errp); + if (*errp) { goto out_nested; } } - visit_check_struct(v, &err); + visit_check_struct(v, errp); out_nested: visit_end_struct(v, NULL); - if (!err) { - visit_check_struct(v, &err); + if (!*errp) { + visit_check_struct(v, errp); } out_end: visit_end_struct(v, NULL); -out: - error_propagate(errp, err); } static void balloon_stats_get_poll_interval(Object *obj, Visitor *v, @@ -277,13 +275,12 @@ static void balloon_stats_set_poll_interval(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { + ERRP_AUTO_PROPAGATE(); VirtIOBalloon *s = opaque; - Error *local_err = NULL; int64_t value; - visit_type_int(v, name, &value, &local_err); - if (local_err) { - error_propagate(errp, local_err); + visit_type_int(v, name, &value, errp); + if (*errp) { return; } diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c index b2c804292e..d823fe682d 100644 --- a/hw/virtio/virtio-bus.c +++ b/hw/virtio/virtio-bus.c @@ -42,20 +42,19 @@ do { printf("virtio_bus: " fmt , ## __VA_ARGS__); } while (0) /* A VirtIODevice is being plugged */ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp) { + ERRP_AUTO_PROPAGATE(); DeviceState *qdev = DEVICE(vdev); BusState *qbus = BUS(qdev_get_parent_bus(qdev)); VirtioBusState *bus = VIRTIO_BUS(qbus); VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus); VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev); bool has_iommu = virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM); - Error *local_err = NULL; DPRINTF("%s: plug device.\n", qbus->name); if (klass->pre_plugged != NULL) { - klass->pre_plugged(qbus->parent, &local_err); - if (local_err) { - error_propagate(errp, local_err); + klass->pre_plugged(qbus->parent, errp); + if (*errp) { return; } } @@ -63,17 +62,15 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp) /* Get the features of the plugged device. */ assert(vdc->get_features != NULL); vdev->host_features = vdc->get_features(vdev, vdev->host_features, - &local_err); - if (local_err) { - error_propagate(errp, local_err); + errp); + if (*errp) { return; } if (klass->device_plugged != NULL) { - klass->device_plugged(qbus->parent, &local_err); + klass->device_plugged(qbus->parent, errp); } - if (local_err) { - error_propagate(errp, local_err); + if (*errp) { return; } diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index c6b47a9c73..a36e5f6990 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1525,6 +1525,7 @@ static void virtio_pci_pre_plugged(DeviceState *d, Error **errp) /* This is called by virtio-bus just after the device is plugged. */ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) { + ERRP_AUTO_PROPAGATE(); VirtIOPCIProxy *proxy = VIRTIO_PCI(d); VirtioBusState *bus = &proxy->bus; bool legacy = virtio_pci_legacy(proxy); @@ -1684,6 +1685,7 @@ static void virtio_pci_device_unplugged(DeviceState *d) static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev); VirtioPCIClass *k = VIRTIO_PCI_GET_CLASS(pci_dev); bool pcie_port = pci_bus_is_express(pci_get_bus(pci_dev)) && diff --git a/hw/virtio/virtio-rng-pci.c b/hw/virtio/virtio-rng-pci.c index 8aaf54b781..993bb9aae4 100644 --- a/hw/virtio/virtio-rng-pci.c +++ b/hw/virtio/virtio-rng-pci.c @@ -32,14 +32,13 @@ struct VirtIORngPCI { static void virtio_rng_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); VirtIORngPCI *vrng = VIRTIO_RNG_PCI(vpci_dev); DeviceState *vdev = DEVICE(&vrng->vdev); - Error *err = NULL; qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); - object_property_set_bool(OBJECT(vdev), true, "realized", &err); - if (err) { - error_propagate(errp, err); + object_property_set_bool(OBJECT(vdev), true, "realized", errp); + if (*errp) { return; } diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 527df03bfd..3a318232e6 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2606,24 +2606,22 @@ static void virtio_memory_listener_commit(MemoryListener *listener) static void virtio_device_realize(DeviceState *dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev); - Error *err = NULL; /* Devices should either use vmsd or the load/save methods */ assert(!vdc->vmsd || !vdc->load); if (vdc->realize != NULL) { - vdc->realize(dev, &err); - if (err != NULL) { - error_propagate(errp, err); + vdc->realize(dev, errp); + if (*errp) { return; } } - virtio_bus_device_plugged(vdev, &err); - if (err != NULL) { - error_propagate(errp, err); + virtio_bus_device_plugged(vdev, errp); + if (*errp) { vdc->unrealize(dev, NULL); return; } @@ -2634,16 +2632,15 @@ static void virtio_device_realize(DeviceState *dev, Error **errp) static void virtio_device_unrealize(DeviceState *dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev); - Error *err = NULL; virtio_bus_device_unplugged(vdev); if (vdc->unrealize != NULL) { - vdc->unrealize(dev, &err); - if (err != NULL) { - error_propagate(errp, err); + vdc->unrealize(dev, errp); + if (*errp) { return; } } -- 2.21.0