From: Michal Hocko <mhocko@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, mm-commits@vger.kernel.org,
pugaowei@gmail.com, vbabka@suse.cz, linux-mm@kvack.org
Subject: Re: + mm-mmapc-use-is_err_value-to-check-return-value-of-get_unmapped_area.patch added to -mm tree
Date: Wed, 16 Oct 2019 10:10:30 +0200 [thread overview]
Message-ID: <20191016081030.GM317@dhcp22.suse.cz> (raw)
In-Reply-To: <20191015204819.t_fZYLeEw%akpm@linux-foundation.org>
On Tue 15-10-19 13:48:19, Andrew Morton wrote:
> From: Gaowei Pu <pugaowei@gmail.com>
> Subject: mm/mmap.c: use IS_ERR_VALUE to check return value of get_unmapped_area
>
> get_unmapped_area() returns an address or -errno on failure. Historically
> we have checked for the failure by offset_in_page() which is correct but
> quite hard to read. Newer code started using IS_ERR_VALUE which is much
> easier to read. Convert remaining users of offset_in_page as well.
>
> [mhocko@suse.com: rewrite changelog]
> Link: http://lkml.kernel.org/r/20191012102512.28051-1-pugaowei@gmail.com
> Signed-off-by: Gaowei Pu <pugaowei@gmail.com>
> Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Michal Hocko <mhocko@suse.com>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Michal Hocko <mhocko@suse.com>
There are few more to convert
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 94d38a39d72e..9c197a26c0f4 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1448,7 +1448,7 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
/* Try to map as high as possible, this is only a hint. */
area->vaddr = get_unmapped_area(NULL, TASK_SIZE - PAGE_SIZE,
PAGE_SIZE, 0, 0);
- if (area->vaddr & ~PAGE_MASK) {
+ if (IS_ERR_VALUE(area->vaddr)) {
ret = area->vaddr;
goto fail;
}
diff --git a/mm/mremap.c b/mm/mremap.c
index 1fc8a29fbe3f..122938dcec15 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -558,7 +558,7 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
ret = get_unmapped_area(vma->vm_file, new_addr, new_len, vma->vm_pgoff +
((addr - vma->vm_start) >> PAGE_SHIFT),
map_flags);
- if (offset_in_page(ret))
+ if (IS_ERR_VALUE(ret))
goto out1;
ret = move_vma(vma, addr, old_len, new_len, new_addr, locked, uf,
@@ -706,7 +706,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
vma->vm_pgoff +
((addr - vma->vm_start) >> PAGE_SHIFT),
map_flags);
- if (offset_in_page(new_addr)) {
+ if (IS_ERR_VALUE(new_addr)) {
ret = new_addr;
goto out;
}
and also few more to consider. e.g. move_vma return value checks. I
haven't checked other offset_in_page users.
> ---
>
> mm/mmap.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> --- a/mm/mmap.c~mm-mmapc-use-is_err_value-to-check-return-value-of-get_unmapped_area
> +++ a/mm/mmap.c
> @@ -1417,7 +1417,7 @@ unsigned long do_mmap(struct file *file,
> * that it represents a valid section of the address space.
> */
> addr = get_unmapped_area(file, addr, len, pgoff, flags);
> - if (offset_in_page(addr))
> + if (IS_ERR_VALUE(addr))
> return addr;
>
> if (flags & MAP_FIXED_NOREPLACE) {
> @@ -2996,15 +2996,16 @@ static int do_brk_flags(unsigned long ad
> struct rb_node **rb_link, *rb_parent;
> pgoff_t pgoff = addr >> PAGE_SHIFT;
> int error;
> + unsigned long mapped_addr;
>
> /* Until we need other flags, refuse anything except VM_EXEC. */
> if ((flags & (~VM_EXEC)) != 0)
> return -EINVAL;
> flags |= VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
>
> - error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
> - if (offset_in_page(error))
> - return error;
> + mapped_addr = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
> + if (IS_ERR_VALUE(mapped_addr))
> + return mapped_addr;
>
> error = mlock_future_check(mm, mm->def_flags, len);
> if (error)
> _
>
> Patches currently in -mm which might be from pugaowei@gmail.com are
>
> mm-mmapc-use-is_err_value-to-check-return-value-of-get_unmapped_area.patch
--
Michal Hocko
SUSE Labs
parent reply other threads:[~2019-10-16 8:10 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20191015204819.t_fZYLeEw%akpm@linux-foundation.org>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191016081030.GM317@dhcp22.suse.cz \
--to=mhocko@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mm-commits@vger.kernel.org \
--cc=pugaowei@gmail.com \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox