Remove NULL checks for bdrv_new return value
PATCH 1/1 Remove NULL checks for bdrv_new return value
It's an indirect call to qemu_malloc, which never returns an error.
Signed-off-by Kevin Wolf <[email protected]>
--- hw/xen_disk.c | 17 ++++++----------- qemu-img.c | 5 +---- qemu-io.c | 2 -- qemu-nbd.c | 2 -- 4 files changed, 7 insertions(+), 19 deletions(-)
hw/xen_disk.c +6 -11
@@ -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" );
qemu-img.c +1 -4
@@ -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) {
qemu-io.c +0 -2
@@ -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);
qemu-nbd.c +0 -2
@@ -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;
Signature · 1 line
1.7.2.3
PATCH v2 1/1 Remove NULL checks for bdrv_new return value
It's an indirect call to qemu_malloc, which never returns an error.
Signed-off-by Kevin Wolf <[email protected]>
---
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(-)
hw/xen_disk.c +6 -11
@@ -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" );
qemu-img.c +1 -4
@@ -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) {
qemu-io.c +0 -2
@@ -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);
qemu-nbd.c +0 -2
@@ -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;
Signature · 1 line
1.7.2.3
Quoted 5 lines · Kevin Wolf
It's an indirect call to
qemu_malloc, which never returns an error.Signed-off-by Kevin Wolf <[email protected]>---
Quoted 8 lines
v2:
- Fixedbdrv_openfailure case inxen_diskhw/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 <[email protected]>