hw/arm/smmu-common: Simplify smmu_find_smmu_pcibus() logic
The smmu_find_smmu_pcibus() function was introduced (in commit
cac994ef43
) in a code format that could return an incorrect
pointer, which was then fixed by the previous commit.
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).
Acked-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
parent
a2d3b8f24c
commit
5ca0e6fec5
|
@ -290,20 +290,21 @@ inline int smmu_ptw(SMMUTransCfg *cfg, dma_addr_t iova, IOMMUAccessFlags perm,
|
||||||
SMMUPciBus *smmu_find_smmu_pcibus(SMMUState *s, uint8_t bus_num)
|
SMMUPciBus *smmu_find_smmu_pcibus(SMMUState *s, uint8_t bus_num)
|
||||||
{
|
{
|
||||||
SMMUPciBus *smmu_pci_bus = s->smmu_pcibus_by_bus_num[bus_num];
|
SMMUPciBus *smmu_pci_bus = s->smmu_pcibus_by_bus_num[bus_num];
|
||||||
|
GHashTableIter iter;
|
||||||
|
|
||||||
if (!smmu_pci_bus) {
|
if (smmu_pci_bus) {
|
||||||
GHashTableIter iter;
|
return smmu_pci_bus;
|
||||||
|
|
||||||
g_hash_table_iter_init(&iter, s->smmu_pcibus_by_busptr);
|
|
||||||
while (g_hash_table_iter_next(&iter, NULL, (void **)&smmu_pci_bus)) {
|
|
||||||
if (pci_bus_num(smmu_pci_bus->bus) == bus_num) {
|
|
||||||
s->smmu_pcibus_by_bus_num[bus_num] = smmu_pci_bus;
|
|
||||||
return smmu_pci_bus;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
smmu_pci_bus = NULL;
|
|
||||||
}
|
}
|
||||||
return smmu_pci_bus;
|
|
||||||
|
g_hash_table_iter_init(&iter, s->smmu_pcibus_by_busptr);
|
||||||
|
while (g_hash_table_iter_next(&iter, NULL, (void **)&smmu_pci_bus)) {
|
||||||
|
if (pci_bus_num(smmu_pci_bus->bus) == bus_num) {
|
||||||
|
s->smmu_pcibus_by_bus_num[bus_num] = smmu_pci_bus;
|
||||||
|
return smmu_pci_bus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static AddressSpace *smmu_find_add_as(PCIBus *bus, void *opaque, int devfn)
|
static AddressSpace *smmu_find_add_as(PCIBus *bus, void *opaque, int devfn)
|
||||||
|
|
Loading…
Reference in a new issue