From: Ahmad Fatoum <a.fat...@pengutronix.de>

regmap_range operates on regions identified by start and size, but for
mmu_remap_memory_bank, we operate on the (exclusive) region end instead.

Make the code easier to reason about by using a regmap_range_end()
helper. This is intentionally not exported and functions that operate on
an end are error-prone with respect to whether the range end is
inclusive or exclusive.

Signed-off-by: Ahmad Fatoum <a.fat...@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fat...@barebox.org>
---
 arch/arm/cpu/mmu-common.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/arch/arm/cpu/mmu-common.c b/arch/arm/cpu/mmu-common.c
index 85cb7cb007b9..4c30f98cbd79 100644
--- a/arch/arm/cpu/mmu-common.c
+++ b/arch/arm/cpu/mmu-common.c
@@ -69,6 +69,19 @@ void zero_page_faulting(void)
        remap_range(0x0, PAGE_SIZE, MAP_FAULT);
 }
 
+/**
+ * remap_range_end - remap a range identified by [start, end)
+ *
+ * @start:    start of the range
+ * @end:      end of the first range (exclusive)
+ * @map_type: mapping type to apply
+ */
+static inline void remap_range_end(unsigned long start, unsigned long end,
+                                  unsigned map_type)
+{
+       remap_range((void *)start, end - start, map_type);
+}
+
 static void mmu_remap_memory_banks(void)
 {
        struct memory_bank *bank;
@@ -87,11 +100,11 @@ static void mmu_remap_memory_banks(void)
 
                /* Skip reserved regions */
                for_each_reserved_region(bank, rsv) {
-                       remap_range((void *)pos, rsv->start - pos, MAP_CACHED);
+                       remap_range_end(pos, rsv->start, MAP_CACHED);
                        pos = rsv->end + 1;
                }
 
-               remap_range((void *)pos, bank->start + bank->size - pos, 
MAP_CACHED);
+               remap_range_end(pos, bank->start + bank->size, MAP_CACHED);
        }
 
        setup_trap_pages();
-- 
2.39.5


Reply via email to