* [Qemu-devel] [PATCH] Remove NULL checks for bdrv_new return value
@ 2010-12-16 14:39 Kevin Wolf
2010-12-16 14:44 ` [Qemu-devel] [PATCH v2] " Kevin Wolf
0 siblings, 1 reply; 3+ messages in thread
From: Kevin Wolf @ 2010-12-16 14:39 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf
It's an indirect call to qemu_malloc, which never returns an error.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/xen_disk.c | 17 ++++++-----------
qemu-img.c | 5 +----
qemu-io.c | 2 --
qemu-nbd.c | 2 --
4 files changed, 7 insertions(+), 19 deletions(-)
diff --git a/hw/xen_disk.c b/hw/xen_disk.c
index 85a1c85..1954311 100644
--- a/hw/xen_disk.c
+++ b/hw/xen_disk.c
@@ -634,17 +634,12 @@ static int blk_init(struct XenDevice *xendev)
if (!blkdev->dinfo) {
/* setup via xenbus -> create new block driver instance */
xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
- blkdev->bs = bdrv_new(blkdev->dev);
- if (blkdev->bs) {
- if (bdrv_open(blkdev->bs, blkdev->filename, qflags,
- bdrv_find_whitelisted_format(blkdev->fileproto))
- != 0) {
- bdrv_delete(blkdev->bs);
- blkdev->bs = NULL;
- }
- }
- if (!blkdev->bs)
- return -1;
+ blkdev->bs = bdrv_new(blkdev->dev);
+ if (bdrv_open(blkdev->bs, blkdev->filename, qflags,
+ bdrv_find_whitelisted_format(blkdev->fileproto)) != 0) {
+ bdrv_delete(blkdev->bs);
+ blkdev->bs = NULL;
+ }
} else {
/* setup via qemu cmdline -> already setup for us */
xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline setup)\n");
diff --git a/qemu-img.c b/qemu-img.c
index 0b871d8..afd9ed2 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -215,10 +215,7 @@ static BlockDriverState *bdrv_new_open(const char *filename,
char password[256];
bs = bdrv_new("");
- if (!bs) {
- error_report("Not enough memory");
- goto fail;
- }
+
if (fmt) {
drv = bdrv_find_format(fmt);
if (!drv) {
diff --git a/qemu-io.c b/qemu-io.c
index ff353eb..0f6d1b6 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -1509,8 +1509,6 @@ static int openfile(char *name, int flags, int growable)
}
} else {
bs = bdrv_new("hda");
- if (!bs)
- return 1;
if (bdrv_open(bs, name, flags, NULL) < 0) {
fprintf(stderr, "%s: can't open device %s\n", progname, name);
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 99f1d22..e858033 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -336,8 +336,6 @@ int main(int argc, char **argv)
bdrv_init();
bs = bdrv_new("hda");
- if (bs == NULL)
- return 1;
if ((ret = bdrv_open(bs, argv[optind], flags, NULL)) < 0) {
errno = -ret;
--
1.7.2.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH v2] Remove NULL checks for bdrv_new return value
2010-12-16 14:39 [Qemu-devel] [PATCH] Remove NULL checks for bdrv_new return value Kevin Wolf
@ 2010-12-16 14:44 ` Kevin Wolf
2010-12-16 17:48 ` Stefan Hajnoczi
0 siblings, 1 reply; 3+ messages in thread
From: Kevin Wolf @ 2010-12-16 14:44 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf
It's an indirect call to qemu_malloc, which never returns an error.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
v2:
- Fixed bdrv_open failure case in xen_disk
hw/xen_disk.c | 17 ++++++-----------
qemu-img.c | 5 +----
qemu-io.c | 2 --
qemu-nbd.c | 2 --
4 files changed, 7 insertions(+), 19 deletions(-)
diff --git a/hw/xen_disk.c b/hw/xen_disk.c
index 85a1c85..ed9e5eb 100644
--- a/hw/xen_disk.c
+++ b/hw/xen_disk.c
@@ -634,17 +634,12 @@ static int blk_init(struct XenDevice *xendev)
if (!blkdev->dinfo) {
/* setup via xenbus -> create new block driver instance */
xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
- blkdev->bs = bdrv_new(blkdev->dev);
- if (blkdev->bs) {
- if (bdrv_open(blkdev->bs, blkdev->filename, qflags,
- bdrv_find_whitelisted_format(blkdev->fileproto))
- != 0) {
- bdrv_delete(blkdev->bs);
- blkdev->bs = NULL;
- }
- }
- if (!blkdev->bs)
- return -1;
+ blkdev->bs = bdrv_new(blkdev->dev);
+ if (bdrv_open(blkdev->bs, blkdev->filename, qflags,
+ bdrv_find_whitelisted_format(blkdev->fileproto)) != 0) {
+ bdrv_delete(blkdev->bs);
+ return -1;
+ }
} else {
/* setup via qemu cmdline -> already setup for us */
xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline setup)\n");
diff --git a/qemu-img.c b/qemu-img.c
index 0b871d8..afd9ed2 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -215,10 +215,7 @@ static BlockDriverState *bdrv_new_open(const char *filename,
char password[256];
bs = bdrv_new("");
- if (!bs) {
- error_report("Not enough memory");
- goto fail;
- }
+
if (fmt) {
drv = bdrv_find_format(fmt);
if (!drv) {
diff --git a/qemu-io.c b/qemu-io.c
index ff353eb..0f6d1b6 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -1509,8 +1509,6 @@ static int openfile(char *name, int flags, int growable)
}
} else {
bs = bdrv_new("hda");
- if (!bs)
- return 1;
if (bdrv_open(bs, name, flags, NULL) < 0) {
fprintf(stderr, "%s: can't open device %s\n", progname, name);
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 99f1d22..e858033 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -336,8 +336,6 @@ int main(int argc, char **argv)
bdrv_init();
bs = bdrv_new("hda");
- if (bs == NULL)
- return 1;
if ((ret = bdrv_open(bs, argv[optind], flags, NULL)) < 0) {
errno = -ret;
--
1.7.2.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] Remove NULL checks for bdrv_new return value
2010-12-16 14:44 ` [Qemu-devel] [PATCH v2] " Kevin Wolf
@ 2010-12-16 17:48 ` Stefan Hajnoczi
0 siblings, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2010-12-16 17:48 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-devel
On Thu, Dec 16, 2010 at 2:44 PM, Kevin Wolf <kwolf@redhat.com> wrote:
> It's an indirect call to qemu_malloc, which never returns an error.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>
> v2:
> - Fixed bdrv_open failure case in xen_disk
>
> hw/xen_disk.c | 17 ++++++-----------
> qemu-img.c | 5 +----
> qemu-io.c | 2 --
> qemu-nbd.c | 2 --
> 4 files changed, 7 insertions(+), 19 deletions(-)
Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-12-16 17:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-16 14:39 [Qemu-devel] [PATCH] Remove NULL checks for bdrv_new return value Kevin Wolf
2010-12-16 14:44 ` [Qemu-devel] [PATCH v2] " Kevin Wolf
2010-12-16 17:48 ` Stefan Hajnoczi
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).