vma_address_end() is a confusing function with a lot of moving parts so
clean it up prior to extending it for anon page indexed mappings.

Const-ify some variables and establish pgoff_vma_start and pgoff_end
variables to clearly identify the page offset for the start of the VMA and
the end of the page offset range specified by the page walk.

This simplifies the function significantly and lays the groundwork for a
future change to update this function to account for anonymously page
indexed folios.

No functional change intended.

Signed-off-by: Lorenzo Stoakes (ARM) <[email protected]>
---
 mm/internal.h | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/mm/internal.h b/mm/internal.h
index 03145b8d0d56..98b067472ceb 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -1079,22 +1079,24 @@ static inline unsigned long vma_anon_address(const 
struct vm_area_struct *vma,
 }
 
 /*
- * Then at what user virtual address will none of the range be found in vma?
+ * At what user virtual address will none of the range be found in vma?
  * Assumes that vma_address() already returned a good starting address.
  */
 static inline unsigned long vma_address_end(struct page_vma_mapped_walk *pvmw)
 {
-       struct vm_area_struct *vma = pvmw->vma;
-       pgoff_t pgoff;
+       const pgoff_t pgoff_end = pvmw->pgoff + pvmw->nr_pages;
+       const struct vm_area_struct *vma = pvmw->vma;
+       pgoff_t pgoff_vma_start;
        unsigned long address;
 
        /* Common case, plus ->pgoff is invalid for KSM */
        if (pvmw->nr_pages == 1)
                return pvmw->address + PAGE_SIZE;
 
-       pgoff = pvmw->pgoff + pvmw->nr_pages;
+       pgoff_vma_start = vma_start_pgoff(vma);
+
        address = vma->vm_start +
-               ((pgoff - vma_start_pgoff(vma)) << PAGE_SHIFT);
+               ((pgoff_end - pgoff_vma_start) << PAGE_SHIFT);
        /* Check for address beyond vma (or wrapped through 0?) */
        if (address < vma->vm_start || address > vma->vm_end)
                address = vma->vm_end;

-- 
2.55.0


Reply via email to