From nobody Sun Oct 5 19:07:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615306191; cv=none; d=zohomail.com; s=zohoarc; b=F7p+MaBnxthbsEDXOWSuexa1ytG9tQFIx2ddZmbp33yafe8jDcWM7YwYsmj4MXy7ZH2YeTFlQRNmjQheQlt62fHcxzNynRrVCvusUI99dMweP1wuzTZrI6iSzwJ/8NmdkDbKrFyn7tKv52OS+N39Z03wbKRysKK7TCPKASJu+io= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615306191; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=J3L7Oa+V91GwCEYFoUzTtVcz1YdLNdv3gb/3m3iu5cc=; b=AohNO/laTo6IZU/j3x+11oW7eIJ35ddSM9XhWaKntnRG9Wi7/cGQirdetTniCLsHR25PLswpnzaVMas8v3BB3TQ/dGNFW6spSaBpqQ5sZabA0lby/4K/wb4y1rtrkhEZqV8LRhuLZWvYddTRtQpJ6Maw0sKY+38bz9Xo4Rr9fuY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615306191833104.4208395729878; Tue, 9 Mar 2021 08:09:51 -0800 (PST) Received: from localhost ([::1]:60412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJeve-0004BA-MZ for importer@patchew.org; Tue, 09 Mar 2021 11:09:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJef0-000404-Hm for qemu-devel@nongnu.org; Tue, 09 Mar 2021 10:52:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:29863) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lJeeq-0000xr-Ff for qemu-devel@nongnu.org; Tue, 09 Mar 2021 10:52:38 -0500 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-490-hv6cgEerOZ-U4gr0Evgy3g-1; Tue, 09 Mar 2021 10:52:24 -0500 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 B6CD08018A7; Tue, 9 Mar 2021 15:52:22 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-36.phx2.redhat.com [10.3.112.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33D8519C46; Tue, 9 Mar 2021 15:52:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615305147; 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=J3L7Oa+V91GwCEYFoUzTtVcz1YdLNdv3gb/3m3iu5cc=; b=CLu/zy1gUjcc0/ABV4yYgiiK2OoODa0gRhp4S0JCJHg+aXLjCw4dbVvt/KPlWmD4Fe8YuE 5Eq5Fo6FYU9jDTb9lalA4mEcfQQiCu/oVoB8cgJ+SayHA7Qnrptbd6dG2vbr2wj7jdAvzc 8N0+3i72BxscR71q7SrQyEBMzj+vJ0A= X-MC-Unique: hv6cgEerOZ-U4gr0Evgy3g-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PULL 06/17] block: check return value of bdrv_open_child and drop error propagation Date: Tue, 9 Mar 2021 09:51:51 -0600 Message-Id: <20210309155202.1312571-7-eblake@redhat.com> In-Reply-To: <20210309155202.1312571-1-eblake@redhat.com> References: <20210309155202.1312571-1-eblake@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=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.251, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , Stefan Hajnoczi , "open list:blkdebug" , Greg Kurz , Max Reitz , Pavel Dovgalyuk , Paolo Bonzini , Ari Sundholm Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy This patch is generated by cocci script: @@ symbol bdrv_open_child, errp, local_err; expression file; @@ file =3D bdrv_open_child(..., - &local_err + errp ); - if (local_err) + if (!file) { ... - error_propagate(errp, local_err); ... } with command spatch --sp-file x.cocci --macro-file scripts/cocci-macro-file.h \ --in-place --no-show-diff --max-width 80 --use-gitgrep block Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Greg Kurz Reviewed-by: Alberto Garcia Message-Id: <20210202124956.63146-4-vsementsov@virtuozzo.com> [eblake: fix qcow2_do_open() to use ERRP_GUARD, necessary as the only caller to pass allow_none=3Dtrue] Signed-off-by: Eric Blake --- block/blkdebug.c | 6 ++---- block/blklogwrites.c | 10 ++++------ block/blkreplay.c | 6 ++---- block/blkverify.c | 11 ++++------- block/qcow2.c | 6 +++--- block/quorum.c | 6 ++---- 6 files changed, 17 insertions(+), 28 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index 7eaa8a28bf86..2c0b9b0ee85e 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -464,7 +464,6 @@ static int blkdebug_open(BlockDriverState *bs, QDict *o= ptions, int flags, { BDRVBlkdebugState *s =3D bs->opaque; QemuOpts *opts; - Error *local_err =3D NULL; int ret; uint64_t align; @@ -494,10 +493,9 @@ static int blkdebug_open(BlockDriverState *bs, QDict *= options, int flags, bs->file =3D bdrv_open_child(qemu_opt_get(opts, "x-image"), options, "= image", bs, &child_of_bds, BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, &local_err); - if (local_err) { + false, errp); + if (!bs->file) { ret =3D -EINVAL; - error_propagate(errp, local_err); goto out; } diff --git a/block/blklogwrites.c b/block/blklogwrites.c index 13ae63983bc0..b7579370a30a 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -157,19 +157,17 @@ static int blk_log_writes_open(BlockDriverState *bs, = QDict *options, int flags, /* Open the file */ bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, f= alse, - &local_err); - if (local_err) { + errp); + if (!bs->file) { ret =3D -EINVAL; - error_propagate(errp, local_err); goto fail; } /* Open the log file */ s->log_file =3D bdrv_open_child(NULL, options, "log", bs, &child_of_bd= s, - BDRV_CHILD_METADATA, false, &local_err); - if (local_err) { + BDRV_CHILD_METADATA, false, errp); + if (!s->log_file) { ret =3D -EINVAL; - error_propagate(errp, local_err); goto fail; } diff --git a/block/blkreplay.c b/block/blkreplay.c index 30a0f5d57aa0..4a247752fd8f 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -23,16 +23,14 @@ typedef struct Request { static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { - Error *local_err =3D NULL; int ret; /* Open the image file */ bs->file =3D bdrv_open_child(NULL, options, "image", bs, &child_of_bds, BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, &local_err); - if (local_err) { + false, errp); + if (!bs->file) { ret =3D -EINVAL; - error_propagate(errp, local_err); goto fail; } diff --git a/block/blkverify.c b/block/blkverify.c index 943e62be9cf1..188d7632faec 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -112,7 +112,6 @@ static int blkverify_open(BlockDriverState *bs, QDict *= options, int flags, { BDRVBlkverifyState *s =3D bs->opaque; QemuOpts *opts; - Error *local_err =3D NULL; int ret; opts =3D qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); @@ -125,20 +124,18 @@ static int blkverify_open(BlockDriverState *bs, QDict= *options, int flags, bs->file =3D bdrv_open_child(qemu_opt_get(opts, "x-raw"), options, "ra= w", bs, &child_of_bds, BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, - false, &local_err); - if (local_err) { + false, errp); + if (!bs->file) { ret =3D -EINVAL; - error_propagate(errp, local_err); goto fail; } /* Open the test file */ s->test_file =3D bdrv_open_child(qemu_opt_get(opts, "x-image"), option= s, "test", bs, &child_of_bds, BDRV_CHILD_D= ATA, - false, &local_err); - if (local_err) { + false, errp); + if (!s->test_file) { ret =3D -EINVAL; - error_propagate(errp, local_err); goto fail; } diff --git a/block/qcow2.c b/block/qcow2.c index d9f49a52e770..c5266424bb01 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1292,6 +1292,7 @@ static int validate_compression_type(BDRVQcow2State *= s, Error **errp) static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { + ERRP_GUARD(); BDRVQcow2State *s =3D bs->opaque; unsigned int len, i; int ret =3D 0; @@ -1611,9 +1612,8 @@ static int coroutine_fn qcow2_do_open(BlockDriverStat= e *bs, QDict *options, /* Open external data file */ s->data_file =3D bdrv_open_child(NULL, options, "data-file", bs, &child_of_bds, BDRV_CHILD_DATA, - true, &local_err); - if (local_err) { - error_propagate(errp, local_err); + true, errp); + if (*errp) { ret =3D -EINVAL; goto fail; } diff --git a/block/quorum.c b/block/quorum.c index 0bd75450de97..cfc1436abb59 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -929,7 +929,6 @@ static int quorum_open(BlockDriverState *bs, QDict *opt= ions, int flags, Error **errp) { BDRVQuorumState *s =3D bs->opaque; - Error *local_err =3D NULL; QemuOpts *opts =3D NULL; const char *pattern_str; bool *opened; @@ -1007,9 +1006,8 @@ static int quorum_open(BlockDriverState *bs, QDict *o= ptions, int flags, s->children[i] =3D bdrv_open_child(NULL, options, indexstr, bs, &child_of_bds, BDRV_CHILD_DATA, f= alse, - &local_err); - if (local_err) { - error_propagate(errp, local_err); + errp); + if (!s->children[i]) { ret =3D -EINVAL; goto close_exit; } --=20 2.30.1