drivers: mm: rat: Simplify sys_mm_drv_page_phys_get logic
Instead of tracking if a matching address has been found and then
doing the translation after, we can loop until one is found and
do the translation and return immediately.
This saves having to keep a "found" variable, and makes the code
shorter and more readable IMHO. Do this here.
Signed-off-by: Andrew Davis <afd@ti.com>
diff --git a/drivers/mm/mm_drv_ti_rat.c b/drivers/mm/mm_drv_ti_rat.c
index cc5de67..ee90989 100644
--- a/drivers/mm/mm_drv_ti_rat.c
+++ b/drivers/mm/mm_drv_ti_rat.c
@@ -111,9 +111,7 @@
uintptr_t pa = (uintptr_t) virt;
uintptr_t *va = phys;
- uint32_t found, regionId;
-
- found = 0;
+ uint32_t regionId;
for (regionId = 0; regionId < translate_config.num_regions; regionId++) {
uint64_t start_addr, end_addr;
@@ -126,21 +124,21 @@
end_addr = start_addr + size_mask;
- if (pa >= start_addr && pa <= end_addr) {
- found = 1;
- break;
+ if (pa < start_addr || pa > end_addr) {
+ continue;
}
- }
- if (found) {
+
/* translate input address to output address */
uint32_t offset =
pa - translate_config.region_config[regionId].system_addr;
*va = (translate_config.region_config[regionId].local_addr + offset);
- } else {
- /* no mapping found, set output = input with 32b truncation */
- *va = pa;
+
+ return 0;
}
+ /* no mapping found, set output = input with 32b truncation */
+ *va = pa;
+
return 0;
}