From patchwork Tue Apr 11 18:50:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 749614 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3w2byD6LJFz9sNb for ; Wed, 12 Apr 2017 05:01:56 +1000 (AEST) Received: from localhost ([::1]:40742 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cy132-0002xY-P7 for incoming@patchwork.ozlabs.org; Tue, 11 Apr 2017 15:01:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48610) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cy0sq-00030s-VC for qemu-devel@nongnu.org; Tue, 11 Apr 2017 14:51:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cy0sq-0004ot-5O for qemu-devel@nongnu.org; Tue, 11 Apr 2017 14:51:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49398) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cy0sm-0004ms-G0; Tue, 11 Apr 2017 14:51:16 -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 mx1.redhat.com (Postfix) with ESMTPS id 7511B4DD62; Tue, 11 Apr 2017 18:51:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7511B4DD62 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7511B4DD62 Received: from red.redhat.com (ovpn-122-61.rdu2.redhat.com [10.10.122.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D24152FBC; Tue, 11 Apr 2017 18:51:14 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 11 Apr 2017 13:50:31 -0500 Message-Id: <20170411185034.13460-11-eblake@redhat.com> In-Reply-To: <20170411185034.13460-1-eblake@redhat.com> References: <20170411185034.13460-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 11 Apr 2017 18:51:15 +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] [PATCH v4 10/13] 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: , Cc: Kevin Wolf , armbru@redhat.com, "open list:Block layer core" , Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- v4: fix -O2 compilation bug, kill dead 'ret' v3: split out from bigger v2 patch --- block.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/block.c b/block.c index c8a6bce..2bf3d40 100644 --- a/block.c +++ b/block.c @@ -2158,7 +2158,7 @@ static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs, char *tmp_filename = g_malloc0(PATH_MAX + 1); int64_t total_size; QemuOpts *opts = NULL; - BlockDriverState *bs_snapshot; + BlockDriverState *bs_snapshot = NULL; Error *local_err = NULL; int ret; @@ -2198,28 +2198,25 @@ static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs, bs_snapshot = bdrv_open(NULL, NULL, snapshot_options, flags, errp); snapshot_options = NULL; if (!bs_snapshot) { - ret = -EINVAL; goto out; } - /* bdrv_append() consumes a strong reference to bs_snapshot (i.e. it will - * 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 = -EINVAL; + bs_snapshot = NULL; goto out; } +out: + QDECREF(snapshot_options); g_free(tmp_filename); return bs_snapshot; - -out: - QDECREF(snapshot_options); - g_free(tmp_filename); - return NULL; } /*