blk_attach_dev might not be necessary for devices that use a drive-type property. It is not appropriate to make the call unconditional in sd_init.
Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> --- hw/sd/milkymist-memcard.c | 3 +++ hw/sd/omap_mmc.c | 4 ++++ hw/sd/pl181.c | 7 ++++++- hw/sd/pxa2xx_mmci.c | 4 ++++ hw/sd/sd.c | 1 - hw/sd/sdhci.c | 7 ++++++- hw/sd/ssi-sd.c | 7 ++++++- 7 files changed, 29 insertions(+), 4 deletions(-) diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c index 9661eaf..dc81b9b 100644 --- a/hw/sd/milkymist-memcard.c +++ b/hw/sd/milkymist-memcard.c @@ -257,6 +257,9 @@ static int milkymist_memcard_init(SysBusDevice *dev) dinfo = drive_get_next(IF_SD); blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL; + if (blk) { + blk_attach_dev_nofail(blk, s); + } s->card = sd_init(blk, false); if (s->card == NULL) { return -1; diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c index d072dec..f169cb1 100644 --- a/hw/sd/omap_mmc.c +++ b/hw/sd/omap_mmc.c @@ -19,6 +19,7 @@ #include "hw/hw.h" #include "hw/arm/omap.h" #include "hw/sd.h" +#include "sysemu/block-backend.h" struct omap_mmc_s { qemu_irq irq; @@ -621,6 +622,9 @@ struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta, omap_l4_attach(ta, 0, &s->iomem); /* Instantiate the storage */ + if (blk) { + blk_attach_dev_nofail(blk, s); + } s->card = sd_init(blk, false); if (s->card == NULL) { exit(1); diff --git a/hw/sd/pl181.c b/hw/sd/pl181.c index e704b6e..1b7a72f 100644 --- a/hw/sd/pl181.c +++ b/hw/sd/pl181.c @@ -484,6 +484,7 @@ static int pl181_init(SysBusDevice *sbd) DeviceState *dev = DEVICE(sbd); PL181State *s = PL181(dev); DriveInfo *dinfo; + BlockBackend *blk; memory_region_init_io(&s->iomem, OBJECT(s), &pl181_ops, s, "pl181", 0x1000); sysbus_init_mmio(sbd, &s->iomem); @@ -491,7 +492,11 @@ static int pl181_init(SysBusDevice *sbd) sysbus_init_irq(sbd, &s->irq[1]); qdev_init_gpio_out(dev, s->cardstatus, 2); dinfo = drive_get_next(IF_SD); - s->card = sd_init(dinfo ? blk_by_legacy_dinfo(dinfo) : NULL, false); + blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL; + if (blk) { + blk_attach_dev_nofail(blk, s); + } + s->card = sd_init(blk, false); if (s->card == NULL) { return -1; } diff --git a/hw/sd/pxa2xx_mmci.c b/hw/sd/pxa2xx_mmci.c index ac3ab39..0366414 100644 --- a/hw/sd/pxa2xx_mmci.c +++ b/hw/sd/pxa2xx_mmci.c @@ -14,6 +14,7 @@ #include "hw/arm/pxa.h" #include "hw/sd.h" #include "hw/qdev.h" +#include "sysemu/block-backend.h" struct PXA2xxMMCIState { MemoryRegion iomem; @@ -538,6 +539,9 @@ PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem, memory_region_add_subregion(sysmem, base, &s->iomem); /* Instantiate the actual storage */ + if (blk) { + blk_attach_dev_nofail(blk, s); + } s->card = sd_init(blk, false); if (s->card == NULL) { exit(1); diff --git a/hw/sd/sd.c b/hw/sd/sd.c index f955265..794969b 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -494,7 +494,6 @@ SDState *sd_init(BlockBackend *blk, bool is_spi) sd->enable = true; sd_reset(sd, blk); if (sd->blk) { - blk_attach_dev_nofail(sd->blk, sd); blk_set_dev_ops(sd->blk, &sd_block_ops, sd); } vmstate_register(NULL, -1, &sd_vmstate, sd); diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index 27b914a..ed60674 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -1145,9 +1145,14 @@ static inline unsigned int sdhci_get_fifolen(SDHCIState *s) static void sdhci_initfn(SDHCIState *s) { DriveInfo *di; + BlockBackend *blk; di = drive_get_next(IF_SD); - s->card = sd_init(di ? blk_by_legacy_dinfo(di) : NULL, false); + blk = di ? blk_by_legacy_dinfo(di) : NULL; + if (blk) { + blk_attach_dev_nofail(blk, s); + } + s->card = sd_init(blk, false); if (s->card == NULL) { exit(1); } diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c index a71fbca..488b615 100644 --- a/hw/sd/ssi-sd.c +++ b/hw/sd/ssi-sd.c @@ -253,10 +253,15 @@ static int ssi_sd_init(SSISlave *d) DeviceState *dev = DEVICE(d); ssi_sd_state *s = FROM_SSI_SLAVE(ssi_sd_state, d); DriveInfo *dinfo; + BlockBackend *blk; s->mode = SSI_SD_CMD; dinfo = drive_get_next(IF_SD); - s->sd = sd_init(dinfo ? blk_by_legacy_dinfo(dinfo) : NULL, true); + blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL; + if (blk) { + blk_attach_dev_nofail(blk, s); + } + s->sd = sd_init(blk, true); if (s->sd == NULL) { return -1; } -- 2.3.3