[PATCH] mm/madvise: Use vma_lookup() instead of find_vma()

Miaohe Lin posted 1 patch 4 years, 3 months ago
There is a newer version of this series
mm/madvise.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] mm/madvise: Use vma_lookup() instead of find_vma()
Posted by Miaohe Lin 4 years, 3 months ago
Using vma_lookup() verifies the start address is contained in the found
vma. This results in easier to read the code.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/madvise.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/madvise.c b/mm/madvise.c
index 5b6d796e55de..afd68bfc77d4 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -883,8 +883,8 @@ static long madvise_populate(struct vm_area_struct *vma,
 		 * our VMA might have been split.
 		 */
 		if (!vma || start >= vma->vm_end) {
-			vma = find_vma(mm, start);
-			if (!vma || start < vma->vm_start)
+			vma = vma_lookup(mm, start);
+			if (!vma)
 				return -ENOMEM;
 		}
 
-- 
2.23.0
Re: [PATCH] mm/madvise: Use vma_lookup() instead of find_vma()
Posted by David Hildenbrand 4 years, 3 months ago
On 11.03.22 09:27, Miaohe Lin wrote:
> Using vma_lookup() verifies the start address is contained in the found
> vma. This results in easier to read the code.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  mm/madvise.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/madvise.c b/mm/madvise.c
> index 5b6d796e55de..afd68bfc77d4 100644
> --- a/mm/madvise.c
> +++ b/mm/madvise.c
> @@ -883,8 +883,8 @@ static long madvise_populate(struct vm_area_struct *vma,
>  		 * our VMA might have been split.
>  		 */
>  		if (!vma || start >= vma->vm_end) {
> -			vma = find_vma(mm, start);
> -			if (!vma || start < vma->vm_start)
> +			vma = vma_lookup(mm, start);
> +			if (!vma)
>  				return -ENOMEM;
>  		}
>  

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb