From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:51438) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYbsy-0004Hv-7n for qemu-devel@nongnu.org; Thu, 08 Dec 2011 06:11:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RYbsx-0005Ot-AL for qemu-devel@nongnu.org; Thu, 08 Dec 2011 06:11:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36618) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYbsx-0005Op-0m for qemu-devel@nongnu.org; Thu, 08 Dec 2011 06:11:31 -0500 Message-ID: <4EE09C1E.4020305@redhat.com> Date: Thu, 08 Dec 2011 12:14:38 +0100 From: Kevin Wolf MIME-Version: 1.0 References: <1323322800-2560-1-git-send-email-zhihuili@linux.vnet.ibm.com> In-Reply-To: <1323322800-2560-1-git-send-email-zhihuili@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] block/cow : return real error code in cow.c List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Li Zhi Hui Cc: qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com Am 08.12.2011 06:40, schrieb Li Zhi Hui: > Signed-off-by: Li Zhi Hui > --- > block/cow.c | 22 ++++++++++++---------- > 1 files changed, 12 insertions(+), 10 deletions(-) > > diff --git a/block/cow.c b/block/cow.c > index 3c52735..383482b 100644 > --- a/block/cow.c > +++ b/block/cow.c > @@ -64,10 +64,11 @@ static int cow_open(BlockDriverState *bs, int flags) > struct cow_header_v2 cow_header; > int bitmap_size; > int64_t size; > + int ret; > > /* see if it is a cow image */ > - if (bdrv_pread(bs->file, 0, &cow_header, sizeof(cow_header)) != > - sizeof(cow_header)) { > + ret = bdrv_pread(bs->file, 0, &cow_header, sizeof(cow_header)); > + if (ret < 0) { > goto fail; > } > More context: if (be32_to_cpu(cow_header.magic) != COW_MAGIC || be32_to_cpu(cow_header.version) != COW_VERSION) { goto fail; } This jumps to fail: with uninitialised ret. Needs to be fixed. > @@ -88,7 +89,7 @@ static int cow_open(BlockDriverState *bs, int flags) > qemu_co_mutex_init(&s->lock); > return 0; > fail: > - return -1; > + return ret; > } > > /* > @@ -182,14 +183,14 @@ static int coroutine_fn cow_read(BlockDriverState *bs, int64_t sector_num, > ret = bdrv_pread(bs->file, > s->cow_sectors_offset + sector_num * 512, > buf, n * 512); > - if (ret != n * 512) > - return -1; > + if (ret < 0) > + return ret; Please add braces here while touching the code. > } else { > if (bs->backing_hd) { > /* read from the base image */ > ret = bdrv_read(bs->backing_hd, sector_num, buf, n); > if (ret < 0) > - return -1; > + return ret; And here. Otherwise the patch looks good to me. Kevin