From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NWqTJ-0006hV-HW for qemu-devel@nongnu.org; Mon, 18 Jan 2010 07:12:41 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NWqTE-0006gL-0s for qemu-devel@nongnu.org; Mon, 18 Jan 2010 07:12:41 -0500 Received: from [199.232.76.173] (port=51035 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NWqTD-0006gI-Sd for qemu-devel@nongnu.org; Mon, 18 Jan 2010 07:12:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:3891) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NWqTD-0001b6-HC for qemu-devel@nongnu.org; Mon, 18 Jan 2010 07:12:35 -0500 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0ICCYU1029098 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 18 Jan 2010 07:12:34 -0500 From: Kevin Wolf Date: Mon, 18 Jan 2010 13:11:27 +0100 Message-Id: <1263816696-24122-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1263816696-24122-1-git-send-email-kwolf@redhat.com> References: <1263816696-24122-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 01/10] qcow2: Fix error handling in qcow2_grow_l1_table List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf Return the appropriate error value instead of always using EIO. Don't free the L1 table on errors, we still need it. Signed-off-by: Kevin Wolf --- block/qcow2-cluster.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index f88118c..adddf56 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -67,9 +67,10 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size) /* set new table */ cpu_to_be32w((uint32_t*)data, new_l1_size); cpu_to_be64w((uint64_t*)(data + 4), new_l1_table_offset); - if (bdrv_pwrite(s->hd, offsetof(QCowHeader, l1_size), data, - sizeof(data)) != sizeof(data)) + ret = bdrv_pwrite(s->hd, offsetof(QCowHeader, l1_size), data,sizeof(data)); + if (ret != sizeof(data)) { goto fail; + } qemu_free(s->l1_table); qcow2_free_clusters(bs, s->l1_table_offset, s->l1_size * sizeof(uint64_t)); s->l1_table_offset = new_l1_table_offset; @@ -77,8 +78,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size) s->l1_size = new_l1_size; return 0; fail: - qemu_free(s->l1_table); - return -EIO; + return ret < 0 ? ret : -EIO; } void qcow2_l2_cache_reset(BlockDriverState *bs) -- 1.6.2.5