diff --git a/sys/dev/disk/sdhci/sdhci_pci.c b/sys/dev/disk/sdhci/sdhci_pci.c --- a/sys/dev/disk/sdhci/sdhci_pci.c +++ b/sys/dev/disk/sdhci/sdhci_pci.c @@ -428,8 +428,13 @@ rman_get_rid(sc->irq_res), sc->irq_res); pci_release_msi(dev); - for (i = 0; i < sc->num_slots; i++) { - struct sdhci_slot *slot = &sc->slots[i]; + /* mem_res[] is indexed by BAR slot position which can have gaps + * if a slot failed during attach; iterate by BAR position. */ + for (i = 0; i < 6; i++) { + struct sdhci_slot *slot; + if (sc->mem_res[i] == NULL) + continue; + slot = &sc->slots[i]; sdhci_cleanup_slot(slot); bus_release_resource(dev, SYS_RES_MEMORY,