mm: remove more IS_ERR_VALUE abuses

The do_brk() and vm_brk() return value was "unsigned long" and returned
the starting address on success, and an error value on failure.  The
reasons are entirely historical, and go back to it basically behaving
like the mmap() interface does.

However, nobody actually wanted that interface, and it causes totally
pointless IS_ERR_VALUE() confusion.

What every single caller actually wants is just the simpler integer
return of zero for success and negative error number on failure.

So just convert to that much clearer and more common calling convention,
and get rid of all the IS_ERR_VALUE() uses wrt vm_brk().

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Linus Torvalds 2016-05-27 15:57:31 -07:00
Родитель 287980e49f
Коммит 5d22fc25d4
6 изменённых файлов: 30 добавлений и 36 удалений

Просмотреть файл

@ -116,12 +116,12 @@ static struct linux_binfmt aout_format = {
.min_coredump = PAGE_SIZE .min_coredump = PAGE_SIZE
}; };
static unsigned long set_brk(unsigned long start, unsigned long end) static int set_brk(unsigned long start, unsigned long end)
{ {
start = PAGE_ALIGN(start); start = PAGE_ALIGN(start);
end = PAGE_ALIGN(end); end = PAGE_ALIGN(end);
if (end <= start) if (end <= start)
return start; return 0;
return vm_brk(start, end - start); return vm_brk(start, end - start);
} }
@ -321,7 +321,7 @@ static int load_aout_binary(struct linux_binprm *bprm)
error = vm_brk(text_addr & PAGE_MASK, map_size); error = vm_brk(text_addr & PAGE_MASK, map_size);
if (error != (text_addr & PAGE_MASK)) if (error)
return error; return error;
error = read_code(bprm->file, text_addr, 32, error = read_code(bprm->file, text_addr, 32,
@ -350,7 +350,7 @@ static int load_aout_binary(struct linux_binprm *bprm)
if (!bprm->file->f_op->mmap || (fd_offset & ~PAGE_MASK) != 0) { if (!bprm->file->f_op->mmap || (fd_offset & ~PAGE_MASK) != 0) {
error = vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data); error = vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
if (IS_ERR_VALUE(error)) if (error)
return error; return error;
read_code(bprm->file, N_TXTADDR(ex), fd_offset, read_code(bprm->file, N_TXTADDR(ex), fd_offset,
@ -378,7 +378,7 @@ static int load_aout_binary(struct linux_binprm *bprm)
beyond_if: beyond_if:
error = set_brk(current->mm->start_brk, current->mm->brk); error = set_brk(current->mm->start_brk, current->mm->brk);
if (IS_ERR_VALUE(error)) if (error)
return error; return error;
set_binfmt(&aout_format); set_binfmt(&aout_format);
@ -441,7 +441,7 @@ static int load_aout_library(struct file *file)
} }
#endif #endif
retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss); retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
if (IS_ERR_VALUE(retval)) if (retval)
goto out; goto out;
read_code(file, start_addr, N_TXTOFF(ex), read_code(file, start_addr, N_TXTOFF(ex),
@ -461,9 +461,8 @@ static int load_aout_library(struct file *file)
len = PAGE_ALIGN(ex.a_text + ex.a_data); len = PAGE_ALIGN(ex.a_text + ex.a_data);
bss = ex.a_text + ex.a_data + ex.a_bss; bss = ex.a_text + ex.a_data + ex.a_bss;
if (bss > len) { if (bss > len) {
error = vm_brk(start_addr + len, bss - len); retval = vm_brk(start_addr + len, bss - len);
retval = error; if (retval)
if (error != start_addr + len)
goto out; goto out;
} }
retval = 0; retval = 0;

Просмотреть файл

@ -127,11 +127,8 @@ static int set_brk(unsigned long start, unsigned long end)
{ {
start = PAGE_ALIGN(start); start = PAGE_ALIGN(start);
end = PAGE_ALIGN(end); end = PAGE_ALIGN(end);
if (end > start) { if (end > start)
unsigned long addr; return vm_brk(start, end - start);
addr = vm_brk(start, end - start);
if (BAD_ADDR(addr))
return addr;
} }
return 0; return 0;
} }
@ -275,7 +272,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
map_size = ex.a_text+ex.a_data; map_size = ex.a_text+ex.a_data;
#endif #endif
error = vm_brk(text_addr & PAGE_MASK, map_size); error = vm_brk(text_addr & PAGE_MASK, map_size);
if (error != (text_addr & PAGE_MASK)) if (error)
return error; return error;
error = read_code(bprm->file, text_addr, pos, error = read_code(bprm->file, text_addr, pos,
@ -298,7 +295,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) { if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) {
error = vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data); error = vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
if (IS_ERR_VALUE(error)) if (error)
return error; return error;
read_code(bprm->file, N_TXTADDR(ex), fd_offset, read_code(bprm->file, N_TXTADDR(ex), fd_offset,
@ -382,7 +379,7 @@ static int load_aout_library(struct file *file)
file); file);
} }
retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss); retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
if (IS_ERR_VALUE(retval)) if (retval)
goto out; goto out;
read_code(file, start_addr, N_TXTOFF(ex), read_code(file, start_addr, N_TXTOFF(ex),
@ -402,9 +399,8 @@ static int load_aout_library(struct file *file)
len = PAGE_ALIGN(ex.a_text + ex.a_data); len = PAGE_ALIGN(ex.a_text + ex.a_data);
bss = ex.a_text + ex.a_data + ex.a_bss; bss = ex.a_text + ex.a_data + ex.a_bss;
if (bss > len) { if (bss > len) {
error = vm_brk(start_addr + len, bss - len); retval = vm_brk(start_addr + len, bss - len);
retval = error; if (retval)
if (error != start_addr + len)
goto out; goto out;
} }
retval = 0; retval = 0;

Просмотреть файл

@ -96,10 +96,9 @@ static int set_brk(unsigned long start, unsigned long end)
start = ELF_PAGEALIGN(start); start = ELF_PAGEALIGN(start);
end = ELF_PAGEALIGN(end); end = ELF_PAGEALIGN(end);
if (end > start) { if (end > start) {
unsigned long addr; int error = vm_brk(start, end - start);
addr = vm_brk(start, end - start); if (error)
if (BAD_ADDR(addr)) return error;
return addr;
} }
current->mm->start_brk = current->mm->brk = end; current->mm->start_brk = current->mm->brk = end;
return 0; return 0;
@ -629,7 +628,7 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
/* Map the last of the bss segment */ /* Map the last of the bss segment */
error = vm_brk(elf_bss, last_bss - elf_bss); error = vm_brk(elf_bss, last_bss - elf_bss);
if (BAD_ADDR(error)) if (error)
goto out; goto out;
} }
@ -1178,7 +1177,7 @@ static int load_elf_library(struct file *file)
bss = eppnt->p_memsz + eppnt->p_vaddr; bss = eppnt->p_memsz + eppnt->p_vaddr;
if (bss > len) { if (bss > len) {
error = vm_brk(len, bss - len); error = vm_brk(len, bss - len);
if (BAD_ADDR(error)) if (error)
goto out_free_ph; goto out_free_ph;
} }
error = 0; error = 0;

Просмотреть файл

@ -2018,7 +2018,7 @@ static inline void mm_populate(unsigned long addr, unsigned long len) {}
#endif #endif
/* These take the mm semaphore themselves */ /* These take the mm semaphore themselves */
extern unsigned long __must_check vm_brk(unsigned long, unsigned long); extern int __must_check vm_brk(unsigned long, unsigned long);
extern int vm_munmap(unsigned long, size_t); extern int vm_munmap(unsigned long, size_t);
extern unsigned long __must_check vm_mmap(struct file *, unsigned long, extern unsigned long __must_check vm_mmap(struct file *, unsigned long,
unsigned long, unsigned long, unsigned long, unsigned long,

Просмотреть файл

@ -168,7 +168,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
return next; return next;
} }
static unsigned long do_brk(unsigned long addr, unsigned long len); static int do_brk(unsigned long addr, unsigned long len);
SYSCALL_DEFINE1(brk, unsigned long, brk) SYSCALL_DEFINE1(brk, unsigned long, brk)
{ {
@ -224,7 +224,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
goto out; goto out;
/* Ok, looks good - let it rip. */ /* Ok, looks good - let it rip. */
if (do_brk(oldbrk, newbrk-oldbrk) != oldbrk) if (do_brk(oldbrk, newbrk-oldbrk) < 0)
goto out; goto out;
set_brk: set_brk:
@ -2625,7 +2625,7 @@ static inline void verify_mm_writelocked(struct mm_struct *mm)
* anonymous maps. eventually we may be able to do some * anonymous maps. eventually we may be able to do some
* brk-specific accounting here. * brk-specific accounting here.
*/ */
static unsigned long do_brk(unsigned long addr, unsigned long len) static int do_brk(unsigned long addr, unsigned long len)
{ {
struct mm_struct *mm = current->mm; struct mm_struct *mm = current->mm;
struct vm_area_struct *vma, *prev; struct vm_area_struct *vma, *prev;
@ -2636,7 +2636,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
len = PAGE_ALIGN(len); len = PAGE_ALIGN(len);
if (!len) if (!len)
return addr; return 0;
flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags; flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
@ -2703,13 +2703,13 @@ out:
if (flags & VM_LOCKED) if (flags & VM_LOCKED)
mm->locked_vm += (len >> PAGE_SHIFT); mm->locked_vm += (len >> PAGE_SHIFT);
vma->vm_flags |= VM_SOFTDIRTY; vma->vm_flags |= VM_SOFTDIRTY;
return addr; return 0;
} }
unsigned long vm_brk(unsigned long addr, unsigned long len) int vm_brk(unsigned long addr, unsigned long len)
{ {
struct mm_struct *mm = current->mm; struct mm_struct *mm = current->mm;
unsigned long ret; int ret;
bool populate; bool populate;
if (down_write_killable(&mm->mmap_sem)) if (down_write_killable(&mm->mmap_sem))
@ -2718,7 +2718,7 @@ unsigned long vm_brk(unsigned long addr, unsigned long len)
ret = do_brk(addr, len); ret = do_brk(addr, len);
populate = ((mm->def_flags & VM_LOCKED) != 0); populate = ((mm->def_flags & VM_LOCKED) != 0);
up_write(&mm->mmap_sem); up_write(&mm->mmap_sem);
if (populate) if (populate && !ret)
mm_populate(addr, len); mm_populate(addr, len);
return ret; return ret;
} }

Просмотреть файл

@ -1682,7 +1682,7 @@ void exit_mmap(struct mm_struct *mm)
} }
} }
unsigned long vm_brk(unsigned long addr, unsigned long len) int vm_brk(unsigned long addr, unsigned long len)
{ {
return -ENOMEM; return -ENOMEM;
} }