]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm/mmap: Fix alignment mess of gap searching
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Thu, 4 Feb 2021 01:07:37 +0000 (20:07 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Thu, 4 Feb 2021 01:09:58 +0000 (20:09 -0500)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
mm/mmap.c

index 61af80f654e42d86c4c552b4cab009f56e727dcd..e8a29566375994ee2cca810707394eaca34ecfed 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1623,9 +1623,9 @@ static unsigned long unmapped_area(struct vm_unmapped_area_info *info)
                        rcu_read_unlock();
                        return -ENOMEM;
                }
-               gap = mas.index & ~(info->align_mask);
-               gap += info->align_offset;
-       } while ((gap < mas.index) && (gap > mas.last - info->length + 1));
+               gap = mas.index;
+               gap += (info->align_offset - mas.index) & info->align_mask;
+       } while ((mas.index > gap) && (gap > mas.last - info->length + 1));
        rcu_read_unlock();
 
        return gap;
@@ -1655,10 +1655,9 @@ static unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
                        return -ENOMEM;
                }
 
-               gap = mas.last - info->length + 1;
-               gap &= ~(info->align_mask);
-               gap += info->align_offset;
-       } while (mas.index > gap);
+               gap = mas.last + 1 - info->length;
+               gap -= (gap - info->align_offset) & info->align_mask;
+       } while ((mas.index > gap) && (mas.last > gap + info->length - 1));
        rcu_read_unlock();
 
        return gap;