diff options
author | Paul Brook <paul@codesourcery.com> | 2009-05-03 16:52:16 +0100 |
---|---|---|
committer | Paul Brook <paul@codesourcery.com> | 2009-05-03 17:00:48 +0100 |
commit | 03f311edd33191bae9a2b1a89e37d6e2a8363a69 (patch) | |
tree | 908d2d0c6adf18304e4477c457ebb91b8d4c2883 | |
parent | b89e94af1dfcf881960804344ac9d2a6759d3aea (diff) |
Handle NULL bdrv.
Signed-off-by: Paul Brook <paul@codesourcery.com>
-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; } |