aboutsummaryrefslogtreecommitdiff
path: root/hw/i386
diff options
context:
space:
mode:
authorPhilippe Mathieu-Daudé <philmd@redhat.com>2020-03-05 11:27:02 +0100
committerMichael S. Tsirkin <mst@redhat.com>2020-03-08 09:27:09 -0400
commita6f65f4fc217713ee2c78b99baae1cc31c761778 (patch)
tree1a43b58ded6129084fda0047909f563bbc5ed2b7 /hw/i386
parentf1e92c3d52d2223306a1ea289a57fca2bc5c40a5 (diff)
downloadqemu-a6f65f4fc217713ee2c78b99baae1cc31c761778.zip
qemu-a6f65f4fc217713ee2c78b99baae1cc31c761778.tar.gz
qemu-a6f65f4fc217713ee2c78b99baae1cc31c761778.tar.bz2
hw/i386/intel_iommu: Simplify vtd_find_as_from_bus_num() logic
The vtd_find_as_from_bus_num() function was introduced (in commit dbaabb25f) in a code format that could return an incorrect pointer, which was later fixed by commit a2e1cd41ccf. We could have avoided this by writing the if() statement differently. Do it now, in case this function is re-used. The code is easier to review (harder to miss bugs). Reviewed-by: Peter Xu <peterx@redhat.com> Reviewed-by: Eric Auger <eric.auger@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20200305102702.31512-1-philmd@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'hw/i386')
-rw-r--r--hw/i386/intel_iommu.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 6258c58..204b684 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -987,24 +987,26 @@ static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level)
static VTDBus *vtd_find_as_from_bus_num(IntelIOMMUState *s, uint8_t bus_num)
{
VTDBus *vtd_bus = s->vtd_as_by_bus_num[bus_num];
- if (!vtd_bus) {
- /*
- * Iterate over the registered buses to find the one which
- * currently hold this bus number, and update the bus_num
- * lookup table:
- */
- GHashTableIter iter;
+ GHashTableIter iter;
- g_hash_table_iter_init(&iter, s->vtd_as_by_busptr);
- while (g_hash_table_iter_next(&iter, NULL, (void **)&vtd_bus)) {
- if (pci_bus_num(vtd_bus->bus) == bus_num) {
- s->vtd_as_by_bus_num[bus_num] = vtd_bus;
- return vtd_bus;
- }
+ if (vtd_bus) {
+ return vtd_bus;
+ }
+
+ /*
+ * Iterate over the registered buses to find the one which
+ * currently holds this bus number and update the bus_num
+ * lookup table.
+ */
+ g_hash_table_iter_init(&iter, s->vtd_as_by_busptr);
+ while (g_hash_table_iter_next(&iter, NULL, (void **)&vtd_bus)) {
+ if (pci_bus_num(vtd_bus->bus) == bus_num) {
+ s->vtd_as_by_bus_num[bus_num] = vtd_bus;
+ return vtd_bus;
}
- vtd_bus = NULL;
}
- return vtd_bus;
+
+ return NULL;
}
/* Given the @iova, get relevant @slptep. @slpte_level will be the last level