From patchwork Thu May 24 12:39:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 161134 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id F0E0AB6FD3 for ; Thu, 24 May 2012 22:40:57 +1000 (EST) Received: from localhost ([::1]:36046 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SXXLb-00077D-QO for incoming@patchwork.ozlabs.org; Thu, 24 May 2012 08:40:55 -0400 Received: from eggs.gnu.org ([208.118.235.92]:47882) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SXXLD-00076o-SI for qemu-devel@nongnu.org; Thu, 24 May 2012 08:40:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SXXKa-00039l-FE for qemu-devel@nongnu.org; Thu, 24 May 2012 08:40:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:19836) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SXXKa-00039e-6z for qemu-devel@nongnu.org; Thu, 24 May 2012 08:39:52 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q4OCdoiI017429 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 24 May 2012 08:39:50 -0400 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q4OCdmcm022880; Thu, 24 May 2012 08:39:49 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Thu, 24 May 2012 14:39:48 +0200 Message-Id: <1337863188-6389-1-git-send-email-kwolf@redhat.com> In-Reply-To: <1337857197-5496-1-git-send-email-kwolf@redhat.com> References: <1337857197-5496-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com Subject: [Qemu-devel] [PATCH v2] qcow2: Check qcow2_alloc_clusters_at() return value X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When using qcow2_alloc_clusters_at(), the cluster allocation code checked the wrong variable for an error code. Signed-off-by: Kevin Wolf --- block/qcow2-cluster.c | 23 +++++++++++++---------- 1 files changed, 13 insertions(+), 10 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 2e02241..9aee9fc 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -761,7 +761,6 @@ static int do_alloc_cluster_offset(BlockDriverState *bs, uint64_t guest_offset, uint64_t *host_offset, unsigned int *nb_clusters) { BDRVQcowState *s = bs->opaque; - int64_t cluster_offset; QCowL2Meta *old_alloc; trace_qcow2_do_alloc_clusters_offset(qemu_coroutine_self(), guest_offset, @@ -807,17 +806,21 @@ static int do_alloc_cluster_offset(BlockDriverState *bs, uint64_t guest_offset, /* Allocate new clusters */ trace_qcow2_cluster_alloc_phys(qemu_coroutine_self()); if (*host_offset == 0) { - cluster_offset = qcow2_alloc_clusters(bs, *nb_clusters * s->cluster_size); + int64_t cluster_offset = + qcow2_alloc_clusters(bs, *nb_clusters * s->cluster_size); + if (cluster_offset < 0) { + return cluster_offset; + } + *host_offset = cluster_offset; + return 0; } else { - cluster_offset = *host_offset; - *nb_clusters = qcow2_alloc_clusters_at(bs, cluster_offset, *nb_clusters); - } - - if (cluster_offset < 0) { - return cluster_offset; + int ret = qcow2_alloc_clusters_at(bs, *host_offset, *nb_clusters); + if (ret < 0) { + return ret; + } + *nb_clusters = ret; + return 0; } - *host_offset = cluster_offset; - return 0; } /*