From nobody Thu Apr 25 07:13:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578685455; cv=none; d=zohomail.com; s=zohoarc; b=KZM3kgcXxLLoOPnjbQWxIWl2u5oTkemo4td6IeM3NXynf2aY2td9KH6McEAaFEm8tfBuWLMlKbk9q8DCn5jh8d8Amr+WgVwEWDIPA11REd0Ski93SnIS9R2EWnpxcS2HDCbTZtgxymfzUyfq1XjpddFwyGg3QIZoiEMR0eExUWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578685455; h=Content-Type: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=p1qo0095BLLyXWBVgvazAKrmezponJGXGvdMGomS9Jo=; b=erUOie4XClESnFCWJyEPaU1MHzZ5Nr34nXmBZAJ/8lWnPZoFiQ9vZdes8zn00y8T7+AIf8mbpwHM4st01OImW6XeuEtfKA4NL62WaACIj2yr1Z+v31JBGGjm8V3W/07izTQyk9+BOiUQ9xLh89Vn2H4X4CuaYhvCHVmfPArcLZ0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.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 1578685455566614.1387374493263; Fri, 10 Jan 2020 11:44:15 -0800 (PST) Received: from localhost ([::1]:51016 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq0Cb-0003gD-Qy for importer@patchew.org; Fri, 10 Jan 2020 14:44:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44564) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq0Ao-0001mG-9Q for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iq0Am-0004y0-H0 for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:22 -0500 Received: from relay.sw.ru ([185.231.240.75]:53970) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iq0Am-0004mZ-80; Fri, 10 Jan 2020 14:42:20 -0500 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iq0AT-0008Ob-Ta; Fri, 10 Jan 2020 22:42:02 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Subject: [PATCH v6 01/11] qapi/error: add (Error **errp) cleaning APIs Date: Fri, 10 Jan 2020 22:41:48 +0300 Message-Id: <20200110194158.14190-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200110194158.14190-1-vsementsov@virtuozzo.com> References: <20200110194158.14190-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 , Vladimir Sementsov-Ogievskiy , Laszlo Ersek , qemu-block@nongnu.org, Paul Durrant , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , Greg Kurz , Max Reitz , Stefano Stabellini , Gerd Hoffmann , Stefan Hajnoczi , Anthony Perard , xen-devel@lists.xenproject.org, Michael Roth , Markus Armbruster , Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Reviewed-by: Greg Kurz --- CC: Cornelia Huck CC: Eric Blake CC: Kevin Wolf CC: Max Reitz CC: Greg Kurz CC: Stefan Hajnoczi CC: Stefano Stabellini CC: Anthony Perard CC: Paul Durrant CC: "Philippe Mathieu-Daud=C3=A9" CC: Laszlo Ersek CC: Gerd Hoffmann CC: Stefan Berger CC: Markus Armbruster CC: Michael Roth CC: qemu-block@nongnu.org CC: xen-devel@lists.xenproject.org include/qapi/error.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/qapi/error.h b/include/qapi/error.h index ad5b6e896d..fa8d51fd6d 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -309,6 +309,32 @@ void warn_reportf_err(Error *err, const char *fmt, ...) void error_reportf_err(Error *err, const char *fmt, ...) GCC_FMT_ATTR(2, 3); =20 +/* + * Functions to clean Error **errp: call corresponding Error *err cleaning + * function an set pointer to NULL + */ +static inline void error_free_errp(Error **errp) +{ + assert(errp && *errp); + error_free(*errp); + *errp =3D NULL; +} + +static inline void error_report_errp(Error **errp) +{ + assert(errp && *errp); + error_report_err(*errp); + *errp =3D NULL; +} + +static inline void warn_report_errp(Error **errp) +{ + assert(errp && *errp); + warn_report_err(*errp); + *errp =3D NULL; +} + + /* * Just like error_setg(), except you get to specify the error class. * Note: use of error classes other than ERROR_CLASS_GENERIC_ERROR is --=20 2.21.0 From nobody Thu Apr 25 07:13:13 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1578685425; cv=none; d=zohomail.com; s=zohoarc; b=mqPSeh1NUpAVACJzXkpCeOJDADp5QfvCFa58+Yu2Z8oR6dgBTASAR+GI7Bzs9kcsAlBBG7pj2nez0+1TJjD98RgkB79hCw9V7hW7WkrPmwqi+zKZMryOCWjqvKLUBi4NPsftDsfqW4SQKG6pPf+zgf69DQfIhqms6ZTBFmX3tWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578685425; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=737njdVIyRMraSnvqsm5DOw5L0AK2Zkuas2VrHwFPdU=; b=YnHpNff/58LJCHYsVrMXem9NOUTDleikihbAMlxiR8cEjegGJCg/m83BnAB33w2KcQ1NLxEqCbLi6nB2FuEjOUWAlfMP2mGQL1OOZKtz3OnFPlQsS5C/NXHC44DN1dhnNb7EkS0NPc+e68ZgWO0jUaWC30q8jRZUu/Ixw/Uldjg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1578685425748613.9886213806042; Fri, 10 Jan 2020 11:43:45 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iq0BF-0003qB-9C; Fri, 10 Jan 2020 19:42:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iq0BD-0003q4-Nj for xen-devel@lists.xenproject.org; Fri, 10 Jan 2020 19:42:47 +0000 Received: from relay.sw.ru (unknown [185.231.240.75]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 586fad48-33e1-11ea-a2eb-bc764e2007e4; Fri, 10 Jan 2020 19:42:34 +0000 (UTC) Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iq0AU-0008Ob-Dz; Fri, 10 Jan 2020 22:42:02 +0300 X-Inumbo-ID: 586fad48-33e1-11ea-a2eb-bc764e2007e4 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 10 Jan 2020 22:41:49 +0300 Message-Id: <20200110194158.14190-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200110194158.14190-1-vsementsov@virtuozzo.com> References: <20200110194158.14190-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 02/11] error: auto propagated local_err X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Laszlo Ersek , qemu-block@nongnu.org, Paul Durrant , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , Greg Kurz , Max Reitz , Stefano Stabellini , Gerd Hoffmann , Stefan Hajnoczi , Anthony Perard , xen-devel@lists.xenproject.org, Eric Blake , Michael Roth , Markus Armbruster , Stefan Berger Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Here is introduced ERRP_AUTO_PROPAGATE macro, to be used at start of functions with errp OUT parameter. It has three goals: 1. Fix issue with error_fatal & error_prepend/error_append_hint: user can't see this additional information, because exit() happens in error_setg earlier than information is added. [Reported by Greg Kurz] 2. Fix issue with error_abort & error_propagate: when we wrap error_abort by local_err+error_propagate, resulting coredump will refer to error_propagate and not to the place where error happened. (the macro itself doesn't fix the issue, but it allows to [3.] drop all local_err+error_propagate pattern, which will definitely fix the issue) [Reported by Kevin Wolf] 3. Drop local_err+error_propagate pattern, which is used to workaround void functions with errp parameter, when caller wants to know resulting status. (Note: actually these functions could be merely updated to return int error code). To achieve these goals, we need to add invocation of the macro at start of functions, which needs error_prepend/error_append_hint (1.); add invocation of the macro at start of functions which do local_err+error_propagate scenario the check errors, drop local errors from them and just use *errp instead (2., 3.). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Reviewed-by: Greg Kurz --- CC: Cornelia Huck CC: Eric Blake CC: Kevin Wolf CC: Max Reitz CC: Greg Kurz CC: Stefan Hajnoczi CC: Stefano Stabellini CC: Anthony Perard CC: Paul Durrant CC: "Philippe Mathieu-Daud=C3=A9" CC: Laszlo Ersek CC: Gerd Hoffmann CC: Stefan Berger CC: Markus Armbruster CC: Michael Roth CC: qemu-block@nongnu.org CC: xen-devel@lists.xenproject.org include/qapi/error.h | 84 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/include/qapi/error.h b/include/qapi/error.h index fa8d51fd6d..532b9afb9e 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -78,7 +78,7 @@ * Call a function treating errors as fatal: * foo(arg, &error_fatal); * - * Receive an error and pass it on to the caller: + * Receive an error and pass it on to the caller (DEPRECATED*): * Error *err =3D NULL; * foo(arg, &err); * if (err) { @@ -98,6 +98,50 @@ * foo(arg, errp); * for readability. * + * DEPRECATED* This pattern is deprecated now, use ERRP_AUTO_PROPAGATE mac= ro + * instead (defined below). + * It's deprecated because of two things: + * + * 1. Issue with error_abort & error_propagate: when we wrap error_abort by + * local_err+error_propagate, resulting coredump will refer to error_propa= gate + * and not to the place where error happened. + * + * 2. A lot of extra code of the same pattern + * + * How to update old code to use ERRP_AUTO_PROPAGATE? + * + * All you need is to add ERRP_AUTO_PROPAGATE() invocation at function sta= rt, + * than you may safely dereference errp to check errors and do not need any + * additional local Error variables or calls to error_propagate(). + * + * Example: + * + * old code + * + * void fn(..., Error **errp) { + * Error *err =3D NULL; + * foo(arg, &err); + * if (err) { + * handle the error... + * error_propagate(errp, err); + * return; + * } + * ... + * } + * + * updated code + * + * void fn(..., Error **errp) { + * ERRP_AUTO_PROPAGATE(); + * foo(arg, errp); + * if (*errp) { + * handle the error... + * return; + * } + * ... + * } + * + * * Receive and accumulate multiple errors (first one wins): * Error *err =3D NULL, *local_err =3D NULL; * foo(arg, &err); @@ -348,6 +392,44 @@ void error_set_internal(Error **errp, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(6, 7); =20 +typedef struct ErrorPropagator { + Error *local_err; + Error **errp; +} ErrorPropagator; + +static inline void error_propagator_cleanup(ErrorPropagator *prop) +{ + error_propagate(prop->errp, prop->local_err); +} + +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(ErrorPropagator, error_propagator_cleanup= ); + +/* + * ERRP_AUTO_PROPAGATE + * + * This macro is created to be the first line of a function which use + * Error **errp parameter to report error. It's needed only in cases where= we + * want to use error_prepend, error_append_hint or dereference *errp. It's + * still safe (but useless) in other cases. + * + * If errp is NULL or points to error_fatal, it is rewritten to point to a + * local Error object, which will be automatically propagated to the origi= nal + * errp on function exit (see error_propagator_cleanup). + * + * After invocation of this macro it is always safe to dereference errp + * (as it's not NULL anymore) and to add information (by error_prepend or + * error_append_hint) + * (as, if it was error_fatal, we swapped it with a local_error to be + * propagated on cleanup). + * + * Note: we don't wrap the error_abort case, as we want resulting coredump + * to point to the place where the error happened, not to error_propagate. + */ +#define ERRP_AUTO_PROPAGATE() \ + g_auto(ErrorPropagator) _auto_errp_prop =3D {.errp =3D errp}; \ + errp =3D ((errp =3D=3D NULL || *errp =3D=3D error_fatal) \ + ? &_auto_errp_prop.local_err : errp) + /* * Special error destination to abort on error. * See error_setg() and error_propagate() for details. --=20 2.21.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Apr 25 07:13:13 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1578685425; cv=none; d=zohomail.com; s=zohoarc; b=nq1LJDCO2ADIz6Raa8b0oBeuYdtdAQcckW5erVe0o4C67A1i77y+fMvCxDlBjkp+eoRKhTp8hwC2dIZLCfHXE1BArbNux2pi3+iqW8wEnkutqT1L7CFwGQvmFLONr6CaDcCzjWzPSa7QNrMSRHvf7a5VyW3dsmMcGHcRgcmYqwI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578685425; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KzwD8nhjU88yBqHnArb8RNP0tsw0r5ze8kXJNhjYXao=; b=eYL59E3F5BPwZayLlaGIuBsxtehLQHD1LcoJ+4wfQXMi9komDPOhGqGt1iO6Hjh0BNx/GlDm2WwLxKdNOI82cHUDfMK3OKLgD8Pnax5I6dJjMwluz6eZQPBeRutg2K19murdqwryw9XsDpfdxUqQBCmSsh+VIexlZY2zfZhpyK8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 157868542560891.73092924985201; Fri, 10 Jan 2020 11:43:45 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iq0BA-0003pt-0r; Fri, 10 Jan 2020 19:42:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iq0B8-0003po-Ox for xen-devel@lists.xenproject.org; Fri, 10 Jan 2020 19:42:42 +0000 Received: from relay.sw.ru (unknown [185.231.240.75]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 57c1c304-33e1-11ea-a2eb-bc764e2007e4; Fri, 10 Jan 2020 19:42:32 +0000 (UTC) Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iq0AU-0008Ob-NH; Fri, 10 Jan 2020 22:42:02 +0300 X-Inumbo-ID: 57c1c304-33e1-11ea-a2eb-bc764e2007e4 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 10 Jan 2020 22:41:50 +0300 Message-Id: <20200110194158.14190-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200110194158.14190-1-vsementsov@virtuozzo.com> References: <20200110194158.14190-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 03/11] scripts: add coccinelle script to use auto propagated errp X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Laszlo Ersek , qemu-block@nongnu.org, Paul Durrant , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , Greg Kurz , Max Reitz , Stefano Stabellini , Gerd Hoffmann , Stefan Hajnoczi , Anthony Perard , xen-devel@lists.xenproject.org, Eric Blake , Michael Roth , Markus Armbruster , Stefan Berger Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- CC: Cornelia Huck CC: Eric Blake CC: Kevin Wolf CC: Max Reitz CC: Greg Kurz CC: Stefan Hajnoczi CC: Stefano Stabellini CC: Anthony Perard CC: Paul Durrant CC: "Philippe Mathieu-Daud=C3=A9" CC: Laszlo Ersek CC: Gerd Hoffmann CC: Stefan Berger CC: Markus Armbruster CC: Michael Roth CC: qemu-block@nongnu.org CC: xen-devel@lists.xenproject.org include/qapi/error.h | 3 + scripts/coccinelle/auto-propagated-errp.cocci | 139 ++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 scripts/coccinelle/auto-propagated-errp.cocci diff --git a/include/qapi/error.h b/include/qapi/error.h index 532b9afb9e..dcfb77e107 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -141,6 +141,9 @@ * ... * } * + * For mass conversion use script + * scripts/coccinelle/auto-propagated-errp.cocci + * * * Receive and accumulate multiple errors (first one wins): * Error *err =3D NULL, *local_err =3D NULL; diff --git a/scripts/coccinelle/auto-propagated-errp.cocci b/scripts/coccin= elle/auto-propagated-errp.cocci new file mode 100644 index 0000000000..6c72a5049f --- /dev/null +++ b/scripts/coccinelle/auto-propagated-errp.cocci @@ -0,0 +1,139 @@ +// Use ERRP_AUTO_PROPAGATE (see include/qapi/error.h) +// +// Copyright (c) 2020 Virtuozzo International GmbH. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// Usage example: +// spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \ +// --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff \ +// blockdev-nbd.c qemu-nbd.c {block/nbd*,nbd/*,include/block/nbd*}.[hc] + +@@ +// Add invocation to errp-functions where necessary +// We should skip functions with "Error *const *errp" +// parameter, but how to do it with coccinelle? +// I don't know, so, I skip them by function name regex. +// It's safe: if we not skip some functions with +// "Error *const *errp", ERRP_AUTO_PROPAGATE invocation +// will fail to compile, because of const violation. +identifier fn !~ "error_append_.*_hint"; +identifier local_err, errp; +@@ + + fn(..., Error **errp, ...) + { ++ ERRP_AUTO_PROPAGATE(); + <+... + when !=3D ERRP_AUTO_PROPAGATE(); +( + error_append_hint(errp, ...); +| + error_prepend(errp, ...); +| + Error *local_err =3D NULL; +) + ...+> + } + +@rule1@ +// We do not inherit from previous rule, as we want to match +// also functions, which already had ERRP_AUTO_PROPAGATE +// invocation. +identifier fn !~ "error_append_.*_hint"; +identifier local_err, errp; +@@ + + fn(..., Error **errp, ...) + { + <... +- Error *local_err =3D NULL; + ...> + } + +@@ +// Handle pattern with goto, otherwise we'll finish up +// with labels at function end which will not compile. +identifier rule1.fn, rule1.local_err, rule1.errp; +identifier OUT; +@@ + + fn(...) + { + <... +- goto OUT; ++ return; + ...> +- OUT: +- error_propagate(errp, local_err); + } + +@@ +identifier rule1.fn, rule1.local_err, rule1.errp; +expression list args; // to reindent error_propagate_prepend +@@ + + fn(...) + { + <... +( +- error_free(local_err); +- local_err =3D NULL; ++ error_free_errp(errp); +| +- error_free(local_err); ++ error_free_errp(errp); +| +- error_report_err(local_err); ++ error_report_errp(errp); +| +- warn_report_err(local_err); ++ warn_report_errp(errp); +| +- error_propagate_prepend(errp, local_err, args); ++ error_prepend(errp, args); +| +- error_propagate(errp, local_err); +) + ...> + } + +@@ +identifier rule1.fn, rule1.local_err, rule1.errp; +@@ + + fn(...) + { + <... +( +- &local_err ++ errp +| +- local_err ++ *errp +) + ...> + } + +@@ +identifier rule1.fn, rule1.errp; +@@ + + fn(...) + { + <... +- *errp !=3D NULL ++ *errp + ...> + } --=20 2.21.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Apr 25 07:13:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578685451; cv=none; d=zohomail.com; s=zohoarc; b=g+lZ51af6W0XudnSef/l/pWo9o/QFrlk2iGyr0QDQ+J8lGNlMRuiZqHVyeW0iHpDjfuagWoInp/Yu6cv45sxP7Ig8QILJWsE3mCyrcW/k3PqxF54ZUOk9Wh5LcyhKY5xAacXl3d+gFpdppCF/8Wy59Feh35/qo7vLU1gsXAEcWU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578685451; 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=ljUHPxY/ZraMQEycctTTQs4vyN3Kd9DXNd+t2ViguSY=; b=dD0atc2Njp+M2a6T9dASFSRqYcn8uEqp7NCsw4UJdd9la2PqmqjzD5iJkAOxHa20IDZoDshfdFPxTuCQPMwWW9uzRUoKDRUP8SGg4wQZooZ3cJWtCQMPfhjdcwMB3HDIkYUwXKudwVmDKSsUkeTvkJkYWXPlSYFDQCmHpq8ecOU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.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 1578685451878420.8932870612357; Fri, 10 Jan 2020 11:44:11 -0800 (PST) Received: from localhost ([::1]:51014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq0CX-0003bZ-Fi for importer@patchew.org; Fri, 10 Jan 2020 14:44:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44326) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq0Al-0001gs-On for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iq0Ad-0004dA-E1 for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:15 -0500 Received: from relay.sw.ru ([185.231.240.75]:53908) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iq0Ad-0004Ou-3G for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:11 -0500 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iq0AV-0008Ob-2m; Fri, 10 Jan 2020 22:42:03 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Subject: [PATCH v6 04/11] hw/sd/ssi-sd: fix error handling in ssi_sd_realize Date: Fri, 10 Jan 2020 22:41:51 +0300 Message-Id: <20200110194158.14190-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200110194158.14190-1-vsementsov@virtuozzo.com> References: <20200110194158.14190-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: Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" It's wrong to use same err object as errp parameter for several function calls without intermediate checking for error: we'll crash if try to set err object twice. Fix that, using new ERRP_AUTO_PROPAGATE macro. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- hw/sd/ssi-sd.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c index 91db069212..bc44e1a0f5 100644 --- a/hw/sd/ssi-sd.c +++ b/hw/sd/ssi-sd.c @@ -241,10 +241,10 @@ static const VMStateDescription vmstate_ssi_sd =3D { =20 static void ssi_sd_realize(SSISlave *d, Error **errp) { + ERRP_AUTO_PROPAGATE(); ssi_sd_state *s =3D FROM_SSI_SLAVE(ssi_sd_state, d); DeviceState *carddev; DriveInfo *dinfo; - Error *err =3D NULL; =20 qbus_create_inplace(&s->sdbus, sizeof(s->sdbus), TYPE_SD_BUS, DEVICE(d), "sd-bus"); @@ -254,14 +254,26 @@ static void ssi_sd_realize(SSISlave *d, Error **errp) dinfo =3D drive_get_next(IF_SD); carddev =3D qdev_create(BUS(&s->sdbus), TYPE_SD_CARD); if (dinfo) { - qdev_prop_set_drive(carddev, "drive", blk_by_legacy_dinfo(dinfo), = &err); + qdev_prop_set_drive(carddev, "drive", blk_by_legacy_dinfo(dinfo), = errp); + if (*errp) { + goto fail; + } + } + + object_property_set_bool(OBJECT(carddev), true, "spi", errp); + if (*errp) { + goto fail; } - object_property_set_bool(OBJECT(carddev), true, "spi", &err); - object_property_set_bool(OBJECT(carddev), true, "realized", &err); - if (err) { - error_setg(errp, "failed to init SD card: %s", error_get_pretty(er= r)); - return; + + object_property_set_bool(OBJECT(carddev), true, "realized", errp); + if (*errp) { + goto fail; } + + return; + +fail: + error_prepend(errp, "failed to init SD card: "); } =20 static void ssi_sd_reset(DeviceState *dev) --=20 2.21.0 From nobody Thu Apr 25 07:13:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578685452; cv=none; d=zohomail.com; s=zohoarc; b=cozL03vlIZpT3QvfSvIkDQ5NTMcNt3ojQfWJpQBee5pNIpxlV/Sp9s5wDfW7wR40vqOefh0N0mjPzswm4EnkCIcjQ7p7V99ndfe8IUft5yd6LgCj6Q+Myp/RbnTqLw4jXTrQGCZI8gz5Y5CWmwrJ1d/3Pn7LwZjugZUlgbmvEa8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578685452; h=Content-Type: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=VTnqXhoSgexEXbxQ5gPk32zBblQ/Qk/cjvkK+W/MF70=; b=n2DrfUUdvsdDSUpyEameYqtNx3zDwv9RknPSUD4tH4ETWxftNNLILqDdOvEyOIvUW26SsAwyx7iNM/7reHnYTcZsx6YeZkcZbwcKFXZtI89Pwe91ZdPvxBn/xs2FjT+Z7P5bhFGshQxDj08KiZTD5kSHXSPhu5UqtKLVfUprF70= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.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 1578685452834972.2913079325227; Fri, 10 Jan 2020 11:44:12 -0800 (PST) Received: from localhost ([::1]:51012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq0CY-0003bS-QW for importer@patchew.org; Fri, 10 Jan 2020 14:44:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44327) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq0Al-0001gt-Ol for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iq0Ad-0004dh-G6 for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:15 -0500 Received: from relay.sw.ru ([185.231.240.75]:53922) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iq0Ad-0004Re-3z for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:11 -0500 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iq0AV-0008Ob-Ai; Fri, 10 Jan 2020 22:42:03 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Subject: [PATCH v6 05/11] SD (Secure Card): introduce ERRP_AUTO_PROPAGATE Date: Fri, 10 Jan 2020 22:41:52 +0300 Message-Id: <20200110194158.14190-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200110194158.14190-1-vsementsov@virtuozzo.com> References: <20200110194158.14190-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.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 =3D=3D &error_fatal (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 then 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_fatal, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate) This commit is generated by command sed -n '/^SD (Secure Card)$/,/^$/{s/^F: //p}' \ MAINTAINERS | \ xargs git ls-files | grep '\.[hc]$' | \ xargs spatch \ --sp-file scripts/coccinelle/auto-propagated-errp.cocci \ --macro-file scripts/cocci-macro-file.h \ --in-place --no-show-diff --max-width 80 Reported-by: Kevin Wolf Reported-by: Greg Kurz Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/sd/sdhci-pci.c | 7 +++---- hw/sd/sdhci.c | 21 +++++++++------------ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/hw/sd/sdhci-pci.c b/hw/sd/sdhci-pci.c index 2c8d8f59b5..b1448cf22e 100644 --- a/hw/sd/sdhci-pci.c +++ b/hw/sd/sdhci-pci.c @@ -29,13 +29,12 @@ static Property sdhci_pci_properties[] =3D { =20 static void sdhci_pci_realize(PCIDevice *dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); SDHCIState *s =3D PCI_SDHCI(dev); - Error *local_err =3D NULL; =20 sdhci_initfn(s); - sdhci_common_realize(s, &local_err); - if (local_err) { - error_propagate(errp, local_err); + sdhci_common_realize(s, errp); + if (*errp) { return; } =20 diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index 18c0c052ce..ca258572b3 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -1293,7 +1293,7 @@ static const MemoryRegionOps sdhci_mmio_ops =3D { =20 static void sdhci_init_readonly_registers(SDHCIState *s, Error **errp) { - Error *local_err =3D NULL; + ERRP_AUTO_PROPAGATE(); =20 switch (s->sd_spec_version) { case 2 ... 3: @@ -1304,9 +1304,8 @@ static void sdhci_init_readonly_registers(SDHCIState = *s, Error **errp) } s->version =3D (SDHC_HCVER_VENDOR << 8) | (s->sd_spec_version - 1); =20 - sdhci_check_capareg(s, &local_err); - if (local_err) { - error_propagate(errp, local_err); + sdhci_check_capareg(s, errp); + if (*errp) { return; } } @@ -1337,11 +1336,10 @@ void sdhci_uninitfn(SDHCIState *s) =20 void sdhci_common_realize(SDHCIState *s, Error **errp) { - Error *local_err =3D NULL; + ERRP_AUTO_PROPAGATE(); =20 - sdhci_init_readonly_registers(s, &local_err); - if (local_err) { - error_propagate(errp, local_err); + sdhci_init_readonly_registers(s, errp); + if (*errp) { return; } s->buf_maxsz =3D sdhci_get_fifolen(s); @@ -1461,13 +1459,12 @@ static void sdhci_sysbus_finalize(Object *obj) =20 static void sdhci_sysbus_realize(DeviceState *dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); SDHCIState *s =3D SYSBUS_SDHCI(dev); SysBusDevice *sbd =3D SYS_BUS_DEVICE(dev); - Error *local_err =3D NULL; =20 - sdhci_common_realize(s, &local_err); - if (local_err) { - error_propagate(errp, local_err); + sdhci_common_realize(s, errp); + if (*errp) { return; } =20 --=20 2.21.0 From nobody Thu Apr 25 07:13:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578685452; cv=none; d=zohomail.com; s=zohoarc; b=JplXED2dNis/Ax1HzPnrd4k6VZwHhIFtSdgdgN3I9iLMriIbhVEjPCC041VFypLqgHcTwja3OdvvLzoNADLgH1wJWuiVxBecYzL6qatJ4mSjDtzbitL4bJdO5xqgOt/pSQm7+/cjTao6o3Pug+e/zqcme35Vzn66FPJYpqjfwFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578685452; h=Content-Type: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=DFG0PUVxx/+1zydjdedUZkdlKYtPamtXR45Sd0VW7+c=; b=KaomjXE7cKpvyqBBEaSTu/YGecnzDaeD3wVaGTajMFodhSmr+zzalRV8JN1l4/Rv6XGFVsiHE9NR0Etsxih56Q+Bbje1Ta971O9djRTIbCX6TnfGfj9nzfY76JvDNQjnpvu10Id38VnNf8GWf7jJb/B4DgALCeDdl0RfnwssZ/o= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.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 1578685452892316.20505422706117; Fri, 10 Jan 2020 11:44:12 -0800 (PST) Received: from localhost ([::1]:51010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq0CZ-0003b2-00 for importer@patchew.org; Fri, 10 Jan 2020 14:44:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44329) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq0Al-0001gv-P3 for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iq0Ad-0004dn-Fw for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:15 -0500 Received: from relay.sw.ru ([185.231.240.75]:53912) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iq0Ad-0004Ra-3U; Fri, 10 Jan 2020 14:42:11 -0500 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iq0AV-0008Ob-Mk; Fri, 10 Jan 2020 22:42:03 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Subject: [PATCH v6 06/11] pflash: introduce ERRP_AUTO_PROPAGATE Date: Fri, 10 Jan 2020 22:41:53 +0300 Message-Id: <20200110194158.14190-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200110194158.14190-1-vsementsov@virtuozzo.com> References: <20200110194158.14190-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Greg Kurz , Max Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.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 =3D=3D &error_fatal (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 then 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_fatal, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate) This commit is generated by command sed -n '/^Parallel NOR Flash devices$/,/^$/{s/^F: //p}' \ MAINTAINERS | \ xargs git ls-files | grep '\.[hc]$' | \ xargs spatch \ --sp-file scripts/coccinelle/auto-propagated-errp.cocci \ --macro-file scripts/cocci-macro-file.h \ --in-place --no-show-diff --max-width 80 Reported-by: Kevin Wolf Reported-by: Greg Kurz Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/block/pflash_cfi01.c | 7 +++---- hw/block/pflash_cfi02.c | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 54e6ebd385..9b12b04b65 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -700,12 +700,12 @@ static const MemoryRegionOps pflash_cfi01_ops =3D { =20 static void pflash_cfi01_realize(DeviceState *dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); PFlashCFI01 *pfl =3D PFLASH_CFI01(dev); uint64_t total_len; int ret; uint64_t blocks_per_device, sector_len_per_device, device_len; int num_devices; - Error *local_err =3D NULL; =20 if (pfl->sector_len =3D=3D 0) { error_setg(errp, "attribute \"sector-length\" not specified or zer= o."); @@ -739,9 +739,8 @@ static void pflash_cfi01_realize(DeviceState *dev, Erro= r **errp) &pfl->mem, OBJECT(dev), &pflash_cfi01_ops, pfl, - pfl->name, total_len, &local_err); - if (local_err) { - error_propagate(errp, local_err); + pfl->name, total_len, errp); + if (*errp) { return; } =20 diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index c7d92c3e79..7b33008fd5 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -719,9 +719,9 @@ static const MemoryRegionOps pflash_cfi02_ops =3D { =20 static void pflash_cfi02_realize(DeviceState *dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); PFlashCFI02 *pfl =3D PFLASH_CFI02(dev); int ret; - Error *local_err =3D NULL; =20 if (pfl->uniform_sector_len =3D=3D 0 && pfl->sector_len[0] =3D=3D 0) { error_setg(errp, "attribute \"sector-length\" not specified or zer= o."); @@ -787,9 +787,8 @@ static void pflash_cfi02_realize(DeviceState *dev, Erro= r **errp) =20 memory_region_init_rom_device(&pfl->orig_mem, OBJECT(pfl), &pflash_cfi02_ops, pfl, pfl->name, - pfl->chip_len, &local_err); - if (local_err) { - error_propagate(errp, local_err); + pfl->chip_len, errp); + if (*errp) { return; } =20 --=20 2.21.0 From nobody Thu Apr 25 07:13:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578685736; cv=none; d=zohomail.com; s=zohoarc; b=c8CXFzqIP6TOsZCHx3foFEy5JBupak95q1oymYQCJ4JyBE4cxtyroGRxxc950T9PbhqFE/kS/vMCxPYVpj4guwe8a3552B4aF1HtLirIDq+ErHdDn8e2Fljkecea4MFG7+E9zcUgGcvDW95dD7LRmWEEn2Kjhkt2LX4L2jmSYgw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578685736; h=Content-Type: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=z+mOjEnOvdud8DfmlmvHbkJ91H019qsF9Y1mBejLpYo=; b=U8mzX/WHPv4IOvine+SKpxJKGD96yyu6ixl6SJN7PjLjEJMyIi6vtwWDvMWJGfoCxNgOSUWmXDOe+3e7ZGob1Wm4Gn7j1Bc/apRdFd6Pnm+7mm6Sa6CMwjIwNcuIdFZPm/N3ixo3HNpZnJ8UDg2tSHCI1YBOGk+N8Ra8nRmBKBs= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.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 15786857360371007.9622099318308; Fri, 10 Jan 2020 11:48:56 -0800 (PST) Received: from localhost ([::1]:51082 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq0H8-0001YY-Uu for importer@patchew.org; Fri, 10 Jan 2020 14:48:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44324) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq0Am-0001gq-4K for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iq0Ad-0004cZ-Be for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:15 -0500 Received: from relay.sw.ru ([185.231.240.75]:53920) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iq0Ad-0004Rc-2s for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:11 -0500 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iq0AW-0008Ob-06; Fri, 10 Jan 2020 22:42:04 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Subject: [PATCH v6 07/11] fw_cfg: introduce ERRP_AUTO_PROPAGATE Date: Fri, 10 Jan 2020 22:41:54 +0300 Message-Id: <20200110194158.14190-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200110194158.14190-1-vsementsov@virtuozzo.com> References: <20200110194158.14190-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Greg Kurz , Gerd Hoffmann , Laszlo Ersek Errors-To: qemu-devel-bounces+importer=patchew.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 =3D=3D &error_fatal (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 then 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_fatal, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate) This commit is generated by command sed -n '/^Firmware configuration (fw_cfg)$/,/^$/{s/^F: //p}' \ MAINTAINERS | \ xargs git ls-files | grep '\.[hc]$' | \ xargs spatch \ --sp-file scripts/coccinelle/auto-propagated-errp.cocci \ --macro-file scripts/cocci-macro-file.h \ --in-place --no-show-diff --max-width 80 Reported-by: Kevin Wolf Reported-by: Greg Kurz Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/nvram/fw_cfg.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index 5d879c471e..4f019efcc4 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -1142,12 +1142,11 @@ static Property fw_cfg_io_properties[] =3D { =20 static void fw_cfg_io_realize(DeviceState *dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); FWCfgIoState *s =3D FW_CFG_IO(dev); - Error *local_err =3D NULL; =20 - fw_cfg_file_slots_allocate(FW_CFG(s), &local_err); - if (local_err) { - error_propagate(errp, local_err); + fw_cfg_file_slots_allocate(FW_CFG(s), errp); + if (*errp) { return; } =20 @@ -1193,14 +1192,13 @@ static Property fw_cfg_mem_properties[] =3D { =20 static void fw_cfg_mem_realize(DeviceState *dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); FWCfgMemState *s =3D FW_CFG_MEM(dev); SysBusDevice *sbd =3D SYS_BUS_DEVICE(dev); const MemoryRegionOps *data_ops =3D &fw_cfg_data_mem_ops; - Error *local_err =3D NULL; =20 - fw_cfg_file_slots_allocate(FW_CFG(s), &local_err); - if (local_err) { - error_propagate(errp, local_err); + fw_cfg_file_slots_allocate(FW_CFG(s), errp); + if (*errp) { return; } =20 --=20 2.21.0 From nobody Thu Apr 25 07:13:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578685610; cv=none; d=zohomail.com; s=zohoarc; b=RWg4znsxhJjc5eZZ09o2NwZJyhL37iKuJKbNpRSuUXp55h1V7CukcYl+9FyQ7+aN9+Rx2vIOrFGBDW5Kv0JQmzZTFIFdaV4Dt4GsebLgwNMzwa8nH8OTYEFDwl1iU4Lw44xecy631Zivio4nhTcWajvoMd1/kZqGPJzR5MPSYRQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578685610; 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=8nm9Vr9O4ADsbP+wKnu+nRzo2nWcIbXJPhghTJ4AIew=; b=dRrLghwJdndKhpSN30q5AR3JPMoVgm5DM/C/CI0E4mFN0Jdp3mQnkYA5LUKsMvIbsk5z7Nfge6vV2Kz879W8sFlvGbgiuWcsMKPThECX155GhWw5JmIOdlhiWd9NMxc6kzjVuufMGQyT/M9fZzVkURzqvv4wl6zEI7oGYJjqQtc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.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 1578685610644320.7982177497644; Fri, 10 Jan 2020 11:46:50 -0800 (PST) Received: from localhost ([::1]:51056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq0F7-0007S2-3u for importer@patchew.org; Fri, 10 Jan 2020 14:46:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44328) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq0Al-0001gu-P7 for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iq0Ad-0004dH-Dt for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:15 -0500 Received: from relay.sw.ru ([185.231.240.75]:53924) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iq0Ad-0004Rf-3P for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:11 -0500 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iq0AW-0008Ob-7B; Fri, 10 Jan 2020 22:42:04 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Subject: [PATCH v6 08/11] virtio-9p: introduce ERRP_AUTO_PROPAGATE Date: Fri, 10 Jan 2020 22:41:55 +0300 Message-Id: <20200110194158.14190-9-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200110194158.14190-1-vsementsov@virtuozzo.com> References: <20200110194158.14190-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 , Vladimir Sementsov-Ogievskiy , Greg Kurz 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 &error_fatal (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 then 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_fatal, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate) This commit is generated by command sed -n '/^virtio-9p$/,/^$/{s/^F: //p}' MAINTAINERS | \ xargs git ls-files | grep '\.[hc]$' | \ xargs spatch \ --sp-file scripts/coccinelle/auto-propagated-errp.cocci \ --macro-file scripts/cocci-macro-file.h \ --in-place --no-show-diff --max-width 80 Reported-by: Kevin Wolf Reported-by: Greg Kurz Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Greg Kurz --- hw/9pfs/9p-local.c | 12 +++++------- hw/9pfs/9p.c | 1 + 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index ca641390fb..253814ef2c 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -1481,10 +1481,10 @@ static void error_append_security_model_hint(Error = *const *errp) =20 static int local_parse_opts(QemuOpts *opts, FsDriverEntry *fse, Error **er= rp) { + ERRP_AUTO_PROPAGATE(); const char *sec_model =3D qemu_opt_get(opts, "security_model"); const char *path =3D qemu_opt_get(opts, "path"); const char *multidevs =3D qemu_opt_get(opts, "multidevs"); - Error *local_err =3D NULL; =20 if (!sec_model) { error_setg(errp, "security_model property not set"); @@ -1518,11 +1518,10 @@ static int local_parse_opts(QemuOpts *opts, FsDrive= rEntry *fse, Error **errp) fse->export_flags &=3D ~V9FS_FORBID_MULTIDEVS; fse->export_flags &=3D ~V9FS_REMAP_INODES; } else { - error_setg(&local_err, "invalid multidevs property '%s'", + error_setg(errp, "invalid multidevs property '%s'", multidevs); - error_append_hint(&local_err, "Valid options are: multidevs=3D" + error_append_hint(errp, "Valid options are: multidevs=3D" "[remap|forbid|warn]\n"); - error_propagate(errp, local_err); return -1; } } @@ -1532,9 +1531,8 @@ static int local_parse_opts(QemuOpts *opts, FsDriverE= ntry *fse, Error **errp) return -1; } =20 - if (fsdev_throttle_parse_opts(opts, &fse->fst, &local_err)) { - error_propagate_prepend(errp, local_err, - "invalid throttle configuration: "); + if (fsdev_throttle_parse_opts(opts, &fse->fst, errp)) { + error_prepend(errp, "invalid throttle configuration: "); return -1; } =20 diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 520177f40c..4200c3416b 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -3994,6 +3994,7 @@ void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr) int v9fs_device_realize_common(V9fsState *s, const V9fsTransport *t, Error **errp) { + ERRP_AUTO_PROPAGATE(); int i, len; struct stat stat; FsDriverEntry *fse; --=20 2.21.0 From nobody Thu Apr 25 07:13:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578685827; cv=none; d=zohomail.com; s=zohoarc; b=iB0od5nIhlrAZqV9xL037BJBhaZlehUM1dW3VWOqO4+87k3H4sKg6D4fXFg8o7zCTEk9wvFUbWwznvAmUdhi7kY1ql5Wl8w3emld2tHfw4mWhs9IMU/8DP99evolSGef0z/ipcgcfFJ9o/+k6v1zaI6gIwdnnEW5cdiPCOajIu0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578685827; 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=9FJjkWElo8ytX9IaLjy5/eoOWz7VXRFJZDCdrgTcI1w=; b=bRJR1nLw5BuSbTpq3FlcaM96zRP7T5MiNGso5q8XmUDLxeJiGSBRqjB92S3Bc02pNR0WcDMdvCJjwerSMMd9P4Ex3SadyZtrs41LlNLk4bwCddKyutMNy2OlIo5gS+lPDTlp82a8B45b/93ioOr248Srfx2+ByR05SqM4bQluos= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.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 1578685827685221.63462888923584; Fri, 10 Jan 2020 11:50:27 -0800 (PST) Received: from localhost ([::1]:51096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq0Ic-0003e1-AR for importer@patchew.org; Fri, 10 Jan 2020 14:50:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44502) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq0An-0001lu-ES for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iq0Al-0004rA-79 for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:21 -0500 Received: from relay.sw.ru ([185.231.240.75]:53952) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iq0Ak-0004hi-U1 for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:19 -0500 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iq0AW-0008Ob-Hl; Fri, 10 Jan 2020 22:42:04 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Subject: [PATCH v6 09/11] TPM: introduce ERRP_AUTO_PROPAGATE Date: Fri, 10 Jan 2020 22:41:56 +0300 Message-Id: <20200110194158.14190-10-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200110194158.14190-1-vsementsov@virtuozzo.com> References: <20200110194158.14190-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 , Vladimir Sementsov-Ogievskiy , Greg Kurz , Stefan Berger 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 &error_fatal (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 then 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_fatal, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate) This commit is generated by command sed -n '/^TPM$/,/^$/{s/^F: //p}' MAINTAINERS | \ xargs git ls-files | grep '\.[hc]$' | \ xargs spatch \ --sp-file scripts/coccinelle/auto-propagated-errp.cocci \ --macro-file scripts/cocci-macro-file.h \ --in-place --no-show-diff --max-width 80 Reported-by: Kevin Wolf Reported-by: Greg Kurz Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Stefan Berger --- hw/tpm/tpm_util.c | 7 +++---- tpm.c | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c index 62b091f0c0..b0657bbbf2 100644 --- a/hw/tpm/tpm_util.c +++ b/hw/tpm/tpm_util.c @@ -47,8 +47,8 @@ static void get_tpm(Object *obj, Visitor *v, const char *= name, void *opaque, static void set_tpm(Object *obj, Visitor *v, const char *name, void *opaqu= e, Error **errp) { + ERRP_AUTO_PROPAGATE(); DeviceState *dev =3D DEVICE(obj); - Error *local_err =3D NULL; Property *prop =3D opaque; TPMBackend *s, **be =3D qdev_get_prop_ptr(dev, prop); char *str; @@ -58,9 +58,8 @@ static void set_tpm(Object *obj, Visitor *v, const char *= name, void *opaque, 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/tpm.c b/tpm.c index 9c9e20bbb7..359ebb7f68 100644 --- a/tpm.c +++ b/tpm.c @@ -81,11 +81,11 @@ TPMBackend *qemu_find_tpm_be(const char *id) =20 static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp) { + ERRP_AUTO_PROPAGATE(); const char *value; const char *id; const TPMBackendClass *be; TPMBackend *drv; - Error *local_err =3D NULL; int i; =20 if (!QLIST_EMPTY(&tpm_backends)) { @@ -116,9 +116,8 @@ static int tpm_init_tpmdev(void *dummy, QemuOpts *opts,= Error **errp) } =20 /* validate backend specific opts */ - qemu_opts_validate(opts, be->opts, &local_err); - if (local_err) { - error_propagate(errp, local_err); + qemu_opts_validate(opts, be->opts, errp); + if (*errp) { return 1; } =20 --=20 2.21.0 From nobody Thu Apr 25 07:13:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578685614; cv=none; d=zohomail.com; s=zohoarc; b=Q2QkOeLy6xJ4zGSEPKXqYkYFVpiibR4kxCBvA4Qd2bIPBIVYE7P6gky2+e2s9AVWmFbOll1vxPYVukxGnbInaLw41s5FBlWSaT6Ti7Sfel6Ip4KYtaRK+L6NzWDb+B24K/xTe3sN/bLbZ2vKxYcif6JlQ9K2p3fuCRU1xusxntU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578685614; 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=TSW2lpLtMnZFi7NMKOPjSTusThTLJgSEeoCHgCjRsa8=; b=baqe1oJgtLZRMBvZVzQ2DuQY7UVhOUrcED1HELlrotvGtJMeUwP1S3pHZOXV8DSojcQ1bwX9pVBl69Wawot96pArVzfA/Zr4zdxx+gkK3v+e3XuJfh2mnO/QMoZ5wFyUt+7Mssc2yeHYBIEvZ8H/nGycDAoqHa1hCRDFS77Rszc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.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 1578685614739297.52058887544104; Fri, 10 Jan 2020 11:46:54 -0800 (PST) Received: from localhost ([::1]:51058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq0FB-0007WJ-8R for importer@patchew.org; Fri, 10 Jan 2020 14:46:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44325) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iq0Al-0001gr-Oz for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iq0Ad-0004bd-6L for qemu-devel@nongnu.org; Fri, 10 Jan 2020 14:42:15 -0500 Received: from relay.sw.ru ([185.231.240.75]:53926) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iq0Ac-0004Rh-Tq; Fri, 10 Jan 2020 14:42:11 -0500 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iq0AW-0008Ob-TK; Fri, 10 Jan 2020 22:42:05 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Subject: [PATCH v6 10/11] nbd: introduce ERRP_AUTO_PROPAGATE Date: Fri, 10 Jan 2020 22:41:57 +0300 Message-Id: <20200110194158.14190-11-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200110194158.14190-1-vsementsov@virtuozzo.com> References: <20200110194158.14190-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 , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Greg Kurz , Max Reitz 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 &error_fatal (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 then 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_fatal, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate) This commit is generated by command sed -n '/^Network Block Device (NBD)$/,/^$/{s/^F: //p}' \ MAINTAINERS | \ xargs git ls-files | grep '\.[hc]$' | \ xargs spatch \ --sp-file scripts/coccinelle/auto-propagated-errp.cocci \ --macro-file scripts/cocci-macro-file.h \ --in-place --no-show-diff --max-width 80 Reported-by: Kevin Wolf Reported-by: Greg Kurz Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- include/block/nbd.h | 1 + block/nbd.c | 49 +++++++++++++++++++++------------------------ nbd/client.c | 5 +++++ nbd/server.c | 5 +++++ 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 7f46932d80..4ab8d917ed 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -360,6 +360,7 @@ void nbd_server_start(SocketAddress *addr, const char *= tls_creds, static inline int nbd_read(QIOChannel *ioc, void *buffer, size_t size, const char *desc, Error **errp) { + ERRP_AUTO_PROPAGATE(); int ret =3D qio_channel_read_all(ioc, buffer, size, errp) < 0 ? -EIO := 0; =20 if (ret < 0) { diff --git a/block/nbd.c b/block/nbd.c index d085554f21..9701ccf887 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -990,10 +990,10 @@ static int nbd_co_receive_cmdread_reply(BDRVNBDState = *s, uint64_t handle, uint64_t offset, QEMUIOVector *qio= v, int *request_ret, Error **errp) { + ERRP_AUTO_PROPAGATE(); NBDReplyChunkIter iter; NBDReply reply; void *payload =3D NULL; - Error *local_err =3D NULL; =20 NBD_FOREACH_REPLY_CHUNK(s, iter, handle, s->info.structured_reply, qiov, &reply, &payload) @@ -1012,20 +1012,20 @@ static int nbd_co_receive_cmdread_reply(BDRVNBDStat= e *s, uint64_t handle, break; case NBD_REPLY_TYPE_OFFSET_HOLE: ret =3D nbd_parse_offset_hole_payload(s, &reply.structured, pa= yload, - offset, qiov, &local_err); + offset, qiov, errp); if (ret < 0) { nbd_channel_error(s, ret); - nbd_iter_channel_error(&iter, ret, &local_err); + nbd_iter_channel_error(&iter, ret, errp); } break; default: if (!nbd_reply_type_is_error(chunk->type)) { /* not allowed reply type */ nbd_channel_error(s, -EINVAL); - error_setg(&local_err, + error_setg(errp, "Unexpected reply type: %d (%s) for CMD_READ", chunk->type, nbd_reply_type_lookup(chunk->type)= ); - nbd_iter_channel_error(&iter, -EINVAL, &local_err); + nbd_iter_channel_error(&iter, -EINVAL, errp); } } =20 @@ -1043,10 +1043,10 @@ static int nbd_co_receive_blockstatus_reply(BDRVNBD= State *s, NBDExtent *extent, int *request_ret, Error **errp) { + ERRP_AUTO_PROPAGATE(); NBDReplyChunkIter iter; NBDReply reply; void *payload =3D NULL; - Error *local_err =3D NULL; bool received =3D false; =20 assert(!extent->length); @@ -1060,27 +1060,27 @@ static int nbd_co_receive_blockstatus_reply(BDRVNBD= State *s, case NBD_REPLY_TYPE_BLOCK_STATUS: if (received) { nbd_channel_error(s, -EINVAL); - error_setg(&local_err, "Several BLOCK_STATUS chunks in rep= ly"); - nbd_iter_channel_error(&iter, -EINVAL, &local_err); + error_setg(errp, "Several BLOCK_STATUS chunks in reply"); + nbd_iter_channel_error(&iter, -EINVAL, errp); } received =3D true; =20 ret =3D nbd_parse_blockstatus_payload(s, &reply.structured, payload, length, extent, - &local_err); + errp); if (ret < 0) { nbd_channel_error(s, ret); - nbd_iter_channel_error(&iter, ret, &local_err); + nbd_iter_channel_error(&iter, ret, errp); } break; default: if (!nbd_reply_type_is_error(chunk->type)) { nbd_channel_error(s, -EINVAL); - error_setg(&local_err, + error_setg(errp, "Unexpected reply type: %d (%s) " "for CMD_BLOCK_STATUS", chunk->type, nbd_reply_type_lookup(chunk->type)= ); - nbd_iter_channel_error(&iter, -EINVAL, &local_err); + nbd_iter_channel_error(&iter, -EINVAL, errp); } } =20 @@ -1089,8 +1089,8 @@ static int nbd_co_receive_blockstatus_reply(BDRVNBDSt= ate *s, } =20 if (!extent->length && !iter.request_ret) { - error_setg(&local_err, "Server did not reply with any status exten= ts"); - nbd_iter_channel_error(&iter, -EIO, &local_err); + error_setg(errp, "Server did not reply with any status extents"); + nbd_iter_channel_error(&iter, -EIO, errp); } =20 error_propagate(errp, iter.err); @@ -1385,16 +1385,15 @@ static void nbd_client_close(BlockDriverState *bs) static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr, Error **errp) { + ERRP_AUTO_PROPAGATE(); QIOChannelSocket *sioc; - Error *local_err =3D NULL; =20 sioc =3D qio_channel_socket_new(); qio_channel_set_name(QIO_CHANNEL(sioc), "nbd-client"); =20 - qio_channel_socket_connect_sync(sioc, saddr, &local_err); - if (local_err) { + qio_channel_socket_connect_sync(sioc, saddr, errp); + if (*errp) { object_unref(OBJECT(sioc)); - error_propagate(errp, local_err); return NULL; } =20 @@ -1698,10 +1697,10 @@ static bool nbd_process_legacy_socket_options(QDict= *output_options, static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options, Error **errp) { + ERRP_AUTO_PROPAGATE(); SocketAddress *saddr =3D NULL; QDict *addr =3D NULL; Visitor *iv =3D NULL; - Error *local_err =3D NULL; =20 qdict_extract_subqdict(options, &addr, "server."); if (!qdict_size(addr)) { @@ -1714,9 +1713,8 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDi= ct *options, goto done; } =20 - visit_type_SocketAddress(iv, NULL, &saddr, &local_err); - if (local_err) { - error_propagate(errp, local_err); + visit_type_SocketAddress(iv, NULL, &saddr, errp); + if (*errp) { goto done; } =20 @@ -1809,15 +1807,14 @@ static QemuOptsList nbd_runtime_opts =3D { static int nbd_process_options(BlockDriverState *bs, QDict *options, Error **errp) { + ERRP_AUTO_PROPAGATE(); BDRVNBDState *s =3D bs->opaque; QemuOpts *opts; - Error *local_err =3D NULL; int ret =3D -EINVAL; =20 opts =3D qemu_opts_create(&nbd_runtime_opts, NULL, 0, &error_abort); - qemu_opts_absorb_qdict(opts, options, &local_err); - if (local_err) { - error_propagate(errp, local_err); + qemu_opts_absorb_qdict(opts, options, errp); + if (*errp) { goto error; } =20 diff --git a/nbd/client.c b/nbd/client.c index ba173108ba..e258ef3f7e 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -68,6 +68,7 @@ static int nbd_send_option_request(QIOChannel *ioc, uint3= 2_t opt, uint32_t len, const char *data, Error **errp) { + ERRP_AUTO_PROPAGATE(); NBDOption req; QEMU_BUILD_BUG_ON(sizeof(req) !=3D 16); =20 @@ -153,6 +154,7 @@ static int nbd_receive_option_reply(QIOChannel *ioc, ui= nt32_t opt, static int nbd_handle_reply_err(QIOChannel *ioc, NBDOptionReply *reply, bool strict, Error **errp) { + ERRP_AUTO_PROPAGATE(); g_autofree char *msg =3D NULL; =20 if (!(reply->type & (1 << 31))) { @@ -337,6 +339,7 @@ static int nbd_receive_list(QIOChannel *ioc, char **nam= e, char **description, static int nbd_opt_info_or_go(QIOChannel *ioc, uint32_t opt, NBDExportInfo *info, Error **errp) { + ERRP_AUTO_PROPAGATE(); NBDOptionReply reply; uint32_t len =3D strlen(info->name); uint16_t type; @@ -882,6 +885,7 @@ static int nbd_start_negotiate(AioContext *aio_context,= QIOChannel *ioc, bool structured_reply, bool *zeroes, Error **errp) { + ERRP_AUTO_PROPAGATE(); uint64_t magic; =20 trace_nbd_start_negotiate(tlscreds, hostname ? hostname : ""); @@ -1017,6 +1021,7 @@ int nbd_receive_negotiate(AioContext *aio_context, QI= OChannel *ioc, const char *hostname, QIOChannel **outioc, NBDExportInfo *info, Error **errp) { + ERRP_AUTO_PROPAGATE(); int result; bool zeroes; bool base_allocation =3D info->base_allocation; diff --git a/nbd/server.c b/nbd/server.c index 24ebc1a805..19de61a23e 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -211,6 +211,7 @@ static int GCC_FMT_ATTR(4, 0) nbd_negotiate_send_rep_verr(NBDClient *client, uint32_t type, Error **errp, const char *fmt, va_list va) { + ERRP_AUTO_PROPAGATE(); g_autofree char *msg =3D NULL; int ret; size_t len; @@ -369,6 +370,7 @@ static int nbd_opt_read_name(NBDClient *client, char **= name, uint32_t *length, static int nbd_negotiate_send_rep_list(NBDClient *client, NBDExport *exp, Error **errp) { + ERRP_AUTO_PROPAGATE(); size_t name_len, desc_len; uint32_t len; const char *name =3D exp->name ? exp->name : ""; @@ -432,6 +434,7 @@ static void nbd_check_meta_export(NBDClient *client) static int nbd_negotiate_handle_export_name(NBDClient *client, bool no_zer= oes, Error **errp) { + ERRP_AUTO_PROPAGATE(); g_autofree char *name =3D NULL; char buf[NBD_REPLY_EXPORT_NAME_SIZE] =3D ""; size_t len; @@ -1272,6 +1275,7 @@ static int nbd_negotiate_options(NBDClient *client, E= rror **errp) */ static coroutine_fn int nbd_negotiate(NBDClient *client, Error **errp) { + ERRP_AUTO_PROPAGATE(); char buf[NBD_OLDSTYLE_NEGOTIATE_SIZE] =3D ""; int ret; =20 @@ -1646,6 +1650,7 @@ void nbd_export_close(NBDExport *exp) =20 void nbd_export_remove(NBDExport *exp, NbdServerRemoveMode mode, Error **e= rrp) { + ERRP_AUTO_PROPAGATE(); if (mode =3D=3D NBD_SERVER_REMOVE_MODE_HARD || QTAILQ_EMPTY(&exp->clie= nts)) { nbd_export_close(exp); return; --=20 2.21.0 From nobody Thu Apr 25 07:13:13 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1578685423; cv=none; d=zohomail.com; s=zohoarc; b=TgnYgGYjTAa49RlO+6cpJ/eI94xnvfu/yAVhNVJUt+AgrDAmbbZXLSUcqIGVGeTnRRY2uhD7411Gvd7R36HfSjeyuIDOWdgESxmxKVYD499HFHroDIwPDSq0pbEymE/jD6K6+dgJmPurVY1x26fytvxwK2m7HlB3W1JpjgWkHZE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578685423; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=y5pYwbOmRdeGzo8oSPSQBLcINHGdqeZcWVJjkTbCJGw=; b=ly6sADI1A8j+b/mnI1DNPflWEcUoA7LR/fZJSwzqHHIvHrZ7Qff+BbHO/FpU0BzWVne1dSJM70fm29iosbVFvu+VvqEzKQqP0qACQq+oxx2pzwC654xEHV71UeXNijnVQmIJKC1vlNm66uhDduAOofTHbkjeV5zn+Zwuw3hjfAA= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1578685423159204.25472031698393; Fri, 10 Jan 2020 11:43:43 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iq0BO-0003sY-TB; Fri, 10 Jan 2020 19:42:58 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iq0BN-0003sF-O1 for xen-devel@lists.xenproject.org; Fri, 10 Jan 2020 19:42:57 +0000 Received: from relay.sw.ru (unknown [185.231.240.75]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 58c9e574-33e1-11ea-a2eb-bc764e2007e4; Fri, 10 Jan 2020 19:42:34 +0000 (UTC) Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iq0AX-0008Ob-5N; Fri, 10 Jan 2020 22:42:05 +0300 X-Inumbo-ID: 58c9e574-33e1-11ea-a2eb-bc764e2007e4 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 10 Jan 2020 22:41:58 +0300 Message-Id: <20200110194158.14190-12-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200110194158.14190-1-vsementsov@virtuozzo.com> References: <20200110194158.14190-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 11/11] xen: introduce ERRP_AUTO_PROPAGATE X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paul Durrant , Greg Kurz , Max Reitz , Stefano Stabellini , Stefan Hajnoczi , Anthony Perard , xen-devel@lists.xenproject.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-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 =3D=3D &error_fatal (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 then 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_fatal, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate) This commit is generated by command sed -n '/^X86 Xen CPUs$/,/^$/{s/^F: //p}' MAINTAINERS | \ xargs git ls-files | grep '\.[hc]$' | \ xargs spatch \ --sp-file scripts/coccinelle/auto-propagated-errp.cocci \ --macro-file scripts/cocci-macro-file.h \ --in-place --no-show-diff --max-width 80 Reported-by: Kevin Wolf Reported-by: Greg Kurz Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Paul Durrant --- hw/block/dataplane/xen-block.c | 17 ++--- hw/block/xen-block.c | 125 ++++++++++++++------------------- hw/pci-host/xen_igd_pt.c | 7 +- hw/xen/xen-backend.c | 7 +- hw/xen/xen-bus.c | 100 ++++++++++++-------------- hw/xen/xen-host-pci-device.c | 27 ++++--- hw/xen/xen_pt.c | 25 +++---- hw/xen/xen_pt_config_init.c | 20 +++--- 8 files changed, 142 insertions(+), 186 deletions(-) diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index 3b9caeb2fa..c38e3c3d85 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -727,8 +727,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *datap= lane, unsigned int protocol, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenDevice *xendev =3D dataplane->xendev; - Error *local_err =3D NULL; unsigned int ring_size; unsigned int i; =20 @@ -764,9 +764,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *datap= lane, } =20 xen_device_set_max_grant_refs(xendev, dataplane->nr_ring_ref, - &local_err); - if (local_err) { - error_propagate(errp, local_err); + errp); + if (*errp) { goto stop; } =20 @@ -774,9 +773,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *datap= lane, dataplane->ring_ref, dataplane->nr_ring_ref, PROT_READ | PROT_WRITE, - &local_err); - if (local_err) { - error_propagate(errp, local_err); + errp); + if (*errp) { goto stop; } =20 @@ -809,9 +807,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *datap= lane, dataplane->event_channel =3D xen_device_bind_event_channel(xendev, dataplane->ctx, event_channe= l, xen_block_dataplane_event, dataplane, - &local_err); - if (local_err) { - error_propagate(errp, local_err); + errp); + if (*errp) { goto stop; } =20 diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index 879fc310a4..70428f5a79 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -194,6 +194,7 @@ static const BlockDevOps xen_block_dev_ops =3D { =20 static void xen_block_realize(XenDevice *xendev, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenBlockDevice *blockdev =3D XEN_BLOCK_DEVICE(xendev); XenBlockDeviceClass *blockdev_class =3D XEN_BLOCK_DEVICE_GET_CLASS(xendev); @@ -201,7 +202,6 @@ static void xen_block_realize(XenDevice *xendev, Error = **errp) XenBlockVdev *vdev =3D &blockdev->props.vdev; BlockConf *conf =3D &blockdev->props.conf; BlockBackend *blk =3D conf->blk; - Error *local_err =3D NULL; =20 if (vdev->type =3D=3D XEN_BLOCK_VDEV_TYPE_INVALID) { error_setg(errp, "vdev property not set"); @@ -211,9 +211,8 @@ static void xen_block_realize(XenDevice *xendev, Error = **errp) trace_xen_block_realize(type, vdev->disk, vdev->partition); =20 if (blockdev_class->realize) { - blockdev_class->realize(blockdev, &local_err); - if (local_err) { - error_propagate(errp, local_err); + blockdev_class->realize(blockdev, errp); + if (*errp) { return; } } @@ -283,8 +282,8 @@ static void xen_block_frontend_changed(XenDevice *xende= v, enum xenbus_state frontend_state, Error **errp) { + ERRP_AUTO_PROPAGATE(); enum xenbus_state backend_state =3D xen_device_backend_get_state(xende= v); - Error *local_err =3D NULL; =20 switch (frontend_state) { case XenbusStateInitialised: @@ -293,15 +292,13 @@ static void xen_block_frontend_changed(XenDevice *xen= dev, break; } =20 - xen_block_disconnect(xendev, &local_err); - if (local_err) { - error_propagate(errp, local_err); + xen_block_disconnect(xendev, errp); + if (*errp) { break; } =20 - xen_block_connect(xendev, &local_err); - if (local_err) { - error_propagate(errp, local_err); + xen_block_connect(xendev, errp); + if (*errp) { break; } =20 @@ -314,9 +311,8 @@ static void xen_block_frontend_changed(XenDevice *xende= v, =20 case XenbusStateClosed: case XenbusStateUnknown: - xen_block_disconnect(xendev, &local_err); - if (local_err) { - error_propagate(errp, local_err); + xen_block_disconnect(xendev, errp); + if (*errp) { break; } =20 @@ -403,10 +399,10 @@ static int vbd_name_to_disk(const char *name, const c= har **endp, static void xen_block_set_vdev(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { + ERRP_AUTO_PROPAGATE(); DeviceState *dev =3D DEVICE(obj); Property *prop =3D opaque; XenBlockVdev *vdev =3D qdev_get_prop_ptr(dev, prop); - Error *local_err =3D NULL; char *str, *p; const char *end; =20 @@ -415,9 +411,8 @@ static void xen_block_set_vdev(Object *obj, Visitor *v,= const 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 @@ -671,9 +666,9 @@ static void xen_block_blockdev_del(const char *node_nam= e, Error **errp) static char *xen_block_blockdev_add(const char *id, QDict *qdict, Error **errp) { + ERRP_AUTO_PROPAGATE(); const char *driver =3D qdict_get_try_str(qdict, "driver"); BlockdevOptions *options =3D NULL; - Error *local_err =3D NULL; char *node_name; Visitor *v; =20 @@ -688,18 +683,16 @@ static char *xen_block_blockdev_add(const char *id, Q= Dict *qdict, trace_xen_block_blockdev_add(node_name); =20 v =3D qobject_input_visitor_new(QOBJECT(qdict)); - visit_type_BlockdevOptions(v, NULL, &options, &local_err); + visit_type_BlockdevOptions(v, NULL, &options, errp); visit_free(v); =20 - if (local_err) { - error_propagate(errp, local_err); + if (*errp) { goto fail; } =20 - qmp_blockdev_add(options, &local_err); + qmp_blockdev_add(options, errp); =20 - if (local_err) { - error_propagate(errp, local_err); + if (*errp) { goto fail; } =20 @@ -718,14 +711,12 @@ fail: =20 static void xen_block_drive_destroy(XenBlockDrive *drive, Error **errp) { + ERRP_AUTO_PROPAGATE(); char *node_name =3D drive->node_name; =20 if (node_name) { - Error *local_err =3D NULL; - - xen_block_blockdev_del(node_name, &local_err); - if (local_err) { - error_propagate(errp, local_err); + xen_block_blockdev_del(node_name, errp); + if (*errp) { return; } g_free(node_name); @@ -739,6 +730,7 @@ static XenBlockDrive *xen_block_drive_create(const char= *id, const char *device_type, QDict *opts, Error **errp) { + ERRP_AUTO_PROPAGATE(); const char *params =3D qdict_get_try_str(opts, "params"); const char *mode =3D qdict_get_try_str(opts, "mode"); const char *direct_io_safe =3D qdict_get_try_str(opts, "direct-io-safe= "); @@ -746,7 +738,6 @@ static XenBlockDrive *xen_block_drive_create(const char= *id, char *driver =3D NULL; char *filename =3D NULL; XenBlockDrive *drive =3D NULL; - Error *local_err =3D NULL; QDict *file_layer; QDict *driver_layer; =20 @@ -825,13 +816,12 @@ static XenBlockDrive *xen_block_drive_create(const ch= ar *id, =20 g_assert(!drive->node_name); drive->node_name =3D xen_block_blockdev_add(drive->id, driver_layer, - &local_err); + errp); =20 qobject_unref(driver_layer); =20 done: - if (local_err) { - error_propagate(errp, local_err); + if (*errp) { xen_block_drive_destroy(drive, NULL); return NULL; } @@ -856,15 +846,13 @@ static void xen_block_iothread_destroy(XenBlockIOThre= ad *iothread, static XenBlockIOThread *xen_block_iothread_create(const char *id, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenBlockIOThread *iothread =3D g_new(XenBlockIOThread, 1); - Error *local_err =3D NULL; =20 iothread->id =3D g_strdup(id); =20 - qmp_object_add(TYPE_IOTHREAD, id, false, NULL, &local_err); - if (local_err) { - error_propagate(errp, local_err); - + qmp_object_add(TYPE_IOTHREAD, id, false, NULL, errp); + if (*errp) { g_free(iothread->id); g_free(iothread); return NULL; @@ -876,6 +864,7 @@ static XenBlockIOThread *xen_block_iothread_create(cons= t char *id, static void xen_block_device_create(XenBackendInstance *backend, QDict *opts, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenBus *xenbus =3D xen_backend_get_bus(backend); const char *name =3D xen_backend_get_name(backend); unsigned long number; @@ -883,7 +872,6 @@ static void xen_block_device_create(XenBackendInstance = *backend, XenBlockDrive *drive =3D NULL; XenBlockIOThread *iothread =3D NULL; XenDevice *xendev =3D NULL; - Error *local_err =3D NULL; const char *type; XenBlockDevice *blockdev; =20 @@ -915,52 +903,48 @@ static void xen_block_device_create(XenBackendInstanc= e *backend, goto fail; } =20 - drive =3D xen_block_drive_create(vdev, device_type, opts, &local_err); + drive =3D xen_block_drive_create(vdev, device_type, opts, errp); if (!drive) { - error_propagate_prepend(errp, local_err, "failed to create drive: = "); + error_prepend(errp, "failed to create drive: "); goto fail; } =20 - iothread =3D xen_block_iothread_create(vdev, &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, - "failed to create iothread: "); + iothread =3D xen_block_iothread_create(vdev, errp); + if (*errp) { + error_prepend(errp, "failed to create iothread: "); goto fail; } =20 xendev =3D XEN_DEVICE(qdev_create(BUS(xenbus), type)); blockdev =3D XEN_BLOCK_DEVICE(xendev); =20 - object_property_set_str(OBJECT(xendev), vdev, "vdev", &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, "failed to set 'vdev': "); + object_property_set_str(OBJECT(xendev), vdev, "vdev", errp); + if (*errp) { + error_prepend(errp, "failed to set 'vdev': "); goto fail; } =20 object_property_set_str(OBJECT(xendev), xen_block_drive_get_node_name(drive), "drive", - &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, "failed to set 'drive': "= ); + errp); + if (*errp) { + error_prepend(errp, "failed to set 'drive': "); goto fail; } =20 object_property_set_str(OBJECT(xendev), iothread->id, "iothread", - &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, - "failed to set 'iothread': "); + errp); + if (*errp) { + error_prepend(errp, "failed to set 'iothread': "); goto fail; } =20 blockdev->iothread =3D iothread; blockdev->drive =3D drive; =20 - object_property_set_bool(OBJECT(xendev), true, "realized", &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, - "realization of device %s failed: ", - type); + object_property_set_bool(OBJECT(xendev), true, "realized", errp); + if (*errp) { + error_prepend(errp, "realization of device %s failed: ", type); goto fail; } =20 @@ -984,6 +968,7 @@ fail: static void xen_block_device_destroy(XenBackendInstance *backend, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenDevice *xendev =3D xen_backend_get_device(backend); XenBlockDevice *blockdev =3D XEN_BLOCK_DEVICE(xendev); XenBlockVdev *vdev =3D &blockdev->props.vdev; @@ -995,23 +980,17 @@ static void xen_block_device_destroy(XenBackendInstan= ce *backend, object_unparent(OBJECT(xendev)); =20 if (iothread) { - Error *local_err =3D NULL; - - xen_block_iothread_destroy(iothread, &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, - "failed to destroy iothread: "); + xen_block_iothread_destroy(iothread, errp); + if (*errp) { + error_prepend(errp, "failed to destroy iothread: "); return; } } =20 if (drive) { - Error *local_err =3D NULL; - - xen_block_drive_destroy(drive, &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, - "failed to destroy drive: "); + xen_block_drive_destroy(drive, errp); + if (*errp) { + error_prepend(errp, "failed to destroy drive: "); } } } diff --git a/hw/pci-host/xen_igd_pt.c b/hw/pci-host/xen_igd_pt.c index efcc9347ff..29ade9ca25 100644 --- a/hw/pci-host/xen_igd_pt.c +++ b/hw/pci-host/xen_igd_pt.c @@ -79,17 +79,16 @@ static void host_pci_config_read(int pos, int len, uint= 32_t *val, Error **errp) =20 static void igd_pt_i440fx_realize(PCIDevice *pci_dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); uint32_t val =3D 0; size_t i; int pos, len; - Error *local_err =3D NULL; =20 for (i =3D 0; i < ARRAY_SIZE(igd_host_bridge_infos); i++) { pos =3D igd_host_bridge_infos[i].offset; len =3D igd_host_bridge_infos[i].len; - host_pci_config_read(pos, len, &val, &local_err); - if (local_err) { - error_propagate(errp, local_err); + host_pci_config_read(pos, len, &val, errp); + if (*errp) { return; } pci_default_write_config(pci_dev, pos, val, len); diff --git a/hw/xen/xen-backend.c b/hw/xen/xen-backend.c index da065f81b7..1cc0694053 100644 --- a/hw/xen/xen-backend.c +++ b/hw/xen/xen-backend.c @@ -98,9 +98,9 @@ static void xen_backend_list_remove(XenBackendInstance *b= ackend) void xen_backend_device_create(XenBus *xenbus, const char *type, const char *name, QDict *opts, Error **errp) { + ERRP_AUTO_PROPAGATE(); const XenBackendImpl *impl =3D xen_backend_table_lookup(type); XenBackendInstance *backend; - Error *local_error =3D NULL; =20 if (!impl) { return; @@ -110,9 +110,8 @@ void xen_backend_device_create(XenBus *xenbus, const ch= ar *type, backend->xenbus =3D xenbus; backend->name =3D g_strdup(name); =20 - impl->create(backend, opts, &local_error); - if (local_error) { - error_propagate(errp, local_error); + impl->create(backend, opts, errp); + if (*errp) { g_free(backend->name); g_free(backend); return; diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index c2ad22a42d..270ee31aa5 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -53,9 +53,9 @@ static char *xen_device_get_frontend_path(XenDevice *xend= ev) =20 static void xen_device_unplug(XenDevice *xendev, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenBus *xenbus =3D XEN_BUS(qdev_get_parent_bus(DEVICE(xendev))); const char *type =3D object_get_typename(OBJECT(xendev)); - Error *local_err =3D NULL; xs_transaction_t tid; =20 trace_xen_device_unplug(type, xendev->name); @@ -69,14 +69,14 @@ again: } =20 xs_node_printf(xenbus->xsh, tid, xendev->backend_path, "online", - &local_err, "%u", 0); - if (local_err) { + errp, "%u", 0); + if (*errp) { goto abort; } =20 xs_node_printf(xenbus->xsh, tid, xendev->backend_path, "state", - &local_err, "%u", XenbusStateClosing); - if (local_err) { + errp, "%u", XenbusStateClosing); + if (*errp) { goto abort; } =20 @@ -96,7 +96,6 @@ abort: * from ending the transaction. */ xs_transaction_end(xenbus->xsh, tid, true); - error_propagate(errp, local_err); } =20 static void xen_bus_print_dev(Monitor *mon, DeviceState *dev, int indent) @@ -205,15 +204,13 @@ static XenWatch *watch_list_add(XenWatchList *watch_l= ist, const char *node, const char *key, XenWatchHandler handler, void *opaque, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenWatch *watch =3D new_watch(node, key, handler, opaque); - Error *local_err =3D NULL; =20 notifier_list_add(&watch_list->notifiers, &watch->notifier); =20 - xs_node_watch(watch_list->xsh, node, key, watch->token, &local_err); - if (local_err) { - error_propagate(errp, local_err); - + xs_node_watch(watch_list->xsh, node, key, watch->token, errp); + if (*errp) { notifier_remove(&watch->notifier); free_watch(watch); =20 @@ -255,11 +252,11 @@ static void xen_bus_backend_create(XenBus *xenbus, co= nst char *type, const char *name, char *path, Error **errp) { + ERRP_AUTO_PROPAGATE(); xs_transaction_t tid; char **key; QDict *opts; unsigned int i, n; - Error *local_err =3D NULL; =20 trace_xen_bus_backend_create(type, path); =20 @@ -314,13 +311,11 @@ again: return; } =20 - xen_backend_device_create(xenbus, type, name, opts, &local_err); + xen_backend_device_create(xenbus, type, name, opts, errp); qobject_unref(opts); =20 - if (local_err) { - error_propagate_prepend(errp, local_err, - "failed to create '%s' device '%s': ", - type, name); + if (*errp) { + error_prepend(errp, "failed to create '%s' device '%s': ", type, n= ame); } } =20 @@ -451,9 +446,9 @@ static void xen_bus_unrealize(BusState *bus, Error **er= rp) =20 static void xen_bus_realize(BusState *bus, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenBus *xenbus =3D XEN_BUS(bus); unsigned int domid; - Error *local_err =3D NULL; =20 trace_xen_bus_realize(); =20 @@ -476,10 +471,10 @@ static void xen_bus_realize(BusState *bus, Error **er= rp) =20 xenbus->backend_watch =3D xen_bus_add_watch(xenbus, "", /* domain root node */ - "backend", xen_bus_backend_changed, &local_err); - if (local_err) { + "backend", xen_bus_backend_changed, errp); + if (*errp) { /* This need not be treated as a hard error so don't propagate */ - error_reportf_err(local_err, + error_reportf_err(*errp, "failed to set up enumeration watch: "); } =20 @@ -692,9 +687,9 @@ static void xen_device_remove_watch(XenDevice *xendev, = XenWatch *watch, =20 static void xen_device_backend_create(XenDevice *xendev, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenBus *xenbus =3D XEN_BUS(qdev_get_parent_bus(DEVICE(xendev))); struct xs_permissions perms[2]; - Error *local_err =3D NULL; =20 xendev->backend_path =3D xen_device_get_backend_path(xendev); =20 @@ -706,30 +701,27 @@ static void xen_device_backend_create(XenDevice *xend= ev, Error **errp) g_assert(xenbus->xsh); =20 xs_node_create(xenbus->xsh, XBT_NULL, xendev->backend_path, perms, - ARRAY_SIZE(perms), &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, - "failed to create backend: "); + ARRAY_SIZE(perms), errp); + if (*errp) { + error_prepend(errp, "failed to create backend: "); return; } =20 xendev->backend_state_watch =3D xen_device_add_watch(xendev, xendev->backend_path, "state", xen_device_backend_changed, - &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, - "failed to watch backend state: "); + errp); + if (*errp) { + error_prepend(errp, "failed to watch backend state: "); return; } =20 xendev->backend_online_watch =3D xen_device_add_watch(xendev, xendev->backend_path, "online", xen_device_backend_changed, - &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, - "failed to watch backend online: "); + errp); + if (*errp) { + error_prepend(errp, "failed to watch backend online: "); return; } } @@ -866,9 +858,9 @@ static bool xen_device_frontend_exists(XenDevice *xende= v) =20 static void xen_device_frontend_create(XenDevice *xendev, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenBus *xenbus =3D XEN_BUS(qdev_get_parent_bus(DEVICE(xendev))); struct xs_permissions perms[2]; - Error *local_err =3D NULL; =20 xendev->frontend_path =3D xen_device_get_frontend_path(xendev); =20 @@ -885,20 +877,18 @@ static void xen_device_frontend_create(XenDevice *xen= dev, Error **errp) g_assert(xenbus->xsh); =20 xs_node_create(xenbus->xsh, XBT_NULL, xendev->frontend_path, perms, - ARRAY_SIZE(perms), &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, - "failed to create frontend: "); + ARRAY_SIZE(perms), errp); + if (*errp) { + error_prepend(errp, "failed to create frontend: "); return; } } =20 xendev->frontend_state_watch =3D xen_device_add_watch(xendev, xendev->frontend_path, "state", - xen_device_frontend_changed, &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, - "failed to watch frontend state: "); + xen_device_frontend_changed, errp); + if (*errp) { + error_prepend(errp, "failed to watch frontend state: "); } } =20 @@ -1228,11 +1218,11 @@ static void xen_device_exit(Notifier *n, void *data) =20 static void xen_device_realize(DeviceState *dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenDevice *xendev =3D XEN_DEVICE(dev); XenDeviceClass *xendev_class =3D XEN_DEVICE_GET_CLASS(xendev); XenBus *xenbus =3D XEN_BUS(qdev_get_parent_bus(DEVICE(xendev))); const char *type =3D object_get_typename(OBJECT(xendev)); - Error *local_err =3D NULL; =20 if (xendev->frontend_id =3D=3D DOMID_INVALID) { xendev->frontend_id =3D xen_domid; @@ -1248,10 +1238,9 @@ static void xen_device_realize(DeviceState *dev, Err= or **errp) goto unrealize; } =20 - xendev->name =3D xendev_class->get_name(xendev, &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, - "failed to get device name: "); + xendev->name =3D xendev_class->get_name(xendev, errp); + if (*errp) { + error_prepend(errp, "failed to get device name: "); goto unrealize; } =20 @@ -1274,22 +1263,19 @@ static void xen_device_realize(DeviceState *dev, Er= ror **errp) xendev->feature_grant_copy =3D (xengnttab_grant_copy(xendev->xgth, 0, NULL) =3D=3D 0); =20 - xen_device_backend_create(xendev, &local_err); - if (local_err) { - error_propagate(errp, local_err); + xen_device_backend_create(xendev, errp); + if (*errp) { goto unrealize; } =20 - xen_device_frontend_create(xendev, &local_err); - if (local_err) { - error_propagate(errp, local_err); + xen_device_frontend_create(xendev, errp); + if (*errp) { goto unrealize; } =20 if (xendev_class->realize) { - xendev_class->realize(xendev, &local_err); - if (local_err) { - error_propagate(errp, local_err); + xendev_class->realize(xendev, errp); + if (*errp) { goto unrealize; } } diff --git a/hw/xen/xen-host-pci-device.c b/hw/xen/xen-host-pci-device.c index 1b44dcafaf..02379c341c 100644 --- a/hw/xen/xen-host-pci-device.c +++ b/hw/xen/xen-host-pci-device.c @@ -333,8 +333,8 @@ void xen_host_pci_device_get(XenHostPCIDevice *d, uint1= 6_t domain, uint8_t bus, uint8_t dev, uint8_t func, Error **errp) { + ERRP_AUTO_PROPAGATE(); unsigned int v; - Error *err =3D NULL; =20 d->config_fd =3D -1; d->domain =3D domain; @@ -342,36 +342,36 @@ void xen_host_pci_device_get(XenHostPCIDevice *d, uin= t16_t domain, d->dev =3D dev; d->func =3D func; =20 - xen_host_pci_config_open(d, &err); - if (err) { + xen_host_pci_config_open(d, errp); + if (*errp) { goto error; } =20 - xen_host_pci_get_resource(d, &err); - if (err) { + xen_host_pci_get_resource(d, errp); + if (*errp) { goto error; } =20 - xen_host_pci_get_hex_value(d, "vendor", &v, &err); - if (err) { + xen_host_pci_get_hex_value(d, "vendor", &v, errp); + if (*errp) { goto error; } d->vendor_id =3D v; =20 - xen_host_pci_get_hex_value(d, "device", &v, &err); - if (err) { + xen_host_pci_get_hex_value(d, "device", &v, errp); + if (*errp) { goto error; } d->device_id =3D v; =20 - xen_host_pci_get_dec_value(d, "irq", &v, &err); - if (err) { + xen_host_pci_get_dec_value(d, "irq", &v, errp); + if (*errp) { goto error; } d->irq =3D v; =20 - xen_host_pci_get_hex_value(d, "class", &v, &err); - if (err) { + xen_host_pci_get_hex_value(d, "class", &v, errp); + if (*errp) { goto error; } d->class_code =3D v; @@ -381,7 +381,6 @@ void xen_host_pci_device_get(XenHostPCIDevice *d, uint1= 6_t domain, return; =20 error: - error_propagate(errp, err); =20 if (d->config_fd >=3D 0) { close(d->config_fd); diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index 9e767d4244..33b68dfcb8 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -767,12 +767,12 @@ static void xen_pt_destroy(PCIDevice *d) { =20 static void xen_pt_realize(PCIDevice *d, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenPCIPassthroughState *s =3D XEN_PT_DEVICE(d); int i, rc =3D 0; uint8_t machine_irq =3D 0, scratch; uint16_t cmd =3D 0; int pirq =3D XEN_PT_UNASSIGNED_PIRQ; - Error *err =3D NULL; =20 /* register real device */ XEN_PT_LOG(d, "Assigning real physical device %02x:%02x.%d" @@ -783,10 +783,9 @@ static void xen_pt_realize(PCIDevice *d, Error **errp) xen_host_pci_device_get(&s->real_device, s->hostaddr.domain, s->hostaddr.bus, s->hostaddr.slot, s->hostaddr.function, - &err); - if (err) { - error_append_hint(&err, "Failed to \"open\" the real pci device"); - error_propagate(errp, err); + errp); + if (*errp) { + error_append_hint(errp, "Failed to \"open\" the real pci device"); return; } =20 @@ -813,11 +812,10 @@ static void xen_pt_realize(PCIDevice *d, Error **errp) return; } =20 - xen_pt_setup_vga(s, &s->real_device, &err); - if (err) { - error_append_hint(&err, "Setup VGA BIOS of passthrough" - " GFX failed"); - error_propagate(errp, err); + xen_pt_setup_vga(s, &s->real_device, errp); + if (*errp) { + error_append_hint(errp, "Setup VGA BIOS of passthrough" + " GFX failed"); xen_host_pci_device_put(&s->real_device); return; } @@ -830,10 +828,9 @@ static void xen_pt_realize(PCIDevice *d, Error **errp) xen_pt_register_regions(s, &cmd); =20 /* reinitialize each config register to be emulated */ - xen_pt_config_init(s, &err); - if (err) { - error_append_hint(&err, "PCI Config space initialisation failed"); - error_propagate(errp, err); + xen_pt_config_init(s, errp); + if (*errp) { + error_append_hint(errp, "PCI Config space initialisation failed"); rc =3D -1; goto err_out; } diff --git a/hw/xen/xen_pt_config_init.c b/hw/xen/xen_pt_config_init.c index 31ec5add1d..af3fbd1bfb 100644 --- a/hw/xen/xen_pt_config_init.c +++ b/hw/xen/xen_pt_config_init.c @@ -2008,8 +2008,8 @@ static void xen_pt_config_reg_init(XenPCIPassthroughS= tate *s, =20 void xen_pt_config_init(XenPCIPassthroughState *s, Error **errp) { + ERRP_AUTO_PROPAGATE(); int i, rc; - Error *err =3D NULL; =20 QLIST_INIT(&s->reg_grps); =20 @@ -2052,10 +2052,9 @@ void xen_pt_config_init(XenPCIPassthroughState *s, E= rror **errp) reg_grp_offset, ®_grp_entry->size); if (rc < 0) { - error_setg(&err, "Failed to initialize %d/%zu, type =3D 0x= %x," + error_setg(errp, "Failed to initialize %d/%zu, type =3D 0x= %x," " rc: %d", i, ARRAY_SIZE(xen_pt_emu_reg_grps), xen_pt_emu_reg_grps[i].grp_type, rc); - error_propagate(errp, err); xen_pt_config_delete(s); return; } @@ -2068,13 +2067,14 @@ void xen_pt_config_init(XenPCIPassthroughState *s, = Error **errp) =20 /* initialize capability register */ for (j =3D 0; regs->size !=3D 0; j++, regs++) { - xen_pt_config_reg_init(s, reg_grp_entry, regs, &err); - if (err) { - error_append_hint(&err, "Failed to init register %= d" - " offsets 0x%x in grp_type =3D 0x%x (%d/%z= u)", j, - regs->offset, xen_pt_emu_reg_grps[i].grp_t= ype, - i, ARRAY_SIZE(xen_pt_emu_reg_grps)); - error_propagate(errp, err); + xen_pt_config_reg_init(s, reg_grp_entry, regs, errp); + if (*errp) { + error_append_hint(errp, "Failed to init register %= d" + " offsets 0x%x in grp_type =3D 0= x%x (%d/%zu)", + j, + regs->offset, + xen_pt_emu_reg_grps[i].grp_type, + i, ARRAY_SIZE(xen_pt_emu_reg_grp= s)); xen_pt_config_delete(s); return; } --=20 2.21.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel