MSI: Robust resource release
msi_init may fail, so we need to check on uninit if the cap was actually installed. This also avoids that the users need to check. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
072476ea08
commit
45fe15c25a
@ -110,10 +110,7 @@ static int pci_ich9_uninit(PCIDevice *dev)
|
||||
struct AHCIPCIState *d;
|
||||
d = DO_UPCAST(struct AHCIPCIState, card, dev);
|
||||
|
||||
if (msi_enabled(dev)) {
|
||||
msi_uninit(dev);
|
||||
}
|
||||
|
||||
msi_uninit(dev);
|
||||
qemu_unregister_reset(ahci_reset, d);
|
||||
ahci_uninit(&d->ahci);
|
||||
|
||||
|
@ -1165,9 +1165,7 @@ static int intel_hda_exit(PCIDevice *pci)
|
||||
{
|
||||
IntelHDAState *d = DO_UPCAST(IntelHDAState, pci, pci);
|
||||
|
||||
if (d->msi) {
|
||||
msi_uninit(&d->pci);
|
||||
}
|
||||
msi_uninit(&d->pci);
|
||||
cpu_unregister_io_memory(d->mmio_addr);
|
||||
return 0;
|
||||
}
|
||||
|
12
hw/msi.c
12
hw/msi.c
@ -164,9 +164,17 @@ int msi_init(struct PCIDevice *dev, uint8_t offset,
|
||||
|
||||
void msi_uninit(struct PCIDevice *dev)
|
||||
{
|
||||
uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev));
|
||||
uint8_t cap_size = msi_cap_sizeof(flags);
|
||||
uint16_t flags;
|
||||
uint8_t cap_size;
|
||||
|
||||
if (!(dev->cap_present & QEMU_PCI_CAP_MSI)) {
|
||||
return;
|
||||
}
|
||||
flags = pci_get_word(dev->config + msi_flags_off(dev));
|
||||
cap_size = msi_cap_sizeof(flags);
|
||||
pci_del_capability(dev, PCI_CAP_ID_MSIX, cap_size);
|
||||
dev->cap_present &= ~QEMU_PCI_CAP_MSI;
|
||||
|
||||
MSI_DEV_PRINTF(dev, "uninit\n");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user