From nobody Mon Feb 9 01:20:40 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1570813486; cv=none; d=zoho.com; s=zohoarc; b=FCzuhdcSAIhFFCld+A0yQez6fXKsLxJF23pZQLDqL8p7lcsiCVA1U4L8eJ6hEaWxvPRwshJ7gtySMUCGPmjTOrzFNwb7SoEQCTtQZTpQjbvP+ynRsu+W9hOGrA0SnLih+4AVC55riQIrfGC7ADfOwWd2zx9KzXwA2pAG355UY94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570813486; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+AipQ/R3IpjlcM4Wrw44mKt3Wh32nV4HUy5xfhEE520=; b=lmvFgOow7elff9pAgmN93fYQrjr3KUQJcY3qZ8rOaavAbCNCEFKXowv/5eh3VjVSEOspnGYZJFfbsjItU2vioyAoJC8w8kGBEyUDTL+EoO3HHs36hZ9Jb8nO5TWDppXtaGQ1VD86GzvwlPVzZ+fuDiEbr7KU+XtWENPl0U8TKEE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1570813486522139.85063201239518; Fri, 11 Oct 2019 10:04:46 -0700 (PDT) Received: from localhost ([::1]:54328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIyLN-00009w-35 for importer@patchew.org; Fri, 11 Oct 2019 13:04:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36564) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIxR0-0006Ny-Mf for qemu-devel@nongnu.org; Fri, 11 Oct 2019 12:06:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iIxQy-0004aC-9e for qemu-devel@nongnu.org; Fri, 11 Oct 2019 12:06:30 -0400 Received: from relay.sw.ru ([185.231.240.75]:47914) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iIxQx-00048G-SA; Fri, 11 Oct 2019 12:06:28 -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 1iIxQc-0003XG-Hd; Fri, 11 Oct 2019 19:06:06 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Subject: [RFC v5 028/126] s390x: introduce ERRP_AUTO_PROPAGATE Date: Fri, 11 Oct 2019 19:04:14 +0300 Message-Id: <20191011160552.22907-29-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: quoted-printable 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 , Eric Farman , vsementsov@virtuozzo.com, David Hildenbrand , qemu-s390x@nongnu.org, Cornelia Huck , armbru@redhat.com, Greg Kurz , Halil Pasic , Christian Borntraeger , Alex Williamson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 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 =3D=3D &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/intc/s390_flic_kvm.c | 9 ++++----- hw/s390x/3270-ccw.c | 13 ++++++------- hw/s390x/css-bridge.c | 7 +++---- hw/s390x/css.c | 7 +++---- hw/s390x/s390-skeys.c | 7 +++---- hw/s390x/s390-virtio-ccw.c | 11 +++++------ hw/s390x/sclp.c | 15 ++++++--------- hw/s390x/tod-kvm.c | 14 ++++++-------- hw/vfio/ccw.c | 24 +++++++++++------------- target/s390x/cpu.c | 26 ++++++++++++-------------- 10 files changed, 59 insertions(+), 74 deletions(-) diff --git a/hw/intc/s390_flic_kvm.c b/hw/intc/s390_flic_kvm.c index cedccba8a9..5550cecef8 100644 --- a/hw/intc/s390_flic_kvm.c +++ b/hw/intc/s390_flic_kvm.c @@ -578,14 +578,14 @@ typedef struct KVMS390FLICStateClass { =20 static void kvm_s390_flic_realize(DeviceState *dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); KVMS390FLICState *flic_state =3D KVM_S390_FLIC(dev); struct kvm_create_device cd =3D {0}; struct kvm_device_attr test_attr =3D {0}; int ret; - Error *errp_local =3D NULL; =20 - KVM_S390_FLIC_GET_CLASS(dev)->parent_realize(dev, &errp_local); - if (errp_local) { + KVM_S390_FLIC_GET_CLASS(dev)->parent_realize(dev, errp); + if (*errp) { goto fail; } flic_state->fd =3D -1; @@ -593,7 +593,7 @@ static void kvm_s390_flic_realize(DeviceState *dev, Err= or **errp) cd.type =3D KVM_DEV_TYPE_FLIC; ret =3D kvm_vm_ioctl(kvm_state, KVM_CREATE_DEVICE, &cd); if (ret < 0) { - error_setg_errno(&errp_local, errno, "Creating the KVM device fail= ed"); + error_setg_errno(errp, errno, "Creating the KVM device failed"); trace_flic_create_device(errno); goto fail; } @@ -605,7 +605,6 @@ static void kvm_s390_flic_realize(DeviceState *dev, Err= or **errp) KVM_HAS_DEVICE_ATTR, test_attr= ); return; fail: - error_propagate(errp, errp_local); } =20 static void kvm_s390_flic_reset(DeviceState *dev) diff --git a/hw/s390x/3270-ccw.c b/hw/s390x/3270-ccw.c index c19a75b9b7..830d7f385e 100644 --- a/hw/s390x/3270-ccw.c +++ b/hw/s390x/3270-ccw.c @@ -95,13 +95,13 @@ static int emulated_ccw_3270_cb(SubchDev *sch, CCW1 ccw) =20 static void emulated_ccw_3270_realize(DeviceState *ds, Error **errp) { + ERRP_AUTO_PROPAGATE(); uint16_t chpid; EmulatedCcw3270Device *dev =3D EMULATED_CCW_3270(ds); EmulatedCcw3270Class *ck =3D EMULATED_CCW_3270_GET_CLASS(dev); CcwDevice *cdev =3D CCW_DEVICE(ds); CCWDeviceClass *cdk =3D CCW_DEVICE_GET_CLASS(cdev); SubchDev *sch; - Error *err =3D NULL; =20 sch =3D css_create_sch(cdev->devno, errp); if (!sch) { @@ -117,7 +117,7 @@ static void emulated_ccw_3270_realize(DeviceState *ds, = Error **errp) chpid =3D css_find_free_chpid(sch->cssid); =20 if (chpid > MAX_CHPID) { - error_setg(&err, "No available chpid to use."); + error_setg(errp, "No available chpid to use."); goto out_err; } =20 @@ -128,20 +128,19 @@ static void emulated_ccw_3270_realize(DeviceState *ds= , Error **errp) sch->do_subchannel_work =3D do_subchannel_work_virtual; sch->ccw_cb =3D emulated_ccw_3270_cb; =20 - ck->init(dev, &err); - if (err) { + ck->init(dev, errp); + if (*errp) { goto out_err; } =20 - cdk->realize(cdev, &err); - if (err) { + cdk->realize(cdev, errp); + if (*errp) { goto out_err; } =20 return; =20 out_err: - error_propagate(errp, err); css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL); cdev->sch =3D NULL; g_free(sch); diff --git a/hw/s390x/css-bridge.c b/hw/s390x/css-bridge.c index 15a8ed96de..93dca01b0f 100644 --- a/hw/s390x/css-bridge.c +++ b/hw/s390x/css-bridge.c @@ -30,15 +30,14 @@ static void ccw_device_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); CcwDevice *ccw_dev =3D CCW_DEVICE(dev); CCWDeviceClass *k =3D CCW_DEVICE_GET_CLASS(ccw_dev); SubchDev *sch =3D ccw_dev->sch; - Error *err =3D NULL; =20 if (k->unplug) { - k->unplug(hotplug_dev, dev, &err); - if (err) { - error_propagate(errp, err); + k->unplug(hotplug_dev, dev, errp); + if (*errp) { return; } } diff --git a/hw/s390x/css.c b/hw/s390x/css.c index 844caab408..e911d2fbd2 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -2351,10 +2351,10 @@ static void get_css_devid(Object *obj, Visitor *v, = const char *name, static void set_css_devid(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { + ERRP_AUTO_PROPAGATE(); DeviceState *dev =3D DEVICE(obj); Property *prop =3D opaque; CssDevId *dev_id =3D qdev_get_prop_ptr(dev, prop); - Error *local_err =3D NULL; char *str; int num, n1, n2; unsigned int cssid, ssid, devid; @@ -2364,9 +2364,8 @@ static void set_css_devid(Object *obj, Visitor *v, co= nst char *name, return; } =20 - visit_type_str(v, name, &str, &local_err); - if (local_err) { - error_propagate(errp, local_err); + visit_type_str(v, name, &str, errp); + if (*errp) { return; } =20 diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c index bd37f39120..f176db09c9 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -107,11 +107,11 @@ void hmp_dump_skeys(Monitor *mon, const QDict *qdict) =20 void qmp_dump_skeys(const char *filename, Error **errp) { + ERRP_AUTO_PROPAGATE(); S390SKeysState *ss =3D s390_get_skeys_device(); S390SKeysClass *skeyclass =3D S390_SKEYS_GET_CLASS(ss); const uint64_t total_count =3D ram_size / TARGET_PAGE_SIZE; uint64_t handled_count =3D 0, cur_count; - Error *lerr =3D NULL; vaddr cur_gfn =3D 0; uint8_t *buf; int ret; @@ -155,8 +155,8 @@ void qmp_dump_skeys(const char *filename, Error **errp) } =20 /* write keys to stream */ - write_keys(f, buf, cur_gfn, cur_count, &lerr); - if (lerr) { + write_keys(f, buf, cur_gfn, cur_count, errp); + if (*errp) { goto out_free; } =20 @@ -165,7 +165,6 @@ void qmp_dump_skeys(const char *filename, Error **errp) } =20 out_free: - error_propagate(errp, lerr); g_free(buf); out: fclose(f); diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 18ad279a00..3c5e4c9804 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -61,19 +61,18 @@ S390CPU *s390_cpu_addr2state(uint16_t cpu_addr) static S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id, Error **errp) { + ERRP_AUTO_PROPAGATE(); S390CPU *cpu =3D S390_CPU(object_new(typename)); - Error *err =3D NULL; =20 - object_property_set_int(OBJECT(cpu), core_id, "core-id", &err); - if (err !=3D NULL) { + object_property_set_int(OBJECT(cpu), core_id, "core-id", errp); + if (*errp) { goto out; } - object_property_set_bool(OBJECT(cpu), true, "realized", &err); + object_property_set_bool(OBJECT(cpu), true, "realized", errp); =20 out: object_unref(OBJECT(cpu)); - if (err) { - error_propagate(errp, err); + if (*errp) { cpu =3D NULL; } return cpu; diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c index f57ce7b739..4cacd7b3a8 100644 --- a/hw/s390x/sclp.c +++ b/hw/s390x/sclp.c @@ -300,16 +300,16 @@ void s390_sclp_init(void) =20 static void sclp_realize(DeviceState *dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); MachineState *machine =3D MACHINE(qdev_get_machine()); SCLPDevice *sclp =3D SCLP(dev); - Error *err =3D NULL; uint64_t hw_limit; int ret; =20 object_property_set_bool(OBJECT(sclp->event_facility), true, "realized= ", - &err); - if (err) { - goto out; + errp); + if (*errp) { + return; } /* * qdev_device_add searches the sysbus for TYPE_SCLP_EVENTS_BUS. As lo= ng @@ -320,14 +320,11 @@ static void sclp_realize(DeviceState *dev, Error **er= rp) =20 ret =3D s390_set_memory_limit(machine->maxram_size, &hw_limit); if (ret =3D=3D -E2BIG) { - error_setg(&err, "host supports a maximum of %" PRIu64 " GB", + error_setg(errp, "host supports a maximum of %" PRIu64 " GB", hw_limit / GiB); } else if (ret) { - error_setg(&err, "setting the guest size failed"); + error_setg(errp, "setting the guest size failed"); } - -out: - error_propagate(errp, err); } =20 static void sclp_memory_init(SCLPDevice *sclp) diff --git a/hw/s390x/tod-kvm.c b/hw/s390x/tod-kvm.c index 6e21d83181..f59d07b375 100644 --- a/hw/s390x/tod-kvm.c +++ b/hw/s390x/tod-kvm.c @@ -55,7 +55,7 @@ static void kvm_s390_set_tod_raw(const S390TOD *tod, Erro= r **errp) =20 static void kvm_s390_tod_set(S390TODState *td, const S390TOD *tod, Error *= *errp) { - Error *local_err =3D NULL; + ERRP_AUTO_PROPAGATE(); =20 /* * Somebody (e.g. migration) set the TOD. We'll store it into KVM to @@ -64,9 +64,8 @@ static void kvm_s390_tod_set(S390TODState *td, const S390= TOD *tod, Error **errp) * is the point where we want to stop the initially running TOD to fire * it back up when actually starting the migrated guest. */ - kvm_s390_set_tod_raw(tod, &local_err); - if (local_err) { - error_propagate(errp, local_err); + kvm_s390_set_tod_raw(tod, errp); + if (*errp) { return; } =20 @@ -106,13 +105,12 @@ static void kvm_s390_tod_vm_state_change(void *opaque= , int running, =20 static void kvm_s390_tod_realize(DeviceState *dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); S390TODState *td =3D S390_TOD(dev); S390TODClass *tdc =3D S390_TOD_GET_CLASS(td); - Error *local_err =3D NULL; =20 - tdc->parent_realize(dev, &local_err); - if (local_err) { - error_propagate(errp, local_err); + tdc->parent_realize(dev, errp); + if (*errp) { return; } =20 diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 6863f6c69f..057c2e4f09 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -476,38 +476,38 @@ static VFIOGroup *vfio_ccw_get_group(S390CCWDevice *c= dev, Error **errp) =20 static void vfio_ccw_realize(DeviceState *dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); VFIOGroup *group; CcwDevice *ccw_dev =3D DO_UPCAST(CcwDevice, parent_obj, dev); S390CCWDevice *cdev =3D DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev); VFIOCCWDevice *vcdev =3D DO_UPCAST(VFIOCCWDevice, cdev, cdev); S390CCWDeviceClass *cdc =3D S390_CCW_DEVICE_GET_CLASS(cdev); - Error *err =3D NULL; =20 /* Call the class init function for subchannel. */ if (cdc->realize) { - cdc->realize(cdev, vcdev->vdev.sysfsdev, &err); - if (err) { - goto out_err_propagate; + cdc->realize(cdev, vcdev->vdev.sysfsdev, errp); + if (*errp) { + return; } } =20 - group =3D vfio_ccw_get_group(cdev, &err); + group =3D vfio_ccw_get_group(cdev, errp); if (!group) { goto out_group_err; } =20 - vfio_ccw_get_device(group, vcdev, &err); - if (err) { + vfio_ccw_get_device(group, vcdev, errp); + if (*errp) { goto out_device_err; } =20 - vfio_ccw_get_region(vcdev, &err); - if (err) { + vfio_ccw_get_region(vcdev, errp); + if (*errp) { goto out_region_err; } =20 - vfio_ccw_register_io_notifier(vcdev, &err); - if (err) { + vfio_ccw_register_io_notifier(vcdev, errp); + if (*errp) { goto out_notifier_err; } =20 @@ -523,8 +523,6 @@ out_group_err: if (cdc->unrealize) { cdc->unrealize(cdev, NULL); } -out_err_propagate: - error_propagate(errp, err); } =20 static void vfio_ccw_unrealize(DeviceState *dev, Error **errp) diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index 3abe7e80fd..5569b48934 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -184,42 +184,42 @@ static void s390_cpu_disas_set_info(CPUState *cpu, di= sassemble_info *info) =20 static void s390_cpu_realizefn(DeviceState *dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); CPUState *cs =3D CPU(dev); S390CPUClass *scc =3D S390_CPU_GET_CLASS(dev); #if !defined(CONFIG_USER_ONLY) S390CPU *cpu =3D S390_CPU(dev); #endif - Error *err =3D NULL; =20 /* the model has to be realized before qemu_init_vcpu() due to kvm */ - s390_realize_cpu_model(cs, &err); - if (err) { - goto out; + s390_realize_cpu_model(cs, errp); + if (*errp) { + return; } =20 #if !defined(CONFIG_USER_ONLY) MachineState *ms =3D MACHINE(qdev_get_machine()); unsigned int max_cpus =3D ms->smp.max_cpus; if (cpu->env.core_id >=3D max_cpus) { - error_setg(&err, "Unable to add CPU with core-id: %" PRIu32 + error_setg(errp, "Unable to add CPU with core-id: %" PRIu32 ", maximum core-id: %d", cpu->env.core_id, max_cpus - 1); - goto out; + return; } =20 if (cpu_exists(cpu->env.core_id)) { - error_setg(&err, "Unable to add CPU with core-id: %" PRIu32 + error_setg(errp, "Unable to add CPU with core-id: %" PRIu32 ", it already exists", cpu->env.core_id); - goto out; + return; } =20 /* sync cs->cpu_index and env->core_id. The latter is needed for TCG. = */ cs->cpu_index =3D cpu->env.core_id; #endif =20 - cpu_exec_realizefn(cs, &err); - if (err !=3D NULL) { - goto out; + cpu_exec_realizefn(cs, errp); + if (*errp) { + return; } =20 #if !defined(CONFIG_USER_ONLY) @@ -240,9 +240,7 @@ static void s390_cpu_realizefn(DeviceState *dev, Error = **errp) cpu_reset(cs); } =20 - scc->parent_realize(dev, &err); -out: - error_propagate(errp, err); + scc->parent_realize(dev, errp); } =20 static GuestPanicInformation *s390_cpu_get_crash_info(CPUState *cs) --=20 2.21.0