From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Anthony Liguori <aliguori@us.ibm.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH 08/13] vpc: Fix bdrv_open() error handling
Date: Fri, 1 Feb 2013 15:27:59 +0100 [thread overview]
Message-ID: <1359728884-19422-9-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1359728884-19422-1-git-send-email-stefanha@redhat.com>
From: Kevin Wolf <kwolf@redhat.com>
Return -errno instead of -1 on errors. While touching the
code, fix a memory leak.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
block/vpc.c | 42 ++++++++++++++++++++++++++++++------------
1 file changed, 30 insertions(+), 12 deletions(-)
diff --git a/block/vpc.c b/block/vpc.c
index 7948609..82229ef 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -163,24 +163,33 @@ static int vpc_open(BlockDriverState *bs, int flags)
struct vhd_dyndisk_header* dyndisk_header;
uint8_t buf[HEADER_SIZE];
uint32_t checksum;
- int err = -1;
int disk_type = VHD_DYNAMIC;
+ int ret;
- if (bdrv_pread(bs->file, 0, s->footer_buf, HEADER_SIZE) != HEADER_SIZE)
+ ret = bdrv_pread(bs->file, 0, s->footer_buf, HEADER_SIZE);
+ if (ret < 0) {
goto fail;
+ }
footer = (struct vhd_footer*) s->footer_buf;
if (strncmp(footer->creator, "conectix", 8)) {
int64_t offset = bdrv_getlength(bs->file);
- if (offset < HEADER_SIZE) {
+ if (offset < 0) {
+ ret = offset;
+ goto fail;
+ } else if (offset < HEADER_SIZE) {
+ ret = -EINVAL;
goto fail;
}
+
/* If a fixed disk, the footer is found only at the end of the file */
- if (bdrv_pread(bs->file, offset-HEADER_SIZE, s->footer_buf, HEADER_SIZE)
- != HEADER_SIZE) {
+ ret = bdrv_pread(bs->file, offset-HEADER_SIZE, s->footer_buf,
+ HEADER_SIZE);
+ if (ret < 0) {
goto fail;
}
if (strncmp(footer->creator, "conectix", 8)) {
+ ret = -EMEDIUMTYPE;
goto fail;
}
disk_type = VHD_FIXED;
@@ -203,19 +212,21 @@ static int vpc_open(BlockDriverState *bs, int flags)
/* Allow a maximum disk size of approximately 2 TB */
if (bs->total_sectors >= 65535LL * 255 * 255) {
- err = -EFBIG;
+ ret = -EFBIG;
goto fail;
}
if (disk_type == VHD_DYNAMIC) {
- if (bdrv_pread(bs->file, be64_to_cpu(footer->data_offset), buf,
- HEADER_SIZE) != HEADER_SIZE) {
+ ret = bdrv_pread(bs->file, be64_to_cpu(footer->data_offset), buf,
+ HEADER_SIZE);
+ if (ret < 0) {
goto fail;
}
dyndisk_header = (struct vhd_dyndisk_header *) buf;
if (strncmp(dyndisk_header->magic, "cxsparse", 8)) {
+ ret = -EINVAL;
goto fail;
}
@@ -226,8 +237,10 @@ static int vpc_open(BlockDriverState *bs, int flags)
s->pagetable = g_malloc(s->max_table_entries * 4);
s->bat_offset = be64_to_cpu(dyndisk_header->table_offset);
- if (bdrv_pread(bs->file, s->bat_offset, s->pagetable,
- s->max_table_entries * 4) != s->max_table_entries * 4) {
+
+ ret = bdrv_pread(bs->file, s->bat_offset, s->pagetable,
+ s->max_table_entries * 4);
+ if (ret < 0) {
goto fail;
}
@@ -265,8 +278,13 @@ static int vpc_open(BlockDriverState *bs, int flags)
migrate_add_blocker(s->migration_blocker);
return 0;
- fail:
- return err;
+
+fail:
+ g_free(s->pagetable);
+#ifdef CACHE
+ g_free(s->pageentry_u8);
+#endif
+ return ret;
}
static int vpc_reopen_prepare(BDRVReopenState *state,
--
1.8.1
next prev parent reply other threads:[~2013-02-01 14:28 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-01 14:27 [Qemu-devel] [PULL for-1.4 00/13] Block patches Stefan Hajnoczi
2013-02-01 14:27 ` [Qemu-devel] [PATCH 01/13] qemu-iotests: Add regression test for b7ab0fea Stefan Hajnoczi
2013-02-01 14:27 ` [Qemu-devel] [PATCH 02/13] block: Fix is_allocated_above with resized files Stefan Hajnoczi
2013-02-01 14:27 ` [Qemu-devel] [PATCH 03/13] block: Adds mirroring tests for resized images Stefan Hajnoczi
2013-02-01 14:27 ` [Qemu-devel] [PATCH 04/13] vmdk: Allow selecting SCSI adapter in image creation Stefan Hajnoczi
2013-02-01 14:27 ` [Qemu-devel] [PATCH 05/13] sheepdog: pass vdi_id to sheep daemon for sd_close() Stefan Hajnoczi
2013-02-01 14:27 ` [Qemu-devel] [PATCH 06/13] bochs: Fix bdrv_open() error handling Stefan Hajnoczi
2013-02-01 14:27 ` [Qemu-devel] [PATCH 07/13] cloop: " Stefan Hajnoczi
2013-02-01 14:27 ` Stefan Hajnoczi [this message]
2013-02-01 14:28 ` [Qemu-devel] [PATCH 09/13] dmg: " Stefan Hajnoczi
2013-02-02 12:47 ` Blue Swirl
2013-02-01 14:28 ` [Qemu-devel] [PATCH 10/13] dmg: Use g_free instead of free Stefan Hajnoczi
2013-02-01 14:28 ` [Qemu-devel] [PATCH 11/13] parallels: Fix bdrv_open() error handling Stefan Hajnoczi
2013-02-01 14:28 ` [Qemu-devel] [PATCH 12/13] vmdk: Allow space in file name Stefan Hajnoczi
2013-02-01 14:28 ` [Qemu-devel] [PATCH 13/13] block/raw-posix: Build fix for O_ASYNC Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1359728884-19422-9-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).