qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
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 11/13] parallels: Fix bdrv_open() error handling
Date: Fri,  1 Feb 2013 15:28:02 +0100	[thread overview]
Message-ID: <1359728884-19422-12-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. 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>
---
 block/parallels.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/block/parallels.c b/block/parallels.c
index 3773750..8688f6c 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)
-- 
1.8.1

  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 ` [Qemu-devel] [PATCH 08/13] vpc: " Stefan Hajnoczi
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 ` Stefan Hajnoczi [this message]
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-12-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).