Commit 03f311edd33191bae9a2b1a89e37d6e2a8363a69

Authored by Paul Brook
1 parent b89e94af

Handle NULL bdrv.

Signed-off-by: Paul Brook <paul@codesourcery.com>
Showing 1 changed file with 10 additions and 4 deletions
... ... @@ -365,7 +365,11 @@ static void sd_reset(SDState *sd, BlockDriverState *bdrv)
365 365 uint32_t size;
366 366 uint64_t sect;
367 367  
368   - bdrv_get_geometry(bdrv, &sect);
  368 + if (bdrv) {
  369 + bdrv_get_geometry(bdrv, &sect);
  370 + } else {
  371 + sect = 0;
  372 + }
369 373 sect <<= 9;
370 374  
371 375 if (sect > 0x40000000)
... ... @@ -388,7 +392,7 @@ static void sd_reset(SDState *sd, BlockDriverState *bdrv)
388 392  
389 393 if (sd->wp_groups)
390 394 qemu_free(sd->wp_groups);
391   - sd->wp_switch = bdrv_is_read_only(bdrv);
  395 + sd->wp_switch = bdrv ? bdrv_is_read_only(bdrv) : 0;
392 396 sd->wp_groups = (int *) qemu_mallocz(sizeof(int) * sect);
393 397 memset(sd->function_group, 0, sizeof(int) * 6);
394 398 sd->erase_start = 0;
... ... @@ -421,7 +425,9 @@ SDState *sd_init(BlockDriverState *bs, int is_spi)
421 425 sd->spi = is_spi;
422 426 sd->enable = 1;
423 427 sd_reset(sd, bs);
424   - bdrv_set_change_cb(sd->bdrv, sd_cardchange, sd);
  428 + if (sd->bdrv) {
  429 + bdrv_set_change_cb(sd->bdrv, sd_cardchange, sd);
  430 + }
425 431 return sd;
426 432 }
427 433  
... ... @@ -1228,7 +1234,7 @@ int sd_do_command(SDState *sd, struct sd_request_s *req,
1228 1234 sd_rsp_type_t rtype;
1229 1235 int rsplen;
1230 1236  
1231   - if (!bdrv_is_inserted(sd->bdrv) || !sd->enable) {
  1237 + if (!sd->bdrv || !bdrv_is_inserted(sd->bdrv) || !sd->enable) {
1232 1238 return 0;
1233 1239 }
1234 1240  
... ...