From: Liam R. Howlett Date: Thu, 4 Feb 2021 01:07:37 +0000 (-0500) Subject: mm/mmap: Fix alignment mess of gap searching X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=cbcbbd05dcc995f657c39f40ce4325a29e673db4;p=users%2Fjedix%2Flinux-maple.git mm/mmap: Fix alignment mess of gap searching Signed-off-by: Liam R. Howlett --- diff --git a/mm/mmap.c b/mm/mmap.c index 61af80f654e4..e8a295663759 100644 --- 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;