From nobody Thu May 2 08:09:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1594140681; cv=none; d=zohomail.com; s=zohoarc; b=I26Vfxp/HMLhglCJZqVys/CwjLA2nh9Rkkzm0kkYqwERiyIJRJLAISy1E7b9s15ZCy48nRRjFRfeqKEloVSlKuRAwz8H46gASFEDqCf3k5Gbxer+VenenMN9NhrbweK8/+PW+q5nWRKw032SO3bKdpLs8nhR/BbhUNPuH0V4tHU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594140681; 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=KKO2Q9u+xz+qTdzJ9ZmsOxTNiwSVbF6iRvMZkU+WmSs=; b=NSYJ3YjnJMmwrYyBJtCx5+LYq4f41U3DxIarRG53ogjCUX+NwEOFlseCn95zR5yZVc7ZMbObE+hfLqK84c5J3oVl8iv+0FySVtSXrWRgcexpGSDDqXcN0naQClExM2No3ELDs+HRDygiepqN7uOCtqexOP/9bZDNf8Y/lKKGWhE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 159414068159473.52590668665027; Tue, 7 Jul 2020 09:51:21 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jsqnz-0000Dk-9G; Tue, 07 Jul 2020 16:50:51 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jsqny-0000Df-4l for xen-devel@lists.xenproject.org; Tue, 07 Jul 2020 16:50:50 +0000 Received: from us-smtp-delivery-1.mimecast.com (unknown [205.139.110.61]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 02b555cf-c072-11ea-8dc2-12813bfff9fa; Tue, 07 Jul 2020 16:50:49 +0000 (UTC) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-408-mq3_WHHyNKKe-_lpW2tf_w-1; Tue, 07 Jul 2020 12:50:46 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E66C7461; Tue, 7 Jul 2020 16:50:44 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-143.ams2.redhat.com [10.36.112.143]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9169A73FC0; Tue, 7 Jul 2020 16:50:38 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1DA4A1132921; Tue, 7 Jul 2020 18:50:37 +0200 (CEST) X-Inumbo-ID: 02b555cf-c072-11ea-8dc2-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594140649; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KKO2Q9u+xz+qTdzJ9ZmsOxTNiwSVbF6iRvMZkU+WmSs=; b=HlfXZsqzUZIFp22x0kaGtSSoFKguIpL+8VD/c3Sin28ZWkkHjVUn+YUTv791APz7bv6jRW iqIgn6EDd3tSjQqwd6MPZ6J7Vusw7H01gOLkp0qXCIC3ChzycMlJKH72lDDRiDPkFqxoVJ pEKTSdl/zhn5S9/13JhpOFbZ48ng8ww= X-MC-Unique: mq3_WHHyNKKe-_lpW2tf_w-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v12 1/8] error: New macro ERRP_AUTO_PROPAGATE() Date: Tue, 7 Jul 2020 18:50:30 +0200 Message-Id: <20200707165037.1026246-2-armbru@redhat.com> In-Reply-To: <20200707165037.1026246-1-armbru@redhat.com> References: <20200707165037.1026246-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , vsementsov@virtuozzo.com, Michael Roth , qemu-block@nongnu.org, Paul Durrant , Laszlo Ersek , Christian Schoenebeck , groug@kaod.org, Eric Blake , Max Reitz , Stefano Stabellini , Gerd Hoffmann , Stefan Hajnoczi , Anthony Perard , xen-devel@lists.xenproject.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Introduce a new ERRP_AUTO_PROPAGATE macro, to be used at start of functions with an errp OUT parameter. It has three goals: 1. Fix issue with error_fatal and 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 and error_propagate: when we wrap error_abort by local_err+error_propagate, the 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 us to [3.] drop the 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, later patches will add invocations of this macro at the start of functions with either use error_prepend/error_append_hint (solving 1) or which use local_err+error_propagate to check errors, switching those functions to use *errp instead (solving 2 and 3). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Paul Durrant Reviewed-by: Greg Kurz Reviewed-by: Eric Blake [Comments merged properly with recent commit "error: Document Error API usage rules", and edited for clarity. Put ERRP_AUTO_PROPAGATE() before its helpers, and touch up style. Commit message tweaked.] Signed-off-by: Markus Armbruster --- include/qapi/error.h | 160 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 141 insertions(+), 19 deletions(-) diff --git a/include/qapi/error.h b/include/qapi/error.h index 3fed49747d..c865a7d2f1 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -30,6 +30,10 @@ * job. Since the value of @errp is about handling the error, the * function should not examine it. * + * - The function may pass @errp to functions it calls to pass on + * their errors to its caller. If it dereferences @errp to check + * for errors, it must use ERRP_AUTO_PROPAGATE(). + * * - On success, the function should not touch *errp. On failure, it * should set a new error, e.g. with error_setg(errp, ...), or * propagate an existing one, e.g. with error_propagate(errp, ...). @@ -45,15 +49,17 @@ * =3D Creating errors =3D * * Create an error: - * error_setg(&err, "situation normal, all fouled up"); + * error_setg(errp, "situation normal, all fouled up"); + * where @errp points to the location to receive the error. * * Create an error and add additional explanation: - * error_setg(&err, "invalid quark"); - * error_append_hint(&err, "Valid quarks are up, down, strange, " + * error_setg(errp, "invalid quark"); + * error_append_hint(errp, "Valid quarks are up, down, strange, " * "charm, top, bottom.\n"); + * This may require use of ERRP_AUTO_PROPAGATE(); more on that below. * * Do *not* contract this to - * error_setg(&err, "invalid quark\n" // WRONG! + * error_setg(errp, "invalid quark\n" // WRONG! * "Valid quarks are up, down, strange, charm, top, bottom.= "); * * =3D Reporting and destroying errors =3D @@ -107,18 +113,6 @@ * Errors get passed to the caller through the conventional @errp * parameter. * - * Pass an existing error to the caller: - * error_propagate(errp, err); - * where Error **errp is a parameter, by convention the last one. - * - * Pass an existing error to the caller with the message modified: - * error_propagate_prepend(errp, err, - * "Could not frobnicate '%s': ", name); - * This is more concise than - * error_propagate(errp, err); // don't do this - * error_prepend(errp, "Could not frobnicate '%s': ", name); - * and works even when @errp is &error_fatal. - * * Create a new error and pass it to the caller: * error_setg(errp, "situation normal, all fouled up"); * @@ -128,18 +122,26 @@ * handle the error... * } * when it doesn't, say a void function: + * ERRP_AUTO_PROPAGATE(); + * foo(arg, errp); + * if (*errp) { + * handle the error... + * } + * More on ERRP_AUTO_PROPAGATE() below. + * + * Code predating ERRP_AUTO_PROPAGATE() still exits, and looks like this: * Error *err =3D NULL; * foo(arg, &err); * if (err) { * handle the error... - * error_propagate(errp, err); + * error_propagate(errp, err); // deprecated * } - * Do *not* "optimize" this to + * Avoid in new code. Do *not* "optimize" it to * foo(arg, errp); * if (*errp) { // WRONG! * handle the error... * } - * because errp may be NULL! + * because errp may be NULL! Guard with ERRP_AUTO_PROPAGATE(). * * But when all you do with the error is pass it on, please use * foo(arg, errp); @@ -158,6 +160,19 @@ * handle the error... * } * + * Pass an existing error to the caller: + * error_propagate(errp, err); + * This is rarely needed. When @err is a local variable, use of + * ERRP_AUTO_PROPAGATE() commonly results in more readable code. + * + * Pass an existing error to the caller with the message modified: + * error_propagate_prepend(errp, err, + * "Could not frobnicate '%s': ", name); + * This is more concise than + * error_propagate(errp, err); // don't do this + * error_prepend(errp, "Could not frobnicate '%s': ", name); + * and works even when @errp is &error_fatal. + * * Receive and accumulate multiple errors (first one wins): * Error *err =3D NULL, *local_err =3D NULL; * foo(arg, &err); @@ -185,6 +200,70 @@ * error_setg(&err, ...); // WRONG! * } * because this may pass a non-null err to error_setg(). + * + * =3D Why, when and how to use ERRP_AUTO_PROPAGATE() =3D + * + * Without ERRP_AUTO_PROPAGATE(), use of the @errp parameter is + * restricted: + * - It must not be dereferenced, because it may be null. + * - It should not be passed to error_prepend() or + * error_append_hint(), because that doesn't work with &error_fatal. + * ERRP_AUTO_PROPAGATE() lifts these restrictions. + * + * To use ERRP_AUTO_PROPAGATE(), add it right at the beginning of the + * function. @errp can then be used without worrying about the + * argument being NULL or &error_fatal. + * + * Using it when it's not needed is safe, but please avoid cluttering + * the source with useless code. + * + * =3D Converting to ERRP_AUTO_PROPAGATE() =3D + * + * To convert a function to use ERRP_AUTO_PROPAGATE(): + * + * 0. If the Error ** parameter is not named @errp, rename it to + * @errp. + * + * 1. Add an ERRP_AUTO_PROPAGATE() invocation, by convention right at + * the beginning of the function. This makes @errp safe to use. + * + * 2. Replace &err by errp, and err by *errp. Delete local variable + * @err. + * + * 3. Delete error_propagate(errp, *errp), replace + * error_propagate_prepend(errp, *errp, ...) by error_prepend(errp, ...= ), + * + * 4. Ensure @errp is valid at return: when you destroy *errp, set + * errp =3D NULL. + * + * Example: + * + * bool fn(..., Error **errp) + * { + * Error *err =3D NULL; + * + * foo(arg, &err); + * if (err) { + * handle the error... + * error_propagate(errp, err); + * return false; + * } + * ... + * } + * + * becomes + * + * bool fn(..., Error **errp) + * { + * ERRP_AUTO_PROPAGATE(); + * + * foo(arg, errp); + * if (*errp) { + * handle the error... + * return false; + * } + * ... + * } */ =20 #ifndef ERROR_H @@ -285,6 +364,7 @@ void error_setg_win32_internal(Error **errp, * the error object. * Else, move the error object from @local_err to *@dst_errp. * On return, @local_err is invalid. + * Please use ERRP_AUTO_PROPAGATE() instead when possible. * Please don't error_propagate(&error_fatal, ...), use * error_report_err() and exit(), because that's more obvious. */ @@ -296,6 +376,8 @@ void error_propagate(Error **dst_errp, Error *local_err= ); * Behaves like * error_prepend(&local_err, fmt, ...); * error_propagate(dst_errp, local_err); + * Please use ERRP_AUTO_PROPAGATE() and error_prepend() instead when + * possible. */ void error_propagate_prepend(Error **dst_errp, Error *local_err, const char *fmt, ...); @@ -393,6 +475,46 @@ void error_set_internal(Error **errp, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(6, 7); =20 +/* + * Make @errp parameter easier to use regardless of argument value + * + * This macro is for use right at the beginning of a function that + * takes an Error **errp parameter to pass errors to its caller. The + * parameter must be named @errp. + * + * It must be used when the function dereferences @errp or passes + * @errp to error_prepend(), error_vprepend(), or error_append_hint(). + * It is safe to use even when it's not needed, but please avoid + * cluttering the source with useless code. + * + * If @errp is NULL or &error_fatal, rewrite it to point to a local + * Error variable, which will be automatically propagated to the + * original @errp on function exit. + * + * Note: &error_abort is not rewritten, because that would move the + * abort from the place where the error is created to the place where + * it's propagated. + */ +#define ERRP_AUTO_PROPAGATE() \ + g_auto(ErrorPropagator) _auto_errp_prop =3D {.errp =3D errp}; \ + do { \ + if (!errp || errp =3D=3D &error_fatal) { \ + errp =3D &_auto_errp_prop.local_err; \ + } \ + } while (0) + +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= ); + /* * Special error destination to abort on error. * See error_setg() and error_propagate() for details. --=20 2.26.2 From nobody Thu May 2 08:09:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1594140681; cv=none; d=zohomail.com; s=zohoarc; b=SKrPh1FyO7RxbYhsheF+GYm5WCORVnkolZirhr21SsA4RxHWajBqM39aT4ytJEa1bt/ZQ4yl/GMRjV74maofb++x7N3+TKjVMdoGhDNePy2pWeIYaYG7y39VXhkB8QHrsN7OfaBPt1jvVQ8cSOQFVne1xIqADufQJZzFfQXtUUI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594140681; 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=tfYdRm061SMd4nDtfstsQpb4KLifF83vlL7jhH/NxAw=; b=LKUorGtUURwIDKG8GSstRAif6SoPQOa7ikag0Q0tNKD+qwtM5vdDwDv44aYiVIrtNFZYprWxp05PypbX43p0xuzkwPTw/j5W5JH31pRR8IjCuWeNWEX/KQeII9wXjkNJiK8NTudbIO9AT6gUpNkqpsnq3sJiZpmveEPvkePYmYs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1594140681166243.0669612281165; Tue, 7 Jul 2020 09:51:21 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jsqo9-0000F3-6S; Tue, 07 Jul 2020 16:51:01 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jsqo8-0000Dr-22 for xen-devel@lists.xenproject.org; Tue, 07 Jul 2020 16:51:00 +0000 Received: from us-smtp-delivery-1.mimecast.com (unknown [205.139.110.120]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 05964c12-c072-11ea-8496-bc764e2007e4; Tue, 07 Jul 2020 16:50:54 +0000 (UTC) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-486-jgdjWGplOOuWAbWVG03AkQ-1; Tue, 07 Jul 2020 12:50:48 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D8A9191177; Tue, 7 Jul 2020 16:50:46 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-143.ams2.redhat.com [10.36.112.143]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9C55160E1C; Tue, 7 Jul 2020 16:50:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 21DD71132922; Tue, 7 Jul 2020 18:50:37 +0200 (CEST) X-Inumbo-ID: 05964c12-c072-11ea-8496-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594140653; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tfYdRm061SMd4nDtfstsQpb4KLifF83vlL7jhH/NxAw=; b=aqalNxokzJJMU6DCOQCyRYjgpHSlmK50s1VzpXX9wESmQyGpiVezToCpdsr5mwB0InYXzg lYUHH+lnxohvdNYiWGg6CI2QZ5IzdAj+XuUiqyIAwP3bRxqtzY+yuSHvhd+4ZCzV1nODua 09f+uAX4HDXOI+35FyrEQW6C5XyQYpo= X-MC-Unique: jgdjWGplOOuWAbWVG03AkQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v12 2/8] scripts: Coccinelle script to use ERRP_AUTO_PROPAGATE() Date: Tue, 7 Jul 2020 18:50:31 +0200 Message-Id: <20200707165037.1026246-3-armbru@redhat.com> In-Reply-To: <20200707165037.1026246-1-armbru@redhat.com> References: <20200707165037.1026246-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , vsementsov@virtuozzo.com, Michael Roth , qemu-block@nongnu.org, Paul Durrant , Laszlo Ersek , Christian Schoenebeck , groug@kaod.org, Max Reitz , Stefano Stabellini , Gerd Hoffmann , Stefan Hajnoczi , Anthony Perard , xen-devel@lists.xenproject.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Vladimir Sementsov-Ogievskiy Script adds ERRP_AUTO_PROPAGATE macro invocation where appropriate and does corresponding changes in code (look for details in include/qapi/error.h) Usage example: spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \ --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff \ --max-width 80 FILES... Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/coccinelle/auto-propagated-errp.cocci | 337 ++++++++++++++++++ include/qapi/error.h | 3 + MAINTAINERS | 1 + 3 files changed, 341 insertions(+) create mode 100644 scripts/coccinelle/auto-propagated-errp.cocci diff --git a/scripts/coccinelle/auto-propagated-errp.cocci b/scripts/coccin= elle/auto-propagated-errp.cocci new file mode 100644 index 0000000000..c29f695adf --- /dev/null +++ b/scripts/coccinelle/auto-propagated-errp.cocci @@ -0,0 +1,337 @@ +// 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 --max-width 80 FILES... +// +// Note: --max-width 80 is needed because coccinelle default is less +// than 80, and without this parameter coccinelle may reindent some +// lines which fit into 80 characters but not to coccinelle default, +// which in turn produces extra patch hunks for no reason. + +// Switch unusual Error ** parameter names to errp +// (this is necessary to use ERRP_AUTO_PROPAGATE). +// +// Disable optional_qualifier to skip functions with +// "Error *const *errp" parameter. +// +// Skip functions with "assert(_errp && *_errp)" statement, because +// that signals unusual semantics, and the parameter name may well +// serve a purpose. (like nbd_iter_channel_error()). +// +// Skip util/error.c to not touch, for example, error_propagate() and +// error_propagate_prepend(). +@ depends on !(file in "util/error.c") disable optional_qualifier@ +identifier fn; +identifier _errp !=3D errp; +@@ + + fn(..., +- Error **_errp ++ Error **errp + ,...) + { +( + ... when !=3D assert(_errp && *_errp) +& + <... +- _errp ++ errp + ...> +) + } + +// Add invocation of ERRP_AUTO_PROPAGATE to errp-functions where +// necessary +// +// Note, that without "when any" the final "..." does not mach +// something matched by previous pattern, i.e. the rule will not match +// double error_prepend in control flow like in +// vfio_set_irq_signaling(). +// +// Note, "exists" says that we want apply rule even if it does not +// match on all possible control flows (otherwise, it will not match +// standard pattern when error_propagate() call is in if branch). +@ disable optional_qualifier exists@ +identifier fn, local_err; +symbol errp; +@@ + + fn(..., Error **errp, ...) + { ++ ERRP_AUTO_PROPAGATE(); + ... when !=3D ERRP_AUTO_PROPAGATE(); +( +( + error_append_hint(errp, ...); +| + error_prepend(errp, ...); +| + error_vprepend(errp, ...); +) + ... when any +| + Error *local_err =3D NULL; + ... +( + error_propagate_prepend(errp, local_err, ...); +| + error_propagate(errp, local_err); +) + ... +) + } + +// Warn when several Error * definitions are in the control flow. +// This rule is not chained to rule1 and less restrictive, to cover more +// functions to warn (even those we are not going to convert). +// +// Note, that even with one (or zero) Error * definition in the each +// control flow we may have several (in total) Error * definitions in +// the function. This case deserves attention too, but I don't see +// simple way to match with help of coccinelle. +@check1 disable optional_qualifier exists@ +identifier fn, _errp, local_err, local_err2; +position p1, p2; +@@ + + fn(..., Error **_errp, ...) + { + ... + Error *local_err =3D NULL;@p1 + ... when any + Error *local_err2 =3D NULL;@p2 + ... when any + } + +@ script:python @ +fn << check1.fn; +p1 << check1.p1; +p2 << check1.p2; +@@ + +print('Warning: function {} has several definitions of ' + 'Error * local variable: at {}:{} and then at {}:{}'.format( + fn, p1[0].file, p1[0].line, p2[0].file, p2[0].line)) + +// Warn when several propagations are in the control flow. +@check2 disable optional_qualifier exists@ +identifier fn, _errp; +position p1, p2; +@@ + + fn(..., Error **_errp, ...) + { + ... +( + error_propagate_prepend(_errp, ...);@p1 +| + error_propagate(_errp, ...);@p1 +) + ... +( + error_propagate_prepend(_errp, ...);@p2 +| + error_propagate(_errp, ...);@p2 +) + ... when any + } + +@ script:python @ +fn << check2.fn; +p1 << check2.p1; +p2 << check2.p2; +@@ + +print('Warning: function {} propagates to errp several times in ' + 'one control flow: at {}:{} and then at {}:{}'.format( + fn, p1[0].file, p1[0].line, p2[0].file, p2[0].line)) + +// Match functions with propagation of local error to errp. +// We want to refer these functions in several following rules, but I +// don't know a proper way to inherit a function, not just its name +// (to not match another functions with same name in following rules). +// Not-proper way is as follows: rename errp parameter in functions +// header and match it in following rules. Rename it back after all +// transformations. +// +// The common case is a single definition of local_err with at most one +// error_propagate_prepend() or error_propagate() on each control-flow +// path. Functions with multiple definitions or propagates we want to +// examine manually. Rules check1 and check2 emit warnings to guide us +// to them. +// +// Note that we match not only this "common case", but any function, +// which has the "common case" on at least one control-flow path. +@rule1 disable optional_qualifier exists@ +identifier fn, local_err; +symbol errp; +@@ + + fn(..., Error ** +- errp ++ ____ + , ...) + { + ... + Error *local_err =3D NULL; + ... +( + error_propagate_prepend(errp, local_err, ...); +| + error_propagate(errp, local_err); +) + ... + } + +// Convert special case with goto separately. +// I tried merging this into the following rule the obvious way, but +// it made Coccinelle hang on block.c +// +// Note interesting thing: if we don't do it here, and try to fixup +// "out: }" things later after all transformations (the rule will be +// the same, just without error_propagate() call), coccinelle fails to +// match this "out: }". +@ disable optional_qualifier@ +identifier rule1.fn, rule1.local_err, out; +symbol errp; +@@ + + fn(..., Error ** ____, ...) + { + <... +- goto out; ++ return; + ...> +- out: +- error_propagate(errp, local_err); + } + +// Convert most of local_err related stuff. +// +// Note, that we inherit rule1.fn and rule1.local_err names, not +// objects themselves. We may match something not related to the +// pattern matched by rule1. For example, local_err may be defined with +// the same name in different blocks inside one function, and in one +// block follow the propagation pattern and in other block doesn't. +// +// Note also that errp-cleaning functions +// error_free_errp +// error_report_errp +// error_reportf_errp +// warn_report_errp +// warn_reportf_errp +// are not yet implemented. They must call corresponding Error* - +// freeing function and then set *errp to NULL, to avoid further +// propagation to original errp (consider ERRP_AUTO_PROPAGATE in use). +// For example, error_free_errp may look like this: +// +// void error_free_errp(Error **errp) +// { +// error_free(*errp); +// *errp =3D NULL; +// } +@ disable optional_qualifier exists@ +identifier rule1.fn, rule1.local_err; +expression list args; +symbol errp; +@@ + + fn(..., Error ** ____, ...) + { + <... +( +- Error *local_err =3D NULL; +| + +// Convert error clearing functions +( +- error_free(local_err); ++ error_free_errp(errp); +| +- error_report_err(local_err); ++ error_report_errp(errp); +| +- error_reportf_err(local_err, args); ++ error_reportf_errp(errp, args); +| +- warn_report_err(local_err); ++ warn_report_errp(errp); +| +- warn_reportf_err(local_err, args); ++ warn_reportf_errp(errp, args); +) +?- local_err =3D NULL; + +| +- error_propagate_prepend(errp, local_err, args); ++ error_prepend(errp, args); +| +- error_propagate(errp, local_err); +| +- &local_err ++ errp +) + ...> + } + +// Convert remaining local_err usage. For example, different kinds of +// error checking in if conditionals. We can't merge this into +// previous hunk, as this conflicts with other substitutions in it (at +// least with "- local_err =3D NULL"). +@ disable optional_qualifier@ +identifier rule1.fn, rule1.local_err; +symbol errp; +@@ + + fn(..., Error ** ____, ...) + { + <... +- local_err ++ *errp + ...> + } + +// Always use the same pattern for checking error +@ disable optional_qualifier@ +identifier rule1.fn; +symbol errp; +@@ + + fn(..., Error ** ____, ...) + { + <... +- *errp !=3D NULL ++ *errp + ...> + } + +// Revert temporary ___ identifier. +@ disable optional_qualifier@ +identifier rule1.fn; +@@ + + fn(..., Error ** +- ____ ++ errp + , ...) + { + ... + } diff --git a/include/qapi/error.h b/include/qapi/error.h index c865a7d2f1..91547fe4ea 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -264,6 +264,9 @@ * } * ... * } + * + * For mass-conversion, use script + * scripts/coccinelle/auto-propagated-errp.cocci */ =20 #ifndef ERROR_H diff --git a/MAINTAINERS b/MAINTAINERS index c31c878c63..121953b24d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2166,6 +2166,7 @@ F: scripts/coccinelle/error-use-after-free.cocci F: scripts/coccinelle/error_propagate_null.cocci F: scripts/coccinelle/remove_local_err.cocci F: scripts/coccinelle/use-error_fatal.cocci +F: scripts/coccinelle/auto-propagated-errp.cocci =20 GDB stub M: Alex Benn=C3=A9e --=20 2.26.2 From nobody Thu May 2 08:09:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1594140680; cv=none; d=zohomail.com; s=zohoarc; b=X3fPcHWjLJevZxh1l+kSvO+wxAN/ANUMHE+L6KX9FwEsVZsZzLnVCaU6DMaiQPiWUwSo4IaFAOtmL/98puOpsZul2cJGYLWbN4AVDpHL7GkLjxLR1aJTsuNC0Ebdium6+0MmM3xdF56IlHpj6URcTeo3hxy5CnKYbKt9rSisQCQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594140680; 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=kTc4yRwO5a9XF+O06cElX+INNSFMrjGg1hnzHUx6ZOU=; b=WY1Wgh54urYCcRgYondpVZlgWS1EE+yFv8z2ldtCg5PsSw/nbkzSxAvckjbTXlnG4yWE1j5NVudenSf4D/EQtjdJSoZApReK7jfBDTGtXz5h7DPHVRU/W3kor7BBjMatC5gx8l/gJNsyDg9inWI7JTq8J+M2yJsIEV+g8Bkbsow= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 159414068029586.15865365201932; Tue, 7 Jul 2020 09:51:20 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jsqo4-0000EH-Q3; Tue, 07 Jul 2020 16:50:56 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jsqo3-0000Dr-5M for xen-devel@lists.xenproject.org; Tue, 07 Jul 2020 16:50:55 +0000 Received: from us-smtp-1.mimecast.com (unknown [207.211.31.81]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 04f59fd8-c072-11ea-b7bb-bc764e2007e4; Tue, 07 Jul 2020 16:50:53 +0000 (UTC) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-205-8gbxd39nN9aA_Cw08BWDdA-1; Tue, 07 Jul 2020 12:50:50 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B71BD1005510; Tue, 7 Jul 2020 16:50:48 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-143.ams2.redhat.com [10.36.112.143]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 98A2A5D9C9; Tue, 7 Jul 2020 16:50:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 25B3611328A3; Tue, 7 Jul 2020 18:50:37 +0200 (CEST) X-Inumbo-ID: 04f59fd8-c072-11ea-b7bb-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594140652; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kTc4yRwO5a9XF+O06cElX+INNSFMrjGg1hnzHUx6ZOU=; b=aSBpSdGNECTHeybyoEgiQ9+/I91OHNtf7c59WTpSt6Bzl5c++iQf9oGyHQJPoWNEunc2vX qPSEqxOziyB8zC7Y/W4OPJsZ0QCbAnK52gqeug6MuEmSRy370spUUI20msi6EvDVBYcS2W d9dRNFzq5cNOhHON+TwAElysIA0XCNE= X-MC-Unique: 8gbxd39nN9aA_Cw08BWDdA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v12 3/8] sd: Use ERRP_AUTO_PROPAGATE() Date: Tue, 7 Jul 2020 18:50:32 +0200 Message-Id: <20200707165037.1026246-4-armbru@redhat.com> In-Reply-To: <20200707165037.1026246-1-armbru@redhat.com> References: <20200707165037.1026246-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , vsementsov@virtuozzo.com, Michael Roth , qemu-block@nongnu.org, Paul Durrant , Laszlo Ersek , Christian Schoenebeck , groug@kaod.org, Max Reitz , Stefano Stabellini , Gerd Hoffmann , Stefan Hajnoczi , Anthony Perard , xen-devel@lists.xenproject.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Vladimir Sementsov-Ogievskiy 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 [Commit message tweaked] Signed-off-by: Markus Armbruster --- hw/sd/sdhci-pci.c | 7 +++---- hw/sd/sdhci.c | 21 +++++++++------------ hw/sd/ssi-sd.c | 10 +++++----- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/hw/sd/sdhci-pci.c b/hw/sd/sdhci-pci.c index 4f5977d487..38ec572fc6 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 eb2be6529e..be1928784d 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -1288,7 +1288,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: @@ -1299,9 +1299,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; } } @@ -1332,11 +1331,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); @@ -1456,13 +1454,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 diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c index 3717b2e721..adb7fa9c24 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 SSI_SD(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"); @@ -255,23 +255,23 @@ static void ssi_sd_realize(SSISlave *d, Error **errp) carddev =3D qdev_new(TYPE_SD_CARD); if (dinfo) { if (!qdev_prop_set_drive_err(carddev, "drive", - blk_by_legacy_dinfo(dinfo), &err)) { + blk_by_legacy_dinfo(dinfo), errp)) { goto fail; } } =20 - if (!object_property_set_bool(OBJECT(carddev), "spi", true, &err)) { + if (!object_property_set_bool(OBJECT(carddev), "spi", true, errp)) { goto fail; } =20 - if (!qdev_realize_and_unref(carddev, BUS(&s->sdbus), &err)) { + if (!qdev_realize_and_unref(carddev, BUS(&s->sdbus), errp)) { goto fail; } =20 return; =20 fail: - error_propagate_prepend(errp, err, "failed to init SD card: "); + error_prepend(errp, "failed to init SD card: "); } =20 static void ssi_sd_reset(DeviceState *dev) --=20 2.26.2 From nobody Thu May 2 08:09:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1594140680; cv=none; d=zohomail.com; s=zohoarc; b=BPiuiZZOOHwHcXNY0BaMEDCS7+PWVED5drz4EwqtUi2BBiGJQCsIXOdiiLcpGdNHFswmeMyCLEet/qpf8ZzTPZg91i/r6eYmnX4KuWi3A3Ns/QV2vhr1MqrDxhZCk8QxUrte7zx+7Da9obhTy6ueB8eg8/APr5yVH++rgOZg2tQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594140680; 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=ZwJYdyi9Qt1/sCxmydGDv1Kj4p25FpuhPaW1i/Z86t0=; b=aCe68ltl1/JllWcBriPjkbSDOsVfdEVHi8imvnHl9bFSzpeM8lTpW1lv83/cY9H2zZOn7HPd3E8t0qhnnnqeBXFCsBZ+c0Uvz2zhGbObhWG7zB2zpHf1uiTmmAqS1t5kXqAtzKf903hgP9zNRRTMeXEaKNkoQnQZXk35PyfsIaQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1594140680964176.50601613090907; Tue, 7 Jul 2020 09:51:20 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jsqo3-0000E3-Hg; Tue, 07 Jul 2020 16:50:55 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jsqo2-0000Df-Vw for xen-devel@lists.xenproject.org; Tue, 07 Jul 2020 16:50:55 +0000 Received: from us-smtp-delivery-1.mimecast.com (unknown [207.211.31.81]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 05212e3e-c072-11ea-8dc2-12813bfff9fa; Tue, 07 Jul 2020 16:50:53 +0000 (UTC) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-469-cFlUF-bKNRqFv4oHtYQYbA-1; Tue, 07 Jul 2020 12:50:51 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7A42E107ACF2; Tue, 7 Jul 2020 16:50:49 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-143.ams2.redhat.com [10.36.112.143]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9C93719D61; Tue, 7 Jul 2020 16:50:43 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2960311326E4; Tue, 7 Jul 2020 18:50:37 +0200 (CEST) X-Inumbo-ID: 05212e3e-c072-11ea-8dc2-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594140653; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZwJYdyi9Qt1/sCxmydGDv1Kj4p25FpuhPaW1i/Z86t0=; b=DMXS20HIwIMuAu1PfTHuEIpjBPpxgnpsLqvc1fMB6kb3OQSowZl27A0LHhzi0SpCe5PJ+X PWHjo4h2GxaWC/QHwns4Fzvh/ixgr3muUf6QfbbDr61ePz47/Ewva0VPE+Kq33lFgxtGqK exbtSPiMI9f8GpZBdlDlO48ZFBrGCGw= X-MC-Unique: cFlUF-bKNRqFv4oHtYQYbA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v12 4/8] pflash: Use ERRP_AUTO_PROPAGATE() Date: Tue, 7 Jul 2020 18:50:33 +0200 Message-Id: <20200707165037.1026246-5-armbru@redhat.com> In-Reply-To: <20200707165037.1026246-1-armbru@redhat.com> References: <20200707165037.1026246-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , vsementsov@virtuozzo.com, Michael Roth , qemu-block@nongnu.org, Paul Durrant , Laszlo Ersek , Christian Schoenebeck , groug@kaod.org, Max Reitz , Stefano Stabellini , Gerd Hoffmann , Stefan Hajnoczi , Anthony Perard , xen-devel@lists.xenproject.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Vladimir Sementsov-Ogievskiy 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 [Commit message tweaked] Signed-off-by: Markus Armbruster --- 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 cddc3a5a0c..859cfeae14 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -696,12 +696,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."); @@ -735,9 +735,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 b40ce2335a..15035ee5ef 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -724,9 +724,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."); @@ -792,9 +792,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.26.2 From nobody Thu May 2 08:09:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1594140682; cv=none; d=zohomail.com; s=zohoarc; b=NPV9t3QYVQ1R0Y6X++6TlkwqUdv9osmr360CBINOee5f4J4eGfnCGQCxfQ4mvbhW43qWtRt4Bsvt0sljSp59j96Ov9hZlq9bH6GMSYs8pOvhwIpyHmzPyilihk88kIjw8Cr9GA95gCKLewu4S5ZpUTHMc3xJjf0ckQOvF6YWtwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594140682; 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=XdaTtnXzRdmtkraOf3fJnKW205wPYgtaTPC/KbxTb9A=; b=JPpECKPrXTYZBNrW4zHDrzrZZ5Adh3KGUQWeXyh9+kY5BdUPzILTcX9EpypnKhBSX8I87jdnkclS2hZnGHDXQXuece3U2kFCQ+cjVClOGSEfqkOFA5rhjG/5X8b9gFi1V1WLdSVD+tEZU/KUITiR+l2wYnnTfxPdgRQAukg5npI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1594140682936855.6776872158329; Tue, 7 Jul 2020 09:51:22 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jsqoI-0000La-JJ; Tue, 07 Jul 2020 16:51:10 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jsqoI-0000Dr-2X for xen-devel@lists.xenproject.org; Tue, 07 Jul 2020 16:51:10 +0000 Received: from us-smtp-delivery-1.mimecast.com (unknown [207.211.31.81]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 0d763faa-c072-11ea-bca7-bc764e2007e4; Tue, 07 Jul 2020 16:51:07 +0000 (UTC) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-39-CKUKUa5lMlaT6ynxi7hKYw-1; Tue, 07 Jul 2020 12:51:02 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5205D804001; Tue, 7 Jul 2020 16:51:00 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-143.ams2.redhat.com [10.36.112.143]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8857B512FE; Tue, 7 Jul 2020 16:50:54 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2D1D711326EC; Tue, 7 Jul 2020 18:50:37 +0200 (CEST) X-Inumbo-ID: 0d763faa-c072-11ea-bca7-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594140667; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XdaTtnXzRdmtkraOf3fJnKW205wPYgtaTPC/KbxTb9A=; b=Fq3QyNnWigSpK4O9xGqOTT18QL3trFM8gGVZmNqJq6lMxkPZw0YwVEkCWIs8hduFBd5vuP tJZ0tvlx30FriOcF7LQ6Z4Q9t6/viBz80ReAqmzEuHYUUSo/bsDorgAVirWPQNO80smXhy mCPOCLXEknHjGgt7M5xTEQLpOExN+FE= X-MC-Unique: CKUKUa5lMlaT6ynxi7hKYw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v12 5/8] fw_cfg: Use ERRP_AUTO_PROPAGATE() Date: Tue, 7 Jul 2020 18:50:34 +0200 Message-Id: <20200707165037.1026246-6-armbru@redhat.com> In-Reply-To: <20200707165037.1026246-1-armbru@redhat.com> References: <20200707165037.1026246-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , vsementsov@virtuozzo.com, Michael Roth , qemu-block@nongnu.org, Paul Durrant , Laszlo Ersek , Christian Schoenebeck , groug@kaod.org, Max Reitz , Stefano Stabellini , Gerd Hoffmann , Stefan Hajnoczi , Anthony Perard , xen-devel@lists.xenproject.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Vladimir Sementsov-Ogievskiy 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 [Commit message tweaked] Signed-off-by: Markus Armbruster --- 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 0408a31f8e..d5386c3235 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -1231,12 +1231,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 @@ -1282,14 +1281,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.26.2 From nobody Thu May 2 08:09:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1594140681; cv=none; d=zohomail.com; s=zohoarc; b=NHTGEZJH3h0RJvTkBDFdlFBeFmK/f/HrAVUIJ7PIKdaXUD50Cm/Sv615unJ78FRiGm8uBQPI17suZHmhjoqDlrlnlB0sgKVJpvxfPJc0kEqy2hajIOGjIMf90dRp7E7f2R7UjF04udtkGcwDZQgh6xu/1qStbcKg4WitRAwVmYI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594140681; 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=GtSQ9ltFDy+ZS6gTE2EcxmbrVjKJQ192ZTarFddQmh4=; b=UpR+wzJBoHCJnQKOuqnna0TF33ZF2aPde61R12SoMoADAIb4L7BwSwVdHIRNqJtEnACQ4qL5HeXEsFHyHVR/Kxs8bZN3m7bHywkCuGCiIBRwXivO6F/lIQIo24ilTREwMaFUDTAF3DUwdTW1XmZnupwHx6iSulNNV6M+5QUqzHE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1594140681215695.7882266863857; Tue, 7 Jul 2020 09:51:21 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jsqo9-0000FB-Fm; Tue, 07 Jul 2020 16:51:01 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jsqo8-0000Ey-IF for xen-devel@lists.xenproject.org; Tue, 07 Jul 2020 16:51:00 +0000 Received: from us-smtp-1.mimecast.com (unknown [205.139.110.61]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 07f329a9-c072-11ea-8dc2-12813bfff9fa; Tue, 07 Jul 2020 16:50:59 +0000 (UTC) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-450-0UWQII4DOdu_QowMQ0wkdA-1; Tue, 07 Jul 2020 12:50:55 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 39B2E80183C; Tue, 7 Jul 2020 16:50:54 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-143.ams2.redhat.com [10.36.112.143]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8D5415C1D0; Tue, 7 Jul 2020 16:50:48 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3102611326F0; Tue, 7 Jul 2020 18:50:37 +0200 (CEST) X-Inumbo-ID: 07f329a9-c072-11ea-8dc2-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594140659; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GtSQ9ltFDy+ZS6gTE2EcxmbrVjKJQ192ZTarFddQmh4=; b=IdDMDYb/dEoY+IcSojtJq4x9TvwqizZgjdmay49JAj2Ox5uivpsDaZhhlUlMIHHRQEq0XB kt2zhOLsOW4NViO3QKYTB9Hcb46uvSixtEPxtRw3X2PFSgIQoZHxzgowVMtPLwkynGqHMp oNc0tsGch4HuRRSQl/HK1WxdHvaj59o= X-MC-Unique: 0UWQII4DOdu_QowMQ0wkdA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v12 6/8] virtio-9p: Use ERRP_AUTO_PROPAGATE() Date: Tue, 7 Jul 2020 18:50:35 +0200 Message-Id: <20200707165037.1026246-7-armbru@redhat.com> In-Reply-To: <20200707165037.1026246-1-armbru@redhat.com> References: <20200707165037.1026246-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , vsementsov@virtuozzo.com, Michael Roth , qemu-block@nongnu.org, Paul Durrant , Laszlo Ersek , Christian Schoenebeck , groug@kaod.org, Max Reitz , Stefano Stabellini , Gerd Hoffmann , Stefan Hajnoczi , Anthony Perard , xen-devel@lists.xenproject.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy 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 Reviewed-by: Christian Schoenebeck [Commit message tweaked] Signed-off-by: Markus Armbruster --- 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 54e012e5b4..0361e0c0b4 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -1479,10 +1479,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"); @@ -1516,11 +1516,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; } } @@ -1530,9 +1529,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 9755fba9a9..bdb1360482 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -4011,6 +4011,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.26.2 From nobody Thu May 2 08:09:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1594140826; cv=none; d=zohomail.com; s=zohoarc; b=M0mcYk4noxVfMhzg2fXt/9POufbMCbpxrwwAigXvvQguBx/y5uPWnehp2MzC6l/c/M3ken+o55qHW90EYF+KiyquCrzDnk1OgTX6irsLftdEkuqs+M9cG6ZT93aDg3ugb7nEDEmU3+49Niq/VhWIh2rPo3c0HYFxPYtcRtNWBCk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594140826; 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=YkAQltNuOP2YXnC4GnK3EmsF7L67rYh833RXsqUTHOE=; b=IPYBvTvNkdX8b5aR9wEF0ppFgLyh+zf758QRUnPKOPwmGQQF7+Qo8uRZRA2o1tWqH3qbQTktAvYAU/Piw06s2rWLBI+PBeezvKtQ52ShY0iaukzDY5rkJLbI2cXyDi72r9GhXr9TB6AbRdf3PSvWe8TVnceAqVtWVvlFl1dL11U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1594140826915569.6000030387514; Tue, 7 Jul 2020 09:53:46 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jsqqb-0000w1-1o; Tue, 07 Jul 2020 16:53:33 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jsqqa-0000vs-4N for xen-devel@lists.xenproject.org; Tue, 07 Jul 2020 16:53:32 +0000 Received: from us-smtp-1.mimecast.com (unknown [207.211.31.81]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 635ccc04-c072-11ea-8496-bc764e2007e4; Tue, 07 Jul 2020 16:53:31 +0000 (UTC) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-407-RP_ZSErIOhiH6b3uAxhGHA-1; Tue, 07 Jul 2020 12:50:54 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1CF71107ACF4; Tue, 7 Jul 2020 16:50:52 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-143.ams2.redhat.com [10.36.112.143]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 22AF060E1C; Tue, 7 Jul 2020 16:50:50 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 34DC611326F2; Tue, 7 Jul 2020 18:50:37 +0200 (CEST) X-Inumbo-ID: 635ccc04-c072-11ea-8496-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594140811; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YkAQltNuOP2YXnC4GnK3EmsF7L67rYh833RXsqUTHOE=; b=AHYQSo3yWbuAssq/srD4rbKBRuh6bngn1SjXLYfeHdBT6pLpDD4UqsEJrpvQXlaWa5u3Kr 5pLea2Q3OHcx3imQsB5rUiUkE6qDB3F5HrB/v6j1OVI1o1kFmT1klAxw/HawGu99i9Vq7B Beim9GUDV3Y9f/cfF9fxv7qy0hyw86c= X-MC-Unique: RP_ZSErIOhiH6b3uAxhGHA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v12 7/8] nbd: Use ERRP_AUTO_PROPAGATE() Date: Tue, 7 Jul 2020 18:50:36 +0200 Message-Id: <20200707165037.1026246-8-armbru@redhat.com> In-Reply-To: <20200707165037.1026246-1-armbru@redhat.com> References: <20200707165037.1026246-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , vsementsov@virtuozzo.com, Michael Roth , qemu-block@nongnu.org, Paul Durrant , Laszlo Ersek , Christian Schoenebeck , groug@kaod.org, Max Reitz , Stefano Stabellini , Gerd Hoffmann , Stefan Hajnoczi , Anthony Perard , xen-devel@lists.xenproject.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy 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: Markus Armbruster [Commit message tweaked] Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/block/nbd.h | 1 + block/nbd.c | 7 +++---- nbd/client.c | 5 +++++ nbd/server.c | 5 +++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 20363280ae..f7d87636d3 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -361,6 +361,7 @@ void nbd_server_start_options(NbdServerOptions *arg, Er= ror **errp); 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 6876da04a7..b7cea0f650 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -1408,16 +1408,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 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 20754e9ebc..8a12e586d7 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; @@ -382,6 +383,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 : ""; @@ -445,6 +447,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; @@ -1289,6 +1292,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 @@ -1663,6 +1667,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.26.2 From nobody Thu May 2 08:09:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1594140683; cv=none; d=zohomail.com; s=zohoarc; b=aHpiIu1GyyNFD+Js4Id06nwMwSihlPnE+n/M6lKZ2cSJ3y9CgxK/EwfxRlAnSfmJGQQ9l25ReGMrWYSafroI8jX2wn+B1O2br5Dq+cvrSCnbMqxSd/QlddAUvlte3YuRvzU+3Rog/VlnjRk1q7zPoPthLNCV1OThmsLplBSrn8U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594140683; 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=aIJau8wOVykrPOVaricLGyo+FPnaWPbGXksNfPDBJtM=; b=OdoKeUkeiYxLl+01DKJfpcP/aLjgJyxmvbEixsfNccVeot0pFniTQvxCwAQFaZ5HUn4MvWkYgrvj7IrRX938rmLgX85e3SsV8KdyLdom/gs+FA2rSvaCyaarGfSRPJdIBNTzvgtNQ3E+Kv0X1tXDtjojdprwI1guAWW1m49cLGI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1594140683743337.71492856445775; Tue, 7 Jul 2020 09:51:23 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jsqoE-0000IB-3a; Tue, 07 Jul 2020 16:51:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jsqoD-0000Dr-2L for xen-devel@lists.xenproject.org; Tue, 07 Jul 2020 16:51:05 +0000 Received: from us-smtp-delivery-1.mimecast.com (unknown [207.211.31.81]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 07f41f7a-c072-11ea-8496-bc764e2007e4; Tue, 07 Jul 2020 16:50:58 +0000 (UTC) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-231-WEDo_pGxM1Wyw7Jv2vbvsw-1; Tue, 07 Jul 2020 12:50:55 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D81738015F6; Tue, 7 Jul 2020 16:50:52 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-143.ams2.redhat.com [10.36.112.143]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2A0775D9C9; Tue, 7 Jul 2020 16:50:52 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3924F11326F3; Tue, 7 Jul 2020 18:50:37 +0200 (CEST) X-Inumbo-ID: 07f41f7a-c072-11ea-8496-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594140657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aIJau8wOVykrPOVaricLGyo+FPnaWPbGXksNfPDBJtM=; b=PU83hAxKcx94CD/7EdNgm9kJphvbYlHMVE0DJrykf3YeBBrXfane8GZ4WhCLohrBfOKp/P U3zkTJVqYiVNtWmIM/EsTVB6Z3abK0kpnEigANGKgLBSMnbRZ0gHy1LN7MHvGzvbN8Ewd/ 7+NPfpMp03nFGgHzy7SRtC9/9znkCLs= X-MC-Unique: WEDo_pGxM1Wyw7Jv2vbvsw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v12 8/8] xen: Use ERRP_AUTO_PROPAGATE() Date: Tue, 7 Jul 2020 18:50:37 +0200 Message-Id: <20200707165037.1026246-9-armbru@redhat.com> In-Reply-To: <20200707165037.1026246-1-armbru@redhat.com> References: <20200707165037.1026246-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , vsementsov@virtuozzo.com, Michael Roth , qemu-block@nongnu.org, Paul Durrant , Laszlo Ersek , Christian Schoenebeck , groug@kaod.org, Max Reitz , Stefano Stabellini , Gerd Hoffmann , Stefan Hajnoczi , Anthony Perard , xen-devel@lists.xenproject.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Vladimir Sementsov-Ogievskiy 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 Reviewed-by: Philippe Mathieu-Daud=C3=A9 [Commit message tweaked] Signed-off-by: Markus Armbruster --- hw/block/dataplane/xen-block.c | 17 +++--- hw/block/xen-block.c | 102 ++++++++++++++------------------- hw/pci-host/xen_igd_pt.c | 7 +-- hw/xen/xen-backend.c | 7 +-- hw/xen/xen-bus.c | 92 +++++++++++++---------------- hw/xen/xen-host-pci-device.c | 27 +++++---- hw/xen/xen_pt.c | 25 ++++---- hw/xen/xen_pt_config_init.c | 17 +++--- 8 files changed, 128 insertions(+), 166 deletions(-) diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index 5f8f15778b..1a077cc05f 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -723,8 +723,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 @@ -760,9 +760,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 @@ -770,9 +769,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 @@ -805,9 +803,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *datap= lane, dataplane->event_channel =3D xen_device_bind_event_channel(xendev, event_channel, 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 a775fba7c0..623ae5b8e0 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -195,6 +195,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); @@ -202,7 +203,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"); @@ -212,9 +212,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; } } @@ -280,8 +279,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: @@ -290,15 +289,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 @@ -311,9 +308,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 @@ -665,9 +661,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,10 +684,9 @@ static char *xen_block_blockdev_add(const char *id, QD= ict *qdict, 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 @@ -710,14 +705,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); @@ -731,6 +724,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= "); @@ -738,7 +732,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 @@ -817,13 +810,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; } @@ -848,8 +840,8 @@ static void xen_block_iothread_destroy(XenBlockIOThread= *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; QDict *opts; QObject *ret_data =3D NULL; =20 @@ -858,13 +850,11 @@ static XenBlockIOThread *xen_block_iothread_create(co= nst char *id, opts =3D qdict_new(); qdict_put_str(opts, "qom-type", TYPE_IOTHREAD); qdict_put_str(opts, "id", id); - qmp_object_add(opts, &ret_data, &local_err); + qmp_object_add(opts, &ret_data, errp); qobject_unref(opts); qobject_unref(ret_data); =20 - if (local_err) { - error_propagate(errp, local_err); - + if (*errp) { g_free(iothread->id); g_free(iothread); return NULL; @@ -876,6 +866,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 +874,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,16 +905,15 @@ 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 @@ -932,32 +921,29 @@ static void xen_block_device_create(XenBackendInstanc= e *backend, blockdev =3D XEN_BLOCK_DEVICE(xendev); =20 if (!object_property_set_str(OBJECT(xendev), "vdev", vdev, - &local_err)) { - error_propagate_prepend(errp, local_err, "failed to set 'vdev': "); + errp)) { + error_prepend(errp, "failed to set 'vdev': "); goto fail; } =20 if (!object_property_set_str(OBJECT(xendev), "drive", xen_block_drive_get_node_name(drive), - &local_err)) { - error_propagate_prepend(errp, local_err, "failed to set 'drive': "= ); + errp)) { + error_prepend(errp, "failed to set 'drive': "); goto fail; } =20 if (!object_property_set_str(OBJECT(xendev), "iothread", iothread->id, - &local_err)) { - error_propagate_prepend(errp, local_err, - "failed to set 'iothread': "); + errp)) { + error_prepend(errp, "failed to set 'iothread': "); goto fail; } =20 blockdev->iothread =3D iothread; blockdev->drive =3D drive; =20 - if (!qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), &local_err)) { - error_propagate_prepend(errp, local_err, - "realization of device %s failed: ", - type); + if (!qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), errp)) { + error_prepend(errp, "realization of device %s failed: ", type); goto fail; } =20 @@ -981,31 +967,29 @@ 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; XenBlockDrive *drive =3D blockdev->drive; XenBlockIOThread *iothread =3D blockdev->iothread; - Error *local_err =3D NULL; =20 trace_xen_block_device_destroy(vdev->number); =20 object_unparent(OBJECT(xendev)); =20 if (iothread) { - 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) { - 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: "); return; } } 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 c4e2162ae9..2ea5144ef0 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 @@ -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 @@ -1247,11 +1237,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; @@ -1267,10 +1257,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 @@ -1293,22 +1282,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 ab84443d5e..baa25eb91a 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -777,12 +777,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" @@ -793,10 +793,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 @@ -823,11 +822,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; } @@ -840,10 +838,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 d0d7c720a6..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 @@ -2067,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.26.2