aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2013-01-25 17:07:32 +0100
committerStefan Hajnoczi <stefanha@redhat.com>2013-02-01 14:58:29 +0100
commit46536235d80a012cc4286b71426cafad0c7f41f0 (patch)
tree3b821b0c326f44e33d2e4572c364fa49b54b0324
parent4f8aa2e19f88fe0dfaf8240ae666de7fd18dd1d0 (diff)
parallels: Fix bdrv_open() error handling
Return -errno instead of -1 on errors. Hey, no memory leak to fix here while we're touching it! Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
-rw-r--r--block/parallels.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/block/parallels.c b/block/parallels.c
index 377375046f..8688f6ca4c 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -73,14 +73,18 @@ static int parallels_open(BlockDriverState *bs, int flags)
BDRVParallelsState *s = bs->opaque;
int i;
struct parallels_header ph;
+ int ret;
bs->read_only = 1; // no write support yet
- if (bdrv_pread(bs->file, 0, &ph, sizeof(ph)) != sizeof(ph))
+ ret = bdrv_pread(bs->file, 0, &ph, sizeof(ph));
+ if (ret < 0) {
goto fail;
+ }
if (memcmp(ph.magic, HEADER_MAGIC, 16) ||
- (le32_to_cpu(ph.version) != HEADER_VERSION)) {
+ (le32_to_cpu(ph.version) != HEADER_VERSION)) {
+ ret = -EMEDIUMTYPE;
goto fail;
}
@@ -90,18 +94,21 @@ static int parallels_open(BlockDriverState *bs, int flags)
s->catalog_size = le32_to_cpu(ph.catalog_entries);
s->catalog_bitmap = g_malloc(s->catalog_size * 4);
- if (bdrv_pread(bs->file, 64, s->catalog_bitmap, s->catalog_size * 4) !=
- s->catalog_size * 4)
- goto fail;
+
+ ret = bdrv_pread(bs->file, 64, s->catalog_bitmap, s->catalog_size * 4);
+ if (ret < 0) {
+ goto fail;
+ }
+
for (i = 0; i < s->catalog_size; i++)
le32_to_cpus(&s->catalog_bitmap[i]);
qemu_co_mutex_init(&s->lock);
return 0;
+
fail:
- if (s->catalog_bitmap)
- g_free(s->catalog_bitmap);
- return -1;
+ g_free(s->catalog_bitmap);
+ return ret;
}
static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)