Skip to contentSkip to conversation

mm/mmap.c: use IS_ERR_VALUE to check return value of get_unmapped_area

PATCH Superseded Gaowei Pu 2 participants 3 messages Oct 10, 2019 – Oct 12, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Gaowei Pu

author
#0 lore raw

PATCH 1/1 mm/mmap.c: use IS_ERR_VALUE to check return value of get_unmapped_area

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

---
 mm/mmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/mmap.c +2 -2
index 7e8c3e8ae75f..66cd88b2abb7 100644
@@ -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);
Signature · 1 line
2.22.0
maintainer
#1 lore raw
Quoted 6 lines · On Thu, 10 Oct 2019 11:31:17 +0800 Gaowei Pu <[email protected]> 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().

mm/mmap.c static int do_brk_flags(unsigned long addr, unsigned long len, unsigned long fla · line 3003

Quoted 8 lines
mm/mmap.c +1 -1
@@ -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))
author
#2 lore raw
Quoted 5 lines · Andrew Morton <[email protected]> 于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)

Quoted 8 lines
                                                 ^
./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.