diff options
Diffstat (limited to 'hw/sd.c')
-rw-r--r-- | hw/sd.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -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; } |