From 03f311edd33191bae9a2b1a89e37d6e2a8363a69 Mon Sep 17 00:00:00 2001 From: Paul Brook Date: Sun, 3 May 2009 16:52:16 +0100 Subject: Handle NULL bdrv. Signed-off-by: Paul Brook --- hw/sd.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'hw/sd.c') diff --git a/hw/sd.c b/hw/sd.c index 4618883fa6..284cd08840 100644 --- a/hw/sd.c +++ b/hw/sd.c @@ -365,7 +365,11 @@ static void sd_reset(SDState *sd, BlockDriverState *bdrv) uint32_t size; uint64_t sect; - bdrv_get_geometry(bdrv, §); + if (bdrv) { + bdrv_get_geometry(bdrv, §); + } else { + sect = 0; + } sect <<= 9; if (sect > 0x40000000) @@ -388,7 +392,7 @@ static void sd_reset(SDState *sd, BlockDriverState *bdrv) if (sd->wp_groups) qemu_free(sd->wp_groups); - sd->wp_switch = bdrv_is_read_only(bdrv); + sd->wp_switch = bdrv ? bdrv_is_read_only(bdrv) : 0; sd->wp_groups = (int *) qemu_mallocz(sizeof(int) * sect); memset(sd->function_group, 0, sizeof(int) * 6); sd->erase_start = 0; @@ -421,7 +425,9 @@ SDState *sd_init(BlockDriverState *bs, int is_spi) sd->spi = is_spi; sd->enable = 1; sd_reset(sd, bs); - bdrv_set_change_cb(sd->bdrv, sd_cardchange, sd); + if (sd->bdrv) { + bdrv_set_change_cb(sd->bdrv, sd_cardchange, sd); + } return sd; } @@ -1228,7 +1234,7 @@ int sd_do_command(SDState *sd, struct sd_request_s *req, sd_rsp_type_t rtype; int rsplen; - if (!bdrv_is_inserted(sd->bdrv) || !sd->enable) { + if (!sd->bdrv || !bdrv_is_inserted(sd->bdrv) || !sd->enable) { return 0; } -- cgit v1.2.3