[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 05/37] hw/arm/smmu-common: Simplify smmu_find_smmu_pcibus() logic
From: |
Peter Maydell |
Subject: |
[PULL 05/37] hw/arm/smmu-common: Simplify smmu_find_smmu_pcibus() logic |
Date: |
Thu, 5 Mar 2020 16:30:28 +0000 |
From: Philippe Mathieu-Daudé <address@hidden>
The smmu_find_smmu_pcibus() function was introduced (in commit
cac994ef43b) 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 <address@hidden>
Reviewed-by: Peter Xu <address@hidden>
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
Signed-off-by: Peter Maydell <address@hidden>
---
hw/arm/smmu-common.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c
index 67d7b2d0fd9..e13a5f4a7cb 100644
--- a/hw/arm/smmu-common.c
+++ b/hw/arm/smmu-common.c
@@ -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_pci_bus = s->smmu_pcibus_by_bus_num[bus_num];
+ GHashTableIter iter;
- if (!smmu_pci_bus) {
- GHashTableIter iter;
-
- 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;
+ if (smmu_pci_bus) {
+ return smmu_pci_bus;
}
- 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)
--
2.20.1
- [PULL 00/37] target-arm queue, Peter Maydell, 2020/03/05
- [PULL 02/37] hw/arm: versal: Generate xlnx-versal-virt zdma FDT nodes, Peter Maydell, 2020/03/05
- [PULL 04/37] hw/arm/smmu-common: a fix to smmu_find_smmu_pcibus, Peter Maydell, 2020/03/05
- [PULL 03/37] target/arm: Implement (trivially) ARMv8.2-TTCNP, Peter Maydell, 2020/03/05
- [PULL 06/37] hw/arm/gumstix: Simplify since the machines are little-endian only, Peter Maydell, 2020/03/05
- [PULL 05/37] hw/arm/smmu-common: Simplify smmu_find_smmu_pcibus() logic,
Peter Maydell <=
- [PULL 10/37] hw/arm/musicpal: Simplify since the machines are little-endian only, Peter Maydell, 2020/03/05
- [PULL 09/37] hw/arm/z2: Simplify since the machines are little-endian only, Peter Maydell, 2020/03/05
- [PULL 08/37] hw/arm/omap_sx1: Simplify since the machines are little-endian only, Peter Maydell, 2020/03/05
- [PULL 11/37] hw/arm/pxa2xx: move timer_new from init() into realize() to avoid memleaks, Peter Maydell, 2020/03/05
- [PULL 15/37] target/arm: Improve masking of HCR/HCR2 RES0 bits, Peter Maydell, 2020/03/05
- [PULL 16/37] target/arm: Add HCR_EL2 bit definitions from ARMv8.6, Peter Maydell, 2020/03/05
- [PULL 18/37] target/arm: Remove EL2 and EL3 setup from user-only, Peter Maydell, 2020/03/05
- [PULL 21/37] target/arm: Honor the HCR_EL2.TSW bit, Peter Maydell, 2020/03/05
- [PULL 22/37] target/arm: Honor the HCR_EL2.TACR bit, Peter Maydell, 2020/03/05
- [PULL 24/37] target/arm: Honor the HCR_EL2.TPU bit, Peter Maydell, 2020/03/05