Linux-mm Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] mm/mmap.c: use IS_ERR_VALUE to check return value of get_unmapped_area
@ 2019-10-10  3:31 Gaowei Pu
  2019-10-12  2:19 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Gaowei Pu @ 2019-10-10  3:31 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Vlastimil Babka, linux-mm

get_unmapped_area already cover the offset_in_page() check and returned
with error ptr. So replace offset_in_page() with IS_ERR_VALUE().

Signed-off-by: Gaowei Pu <pugaowei@gmail.com>
---
 mm/mmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index 7e8c3e8ae75f..66cd88b2abb7 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1430,7 +1430,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr,
 	 * 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) {
@@ -2997,7 +2997,7 @@ static int do_brk_flags(unsigned long addr, unsigned long len, unsigned long fla
 	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))
+	if (IS_ERR_VALUE(error))
 		return error;
 
 	error = mlock_future_check(mm, mm->def_flags, len);
-- 
2.22.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/mmap.c: use IS_ERR_VALUE to check return value of get_unmapped_area
  2019-10-10  3:31 [PATCH] mm/mmap.c: use IS_ERR_VALUE to check return value of get_unmapped_area Gaowei Pu
@ 2019-10-12  2:19 ` Andrew Morton
  2019-10-12  9:41   ` gaowei Pu
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2019-10-12  2:19 UTC (permalink / raw)
  To: Gaowei Pu; +Cc: Vlastimil Babka, linux-mm

On Thu, 10 Oct 2019 11:31:17 +0800 Gaowei Pu <pugaowei@gmail.com> wrote:

> get_unmapped_area already cover the offset_in_page() check and returned
> with error ptr. So replace offset_in_page() with IS_ERR_VALUE().
> 
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -2997,7 +2997,7 @@ static int do_brk_flags(unsigned long addr, unsigned long len, unsigned long fla
>  	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))
> +	if (IS_ERR_VALUE(error))
>  		return error;
>  
>  	error = mlock_future_check(mm, mm->def_flags, len);

./include/linux/err.h:22:49: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
 #define IS_ERR_VALUE(x) unlikely((unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO)
                                                 ^
./include/linux/compiler.h:78:42: note: in definition of macro unlikely
 # define unlikely(x) __builtin_expect(!!(x), 0)
                                          ^
mm/mmap.c:3006:6: note: in expansion of macro IS_ERR_VALUE
  if (IS_ERR_VALUE(error))



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/mmap.c: use IS_ERR_VALUE to check return value of get_unmapped_area
  2019-10-12  2:19 ` Andrew Morton
@ 2019-10-12  9:41   ` gaowei Pu
  0 siblings, 0 replies; 3+ messages in thread
From: gaowei Pu @ 2019-10-12  9:41 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Vlastimil Babka, linux-mm

[-- Attachment #1: Type: text/plain, Size: 678 bytes --]

Andrew Morton <akpm@linux-foundation.org> 于2019年10月12日周六 上午10:19写道:

>
> ./include/linux/err.h:22:49: warning: cast to pointer from integer of
> different size [-Wint-to-pointer-cast]
>  #define IS_ERR_VALUE(x) unlikely((unsigned long)(void *)(x) >= (unsigned
> long)-MAX_ERRNO)
>                                                  ^
> ./include/linux/compiler.h:78:42: note: in definition of macro unlikely
>  # define unlikely(x) __builtin_expect(!!(x), 0)
>                                           ^
> mm/mmap.c:3006:6: note: in expansion of macro IS_ERR_VALUE
>   if (IS_ERR_VALUE(error))
>
>
Thanks for your review.
I will send a v2.

[-- Attachment #2: Type: text/html, Size: 1108 bytes --]

<div dir="ltr"><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Andrew Morton &lt;<a href="mailto:akpm@linux-foundation.org" target="_blank">akpm@linux-foundation.org</a>&gt; 于2019年10月12日周六 上午10:19写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
./include/linux/err.h:22:49: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]<br>
 #define IS_ERR_VALUE(x) unlikely((unsigned long)(void *)(x) &gt;= (unsigned long)-MAX_ERRNO)<br>
                                                 ^<br>
./include/linux/compiler.h:78:42: note: in definition of macro unlikely<br>
 # define unlikely(x) __builtin_expect(!!(x), 0)<br>
                                          ^<br>
mm/mmap.c:3006:6: note: in expansion of macro IS_ERR_VALUE<br>
  if (IS_ERR_VALUE(error))<br>
<br></blockquote><div><div><br></div><div>Thanks for your review. <br></div><div>I will send a v2.<br></div> </div></div></div>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-10  3:31 [PATCH] mm/mmap.c: use IS_ERR_VALUE to check return value of get_unmapped_area Gaowei Pu
2019-10-12  2:19 ` Andrew Morton
2019-10-12  9:41   ` gaowei Pu

Linux-mm Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mm/0 linux-mm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mm linux-mm/ https://lore.kernel.org/linux-mm \
		linux-mm@kvack.org
	public-inbox-index linux-mm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kvack.linux-mm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git