diff options
author | Jan Kiszka <jan.kiszka@siemens.com> | 2011-05-02 20:00:47 +0200 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2011-05-05 16:10:08 +0300 |
commit | 45fe15c25a5c9feea6e0f78434f5e9f632de9d94 (patch) | |
tree | 0749b7fc7f98200e3c42d213b9916be135195151 /hw/msi.c | |
parent | 072476ea08dcffe89b0bd6e2053f01dd89c54861 (diff) |
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>
Diffstat (limited to 'hw/msi.c')
-rw-r--r-- | hw/msi.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -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"); } |