aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-05-27 18:57:31 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-05-27 18:57:31 -0400
commit5d22fc25d4fc8096d2d7df27ea1893d4e055e764 (patch)
tree464a86dc3d004dd334e37a8fe7e7b42f8511581e
parent287980e49ffc0f6d911601e7e352a812ed27768e (diff)
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>
-rw-r--r--arch/x86/ia32/ia32_aout.c17
-rw-r--r--fs/binfmt_aout.c18
-rw-r--r--fs/binfmt_elf.c11
-rw-r--r--include/linux/mm.h2
-rw-r--r--mm/mmap.c16
-rw-r--r--mm/nommu.c2
6 files changed, 30 insertions, 36 deletions
diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
index f5e737ff0022..cb26f18d43af 100644
--- a/arch/x86/ia32/ia32_aout.c
+++ b/arch/x86/ia32/ia32_aout.c
@@ -116,12 +116,12 @@ static struct linux_binfmt aout_format = {
116 .min_coredump = PAGE_SIZE 116 .min_coredump = PAGE_SIZE
117}; 117};
118 118
119static unsigned long set_brk(unsigned long start, unsigned long end) 119static int set_brk(unsigned long start, unsigned long end)
120{ 120{
121 start = PAGE_ALIGN(start); 121 start = PAGE_ALIGN(start);
122 end = PAGE_ALIGN(end); 122 end = PAGE_ALIGN(end);
123 if (end <= start) 123 if (end <= start)
124 return start; 124 return 0;
125 return vm_brk(start, end - start); 125 return vm_brk(start, end - start);
126} 126}
127 127
@@ -321,7 +321,7 @@ static int load_aout_binary(struct linux_binprm *bprm)
321 321
322 error = vm_brk(text_addr & PAGE_MASK, map_size); 322 error = vm_brk(text_addr & PAGE_MASK, map_size);
323 323
324 if (error != (text_addr & PAGE_MASK)) 324 if (error)
325 return error; 325 return error;
326 326
327 error = read_code(bprm->file, text_addr, 32, 327 error = read_code(bprm->file, text_addr, 32,
@@ -350,7 +350,7 @@ static int load_aout_binary(struct linux_binprm *bprm)
350 350
351 if (!bprm->file->f_op->mmap || (fd_offset & ~PAGE_MASK) != 0) { 351 if (!bprm->file->f_op->mmap || (fd_offset & ~PAGE_MASK) != 0) {
352 error = vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data); 352 error = vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
353 if (IS_ERR_VALUE(error)) 353 if (error)
354 return error; 354 return error;
355 355
356 read_code(bprm->file, N_TXTADDR(ex), fd_offset, 356 read_code(bprm->file, N_TXTADDR(ex), fd_offset,
@@ -378,7 +378,7 @@ static int load_aout_binary(struct linux_binprm *bprm)
378 378
379beyond_if: 379beyond_if:
380 error = set_brk(current->mm->start_brk, current->mm->brk); 380 error = set_brk(current->mm->start_brk, current->mm->brk);
381 if (IS_ERR_VALUE(error)) 381 if (error)
382 return error; 382 return error;
383 383
384 set_binfmt(&aout_format); 384 set_binfmt(&aout_format);
@@ -441,7 +441,7 @@ static int load_aout_library(struct file *file)
441 } 441 }
442#endif 442#endif
443 retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss); 443 retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
444 if (IS_ERR_VALUE(retval)) 444 if (retval)
445 goto out; 445 goto out;
446 446
447 read_code(file, start_addr, N_TXTOFF(ex), 447 read_code(file, start_addr, N_TXTOFF(ex),
@@ -461,9 +461,8 @@ static int load_aout_library(struct file *file)
461 len = PAGE_ALIGN(ex.a_text + ex.a_data); 461 len = PAGE_ALIGN(ex.a_text + ex.a_data);
462 bss = ex.a_text + ex.a_data + ex.a_bss; 462 bss = ex.a_text + ex.a_data + ex.a_bss;
463 if (bss > len) { 463 if (bss > len) {
464 error = vm_brk(start_addr + len, bss - len); 464 retval = vm_brk(start_addr + len, bss - len);
465 retval = error; 465 if (retval)
466 if (error != start_addr + len)
467 goto out; 466 goto out;
468 } 467 }
469 retval = 0; 468 retval = 0;
diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
index 2fab9f130e51..64b331ae3428 100644
--- a/fs/binfmt_aout.c
+++ b/fs/binfmt_aout.c
@@ -127,11 +127,8 @@ static int set_brk(unsigned long start, unsigned long end)
127{ 127{
128 start = PAGE_ALIGN(start); 128 start = PAGE_ALIGN(start);
129 end = PAGE_ALIGN(end); 129 end = PAGE_ALIGN(end);
130 if (end > start) { 130 if (end > start)
131 unsigned long addr; 131 return vm_brk(start, end - start);
132 addr = vm_brk(start, end - start);
133 if (BAD_ADDR(addr))
134 return addr;
135 } 132 }
136 return 0; 133 return 0;
137} 134}
@@ -275,7 +272,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
275 map_size = ex.a_text+ex.a_data; 272 map_size = ex.a_text+ex.a_data;
276#endif 273#endif
277 error = vm_brk(text_addr & PAGE_MASK, map_size); 274 error = vm_brk(text_addr & PAGE_MASK, map_size);
278 if (error != (text_addr & PAGE_MASK)) 275 if (error)
279 return error; 276 return error;
280 277
281 error = read_code(bprm->file, text_addr, pos, 278 error = read_code(bprm->file, text_addr, pos,
@@ -298,7 +295,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
298 295
299 if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) { 296 if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) {
300 error = vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data); 297 error = vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
301 if (IS_ERR_VALUE(error)) 298 if (error)
302 return error; 299 return error;
303 300
304 read_code(bprm->file, N_TXTADDR(ex), fd_offset, 301 read_code(bprm->file, N_TXTADDR(ex), fd_offset,
@@ -382,7 +379,7 @@ static int load_aout_library(struct file *file)
382 file); 379 file);
383 } 380 }
384 retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss); 381 retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
385 if (IS_ERR_VALUE(retval)) 382 if (retval)
386 goto out; 383 goto out;
387 384
388 read_code(file, start_addr, N_TXTOFF(ex), 385 read_code(file, start_addr, N_TXTOFF(ex),
@@ -402,9 +399,8 @@ static int load_aout_library(struct file *file)
402 len = PAGE_ALIGN(ex.a_text + ex.a_data); 399 len = PAGE_ALIGN(ex.a_text + ex.a_data);
403 bss = ex.a_text + ex.a_data + ex.a_bss; 400 bss = ex.a_text + ex.a_data + ex.a_bss;
404 if (bss > len) { 401 if (bss > len) {
405 error = vm_brk(start_addr + len, bss - len); 402 retval = vm_brk(start_addr + len, bss - len);
406 retval = error; 403 if (retval)
407 if (error != start_addr + len)
408 goto out; 404 goto out;
409 } 405 }
410 retval = 0; 406 retval = 0;
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 938fc4ede764..e158b22ef32f 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -96,10 +96,9 @@ static int set_brk(unsigned long start, unsigned long end)
96 start = ELF_PAGEALIGN(start); 96 start = ELF_PAGEALIGN(start);
97 end = ELF_PAGEALIGN(end); 97 end = ELF_PAGEALIGN(end);
98 if (end > start) { 98 if (end > start) {
99 unsigned long addr; 99 int error = vm_brk(start, end - start);
100 addr = vm_brk(start, end - start); 100 if (error)
101 if (BAD_ADDR(addr)) 101 return error;
102 return addr;
103 } 102 }
104 current->mm->start_brk = current->mm->brk = end; 103 current->mm->start_brk = current->mm->brk = end;
105 return 0; 104 return 0;
@@ -629,7 +628,7 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
629 628
630 /* Map the last of the bss segment */ 629 /* Map the last of the bss segment */
631 error = vm_brk(elf_bss, last_bss - elf_bss); 630 error = vm_brk(elf_bss, last_bss - elf_bss);
632 if (BAD_ADDR(error)) 631 if (error)
633 goto out; 632 goto out;
634 } 633 }
635 634
@@ -1178,7 +1177,7 @@ static int load_elf_library(struct file *file)
1178 bss = eppnt->p_memsz + eppnt->p_vaddr; 1177 bss = eppnt->p_memsz + eppnt->p_vaddr;
1179 if (bss > len) { 1178 if (bss > len) {
1180 error = vm_brk(len, bss - len); 1179 error = vm_brk(len, bss - len);
1181 if (BAD_ADDR(error)) 1180 if (error)
1182 goto out_free_ph; 1181 goto out_free_ph;
1183 } 1182 }
1184 error = 0; 1183 error = 0;
diff --git a/include/linux/mm.h b/include/linux/mm.h
index a00ec816233a..5df5feb49575 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2018,7 +2018,7 @@ static inline void mm_populate(unsigned long addr, unsigned long len) {}
2018#endif 2018#endif
2019 2019
2020/* These take the mm semaphore themselves */ 2020/* These take the mm semaphore themselves */
2021extern unsigned long __must_check vm_brk(unsigned long, unsigned long); 2021extern int __must_check vm_brk(unsigned long, unsigned long);
2022extern int vm_munmap(unsigned long, size_t); 2022extern int vm_munmap(unsigned long, size_t);
2023extern unsigned long __must_check vm_mmap(struct file *, unsigned long, 2023extern unsigned long __must_check vm_mmap(struct file *, unsigned long,
2024 unsigned long, unsigned long, 2024 unsigned long, unsigned long,
diff --git a/mm/mmap.c b/mm/mmap.c
index d3d9a94ca031..de2c1769cc68 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -168,7 +168,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
168 return next; 168 return next;
169} 169}
170 170
171static unsigned long do_brk(unsigned long addr, unsigned long len); 171static int do_brk(unsigned long addr, unsigned long len);
172 172
173SYSCALL_DEFINE1(brk, unsigned long, brk) 173SYSCALL_DEFINE1(brk, unsigned long, brk)
174{ 174{
@@ -224,7 +224,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
224 goto out; 224 goto out;
225 225
226 /* Ok, looks good - let it rip. */ 226 /* Ok, looks good - let it rip. */
227 if (do_brk(oldbrk, newbrk-oldbrk) != oldbrk) 227 if (do_brk(oldbrk, newbrk-oldbrk) < 0)
228 goto out; 228 goto out;
229 229
230set_brk: 230set_brk:
@@ -2625,7 +2625,7 @@ static inline void verify_mm_writelocked(struct mm_struct *mm)
2625 * anonymous maps. eventually we may be able to do some 2625 * anonymous maps. eventually we may be able to do some
2626 * brk-specific accounting here. 2626 * brk-specific accounting here.
2627 */ 2627 */
2628static unsigned long do_brk(unsigned long addr, unsigned long len) 2628static int do_brk(unsigned long addr, unsigned long len)
2629{ 2629{
2630 struct mm_struct *mm = current->mm; 2630 struct mm_struct *mm = current->mm;
2631 struct vm_area_struct *vma, *prev; 2631 struct vm_area_struct *vma, *prev;
@@ -2636,7 +2636,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
2636 2636
2637 len = PAGE_ALIGN(len); 2637 len = PAGE_ALIGN(len);
2638 if (!len) 2638 if (!len)
2639 return addr; 2639 return 0;
2640 2640
2641 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags; 2641 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
2642 2642
@@ -2703,13 +2703,13 @@ out:
2703 if (flags & VM_LOCKED) 2703 if (flags & VM_LOCKED)
2704 mm->locked_vm += (len >> PAGE_SHIFT); 2704 mm->locked_vm += (len >> PAGE_SHIFT);
2705 vma->vm_flags |= VM_SOFTDIRTY; 2705 vma->vm_flags |= VM_SOFTDIRTY;
2706 return addr; 2706 return 0;
2707} 2707}
2708 2708
2709unsigned long vm_brk(unsigned long addr, unsigned long len) 2709int vm_brk(unsigned long addr, unsigned long len)
2710{ 2710{
2711 struct mm_struct *mm = current->mm; 2711 struct mm_struct *mm = current->mm;
2712 unsigned long ret; 2712 int ret;
2713 bool populate; 2713 bool populate;
2714 2714
2715 if (down_write_killable(&mm->mmap_sem)) 2715 if (down_write_killable(&mm->mmap_sem))
@@ -2718,7 +2718,7 @@ unsigned long vm_brk(unsigned long addr, unsigned long len)
2718 ret = do_brk(addr, len); 2718 ret = do_brk(addr, len);
2719 populate = ((mm->def_flags & VM_LOCKED) != 0); 2719 populate = ((mm->def_flags & VM_LOCKED) != 0);
2720 up_write(&mm->mmap_sem); 2720 up_write(&mm->mmap_sem);
2721 if (populate) 2721 if (populate && !ret)
2722 mm_populate(addr, len); 2722 mm_populate(addr, len);
2723 return ret; 2723 return ret;
2724} 2724}
diff --git a/mm/nommu.c b/mm/nommu.c
index c8bd59a03c71..c2e58880207f 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1682,7 +1682,7 @@ void exit_mmap(struct mm_struct *mm)
1682 } 1682 }
1683} 1683}
1684 1684
1685unsigned long vm_brk(unsigned long addr, unsigned long len) 1685int vm_brk(unsigned long addr, unsigned long len)
1686{ 1686{
1687 return -ENOMEM; 1687 return -ENOMEM;
1688} 1688}