@samitouri / QOSamiQemu / commits / 64d3884bbf

target/riscv: De-indent some code in get_physical_address()

get_physical_address() is quite complex already. In order to make the two next commits simplers, de-indent one if() ladder. No logical change intended. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> Message-ID: <20260527201348.29511-5-philmd@linaro.org> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Philippe Mathieu-Daudé committed May 27, 2026 at 22:13 UTC 64d3884bbfe9b7abef2919bc3f0234afec7a1866
1 file changed +18 -15
target/riscv/cpu_helper.c
+18 -15
@@ -1667,27 +1667,30 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
1667 hwaddr l = sxlen_bytes, addr1;
1668 mr = address_space_translate(cs->as, pte_addr, &addr1, &l,
1669 false, MEMTXATTRS_UNSPECIFIED);
1670 - if (memory_region_is_ram(mr)) {
1671 - target_ulong *pte_pa = qemu_map_ram_ptr(mr->ram_block, addr1);
1672 - target_ulong old_pte;
1673 - if (riscv_cpu_sxl(env) == MXL_RV32) {
1674 - old_pte = qatomic_cmpxchg((uint32_t *)pte_pa, cpu_to_le32(pte), cpu_to_le32(updated_pte));
1675 - old_pte = le32_to_cpu(old_pte);
1676 - } else {
1677 - old_pte = qatomic_cmpxchg(pte_pa, cpu_to_le64(pte), cpu_to_le64(updated_pte));
1678 - old_pte = le64_to_cpu(old_pte);
1679 - }
1680 - if (old_pte != pte) {
1681 - goto restart;
1682 - }
1683 - pte = updated_pte;
1684 - } else {
1670 + if (!memory_region_is_ram(mr)) {
1671 /*
1672 * Misconfigured PTE in ROM (AD bits are not preset) or
1673 * PTE is in IO space and can't be updated atomically.
1674 */
1675 return TRANSLATE_FAIL;
1676 }
1677 +
1678 + target_ulong *pte_pa = qemu_map_ram_ptr(mr->ram_block, addr1);
1679 + target_ulong old_pte;
1680 +
1681 + if (riscv_cpu_sxl(env) == MXL_RV32) {
1682 + old_pte = qatomic_cmpxchg((uint32_t *)pte_pa, cpu_to_le32(pte),
1683 + cpu_to_le32(updated_pte));
1684 + old_pte = le32_to_cpu(old_pte);
1685 + } else {
1686 + old_pte = qatomic_cmpxchg(pte_pa, cpu_to_le64(pte),
1687 + cpu_to_le64(updated_pte));
1688 + old_pte = le64_to_cpu(old_pte);
1689 + }
1690 + if (old_pte != pte) {
1691 + goto restart;
1692 + }
1693 + pte = updated_pte;
1694 }
1695
1696 /* For superpage mappings, make a fake leaf PTE for the TLB's benefit. */