From nobody Sat Feb 7 06:20:37 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1494317323902937.3505936938726; Tue, 9 May 2017 01:08:43 -0700 (PDT) Received: from localhost ([::1]:35636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d80CH-0001Mh-2D for importer@patchew.org; Tue, 09 May 2017 04:08:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d80Aa-00084j-1s for qemu-devel@nongnu.org; Tue, 09 May 2017 04:06:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d80AT-0007Ws-S5 for qemu-devel@nongnu.org; Tue, 09 May 2017 04:06:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42452) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d80AT-0007Vr-LK for qemu-devel@nongnu.org; Tue, 09 May 2017 04:06:49 -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 mx1.redhat.com (Postfix) with ESMTPS id A9F893D953 for ; Tue, 9 May 2017 08:06:48 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-149.ams2.redhat.com [10.36.116.149]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7717A60466; Tue, 9 May 2017 08:06:48 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5AA34113861D; Tue, 9 May 2017 10:06:45 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A9F893D953 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A9F893D953 From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 9 May 2017 10:06:26 +0200 Message-Id: <1494317205-2211-10-git-send-email-armbru@redhat.com> In-Reply-To: <1494317205-2211-1-git-send-email-armbru@redhat.com> References: <1494317205-2211-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 09 May 2017 08:06:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v3 09/28] block: Simplify bdrv_append_temp_snapshot() logic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Eric Blake Noticed while checking Coccinelle results. Naming a label 'out:' when it is only used on error paths is weird. Also, we had some dead stores to 'ret'. Meanwhile we know that snapshot_options is NULL on success and that QDECREF(NULL) is safe. So merge the two exit paths into one by careful control over bs_snapshot. Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster Message-Id: <20170427215821.19397-8-eblake@redhat.com> Signed-off-by: Markus Armbruster --- block.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/block.c b/block.c index aae8f7e..a45b9b5 100644 --- a/block.c +++ b/block.c @@ -2195,7 +2195,7 @@ static BlockDriverState *bdrv_append_temp_snapshot(Bl= ockDriverState *bs, char *tmp_filename =3D g_malloc0(PATH_MAX + 1); int64_t total_size; QemuOpts *opts =3D NULL; - BlockDriverState *bs_snapshot; + BlockDriverState *bs_snapshot =3D NULL; Error *local_err =3D NULL; int ret; =20 @@ -2235,28 +2235,25 @@ static BlockDriverState *bdrv_append_temp_snapshot(= BlockDriverState *bs, bs_snapshot =3D bdrv_open(NULL, NULL, snapshot_options, flags, errp); snapshot_options =3D NULL; if (!bs_snapshot) { - ret =3D -EINVAL; goto out; } =20 - /* bdrv_append() consumes a strong reference to bs_snapshot (i.e. it w= ill - * call bdrv_unref() on it), so in order to be able to return one, we = have - * to increase bs_snapshot's refcount here */ + /* bdrv_append() consumes a strong reference to bs_snapshot + * (i.e. it will call bdrv_unref() on it) even on error, so in + * order to be able to return one, we have to increase + * bs_snapshot's refcount here */ bdrv_ref(bs_snapshot); bdrv_append(bs_snapshot, bs, &local_err); if (local_err) { error_propagate(errp, local_err); - ret =3D -EINVAL; + bs_snapshot =3D NULL; goto out; } =20 +out: + QDECREF(snapshot_options); g_free(tmp_filename); return bs_snapshot; - -out: - QDECREF(snapshot_options); - g_free(tmp_filename); - return NULL; } =20 /* --=20 2.7.4