OSDN Git Service

sd: Avoid access to NULL BlockDriverState
authorAndreas Färber <afaerber@suse.de>
Wed, 16 Oct 2013 13:24:01 +0000 (15:24 +0200)
committerStefan Hajnoczi <stefanha@redhat.com>
Thu, 17 Oct 2013 08:15:18 +0000 (10:15 +0200)
Commit 4f8a066b5fc254eeaabbbde56ba4f5b29cc68fdf (blockdev: Remove IF_*
check for read-only blockdev_init) added a usage of bdrv_is_read_only()
to sd_init(), which is called for versatilepb, versatileab and
xilinx-zynq-a9 machines among others with NULL argument by default,
causing the new qom-test to fail.

Add a check to prevent this.

Suggested-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
hw/sd/sd.c

index 7380f06..4502ad1 100644 (file)
@@ -494,7 +494,7 @@ SDState *sd_init(BlockDriverState *bs, bool is_spi)
 {
     SDState *sd;
 
-    if (bdrv_is_read_only(bs)) {
+    if (bs && bdrv_is_read_only(bs)) {
         fprintf(stderr, "sd_init: Cannot use read-only drive\n");
         return NULL;
     }