mm: remove redundant var retval in sys_brk
Subsystems (2)
PATCH 1/1 mm: remove redundant var retval in sys_brk
There is only one possible return value of sys_brk, which is mm->brk no matter succeed or not.
--- mm/mmap.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
mm/mmap.c +2 -3
@@ -251,7 +251,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len); SYSCALL_DEFINE1(brk, unsigned long, brk) { -unsigned long rlim, retval; +unsigned long rlim;unsigned long newbrk, oldbrk;struct mm_struct *mm = current->mm;unsigned long min_brk;
@@ -307,9 +307,8 @@ SYSCALL_DEFINE1(brk, unsigned long, brk) set_brk: mm->brk = brk; out: - retval = mm->brk;up_write (&mm->mmap_sem); -return retval; +return mm->brk; }static long vma_compute_subtree_gap (struct vm_area_struct *vma)
Signature · 7 lines
1.7.7.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 23 lines · On Sat, 5 Jan 2013 10:27:44 +0800 Yuanhan Liu <[email protected]>…
There is only one possible return value of
sys_brk, which ismm->brkno matter succeed or not.Cc Andrew Morton <[email protected]>Signed-off-by Yuanhan Liu <[email protected]>--- mm/mmap.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)mm/mmap.c +1
-1@@ -251,7 +251,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len); SYSCALL_DEFINE1(brk, unsigned long, brk) { -unsigned long rlim, retval; +unsigned long rlim;unsigned long newbrk, oldbrk;struct mm_struct *mm = current->mm;unsigned long min_brk;
mm/mmap.c SYSCALL_DEFINE1(brk, unsigned long, brk) · line 312
Quoted 8 lines
mm/mmap.c +1
-2@@ -307,9 +307,8 @@ SYSCALL_DEFINE1(brk, unsigned long, brk) set_brk: mm->brk = brk; out: - retval = mm->brk;up_write (&mm->mmap_sem); -return retval; +return mm->brk; }
Moving the read outside the locked region opens the possibility that this thread will pick up the results of modification by some other thread.
Of course, if two threads are modifying brk at the same time then that's a userspace problem which can still cuase inconsistent return values, but I'm inclined to leave the code as-is just from a quality-of-implementation POV: sys_brk() will reliably return the value which *this thread* set.
The brk() syscall returns 0 on success, so I assume glibc is throwing this value away anyway...
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 39 lines · Andrew Morton
Quoted 23 lines · On Sat, 5 Jan 2013 10:27:44 +0800 Yuanhan Liu <[email protected]>…
There is only one possible return value of
sys_brk, which ismm->brkno matter succeed or not.Cc Andrew Morton <[email protected]>Signed-off-by Yuanhan Liu <[email protected]>--- mm/mmap.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)mm/mmap.c +1
-1@@ -251,7 +251,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len); SYSCALL_DEFINE1(brk, unsigned long, brk) { -unsigned long rlim, retval; +unsigned long rlim;unsigned long newbrk, oldbrk;struct mm_struct *mm = current->mm;unsigned long min_brk;mm/mmap.c SYSCALL_DEFINE1(brk, unsigned long, brk) · line 312
Quoted 8 lines
mm/mmap.c +1
-2@@ -307,9 +307,8 @@ SYSCALL_DEFINE1(brk, unsigned long, brk) set_brk: mm->brk = brk; out: - retval = mm->brk;up_write (&mm->mmap_sem); -return retval; +return mm->brk; }Moving the read outside the locked region opens the possibility that this thread will pick up the results of modification by some other thread.
Quoted 5 lines
Of course, if two threads are modifying brk at the same time then that's a userspace problem which can still cuase inconsistent return values, but I'm inclined to leave the code as-is just from a quality-of-implementation POV:
sys_brk()will reliably return the value which *this thread* set.
Yes. Thanks for the explanation!
--yliu
Quoted 3 lines
The
brk()syscall returns 0 on success, so I assume glibc is throwing this value away anyway...
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>