* [PATCH] mm/mmap.c: use while instead of if+goto @ 2015-03-30 19:40 Rasmus Villemoes 2015-03-30 20:54 ` Kirill A. Shutemov 0 siblings, 1 reply; 4+ messages in thread From: Rasmus Villemoes @ 2015-03-30 19:40 UTC (permalink / raw) To: Andrew Morton, Kirill A. Shutemov, Sasha Levin, Cyrill Gorcunov, Roman Gushchin Cc: Hugh Dickins, Rasmus Villemoes, linux-mm, linux-kernel The creators of the C language gave us the while keyword. Let's use that instead of synthesizing it from if+goto. Made possible by 6597d783397a ("mm/mmap.c: replace find_vma_prepare() with clearer find_vma_links()"). Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> --- mm/mmap.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index da9990acc08b..e1ae629b1e9c 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1553,11 +1553,9 @@ unsigned long mmap_region(struct file *file, unsigned long addr, /* Clear old maps */ error = -ENOMEM; -munmap_back: - if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) { + while (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) { if (do_munmap(mm, addr, len)) return -ENOMEM; - goto munmap_back; } /* @@ -2741,11 +2739,9 @@ static unsigned long do_brk(unsigned long addr, unsigned long len) /* * Clear old maps. this also does some error checking for us */ - munmap_back: - if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) { + while (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) { if (do_munmap(mm, addr, len)) return -ENOMEM; - goto munmap_back; } /* Check against address space limits *after* clearing old maps... */ -- 2.1.3 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/mmap.c: use while instead of if+goto 2015-03-30 19:40 [PATCH] mm/mmap.c: use while instead of if+goto Rasmus Villemoes @ 2015-03-30 20:54 ` Kirill A. Shutemov 2015-03-30 21:58 ` Andrew Morton 0 siblings, 1 reply; 4+ messages in thread From: Kirill A. Shutemov @ 2015-03-30 20:54 UTC (permalink / raw) To: Rasmus Villemoes Cc: Andrew Morton, Kirill A. Shutemov, Sasha Levin, Cyrill Gorcunov, Roman Gushchin, Hugh Dickins, linux-mm, linux-kernel On Mon, Mar 30, 2015 at 09:40:35PM +0200, Rasmus Villemoes wrote: > The creators of the C language gave us the while keyword. Let's use > that instead of synthesizing it from if+goto. > > Made possible by 6597d783397a ("mm/mmap.c: replace find_vma_prepare() > with clearer find_vma_links()"). > > Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Looks good, except both your plus-lines are over 80-characters long for no reason. > --- > mm/mmap.c | 8 ++------ > 1 file changed, 2 insertions(+), 6 deletions(-) > > diff --git a/mm/mmap.c b/mm/mmap.c > index da9990acc08b..e1ae629b1e9c 100644 > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -1553,11 +1553,9 @@ unsigned long mmap_region(struct file *file, unsigned long addr, > > /* Clear old maps */ > error = -ENOMEM; > -munmap_back: > - if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) { > + while (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) { > if (do_munmap(mm, addr, len)) > return -ENOMEM; > - goto munmap_back; > } > > /* > @@ -2741,11 +2739,9 @@ static unsigned long do_brk(unsigned long addr, unsigned long len) > /* > * Clear old maps. this also does some error checking for us > */ > - munmap_back: > - if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) { > + while (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) { > if (do_munmap(mm, addr, len)) > return -ENOMEM; > - goto munmap_back; > } > > /* Check against address space limits *after* clearing old maps... */ -- Kirill A. Shutemov ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/mmap.c: use while instead of if+goto 2015-03-30 20:54 ` Kirill A. Shutemov @ 2015-03-30 21:58 ` Andrew Morton 2015-03-31 10:01 ` Rasmus Villemoes 0 siblings, 1 reply; 4+ messages in thread From: Andrew Morton @ 2015-03-30 21:58 UTC (permalink / raw) To: Kirill A. Shutemov Cc: Rasmus Villemoes, Kirill A. Shutemov, Sasha Levin, Cyrill Gorcunov, Roman Gushchin, Hugh Dickins, linux-mm, linux-kernel On Mon, 30 Mar 2015 23:54:13 +0300 "Kirill A. Shutemov" <kirill@shutemov.name> wrote: > On Mon, Mar 30, 2015 at 09:40:35PM +0200, Rasmus Villemoes wrote: > > The creators of the C language gave us the while keyword. Let's use > > that instead of synthesizing it from if+goto. > > > > Made possible by 6597d783397a ("mm/mmap.c: replace find_vma_prepare() > > with clearer find_vma_links()"). > > > > Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> > > > Looks good, except both your plus-lines are over 80-characters long for no > reason. --- a/mm/mmap.c~mm-mmapc-use-while-instead-of-ifgoto-fix +++ a/mm/mmap.c @@ -1551,7 +1551,8 @@ unsigned long mmap_region(struct file *f /* Clear old maps */ error = -ENOMEM; - while (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) { + while (find_vma_links(mm, addr, addr + len, &prev, &rb_link, + &rb_parent)) { if (do_munmap(mm, addr, len)) return -ENOMEM; } @@ -1569,7 +1570,8 @@ unsigned long mmap_region(struct file *f /* * Can we just expand an old mapping? */ - vma = vma_merge(mm, prev, addr, addr + len, vm_flags, NULL, file, pgoff, NULL); + vma = vma_merge(mm, prev, addr, addr + len, vm_flags, NULL, file, pgoff, + NULL); if (vma) goto out; @@ -2737,7 +2739,8 @@ static unsigned long do_brk(unsigned lon /* * Clear old maps. this also does some error checking for us */ - while (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) { + while (find_vma_links(mm, addr, addr + len, &prev, &rb_link, + &rb_parent)) { if (do_munmap(mm, addr, len)) return -ENOMEM; } I'm not sure it improves things a lot, but mmap.c has been pretty careful about the 80-col thing... ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/mmap.c: use while instead of if+goto 2015-03-30 21:58 ` Andrew Morton @ 2015-03-31 10:01 ` Rasmus Villemoes 0 siblings, 0 replies; 4+ messages in thread From: Rasmus Villemoes @ 2015-03-31 10:01 UTC (permalink / raw) To: Andrew Morton Cc: Kirill A. Shutemov, Kirill A. Shutemov, Sasha Levin, Cyrill Gorcunov, Roman Gushchin, Hugh Dickins, linux-mm, linux-kernel On Mon, Mar 30 2015, Andrew Morton <akpm@linux-foundation.org> wrote: > On Mon, 30 Mar 2015 23:54:13 +0300 "Kirill A. Shutemov" <kirill@shutemov.name> wrote: > >> On Mon, Mar 30, 2015 at 09:40:35PM +0200, Rasmus Villemoes wrote: >> > The creators of the C language gave us the while keyword. Let's use >> > that instead of synthesizing it from if+goto. >> > >> > Made possible by 6597d783397a ("mm/mmap.c: replace find_vma_prepare() >> > with clearer find_vma_links()"). >> > >> > Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> >> >> >> Looks good, except both your plus-lines are over 80-characters long for no >> reason. > > --- a/mm/mmap.c~mm-mmapc-use-while-instead-of-ifgoto-fix > +++ a/mm/mmap.c > @@ -1551,7 +1551,8 @@ unsigned long mmap_region(struct file *f > > I'm not sure it improves things a lot, but mmap.c has been pretty > careful about the 80-col thing... Yeah, I did run checkpatch and chose to ignore the 80-col warning, since I think both the patch and the resulting code was more readable that way. I don't really care either way, though. Rasmus ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-03-31 10:01 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-03-30 19:40 [PATCH] mm/mmap.c: use while instead of if+goto Rasmus Villemoes 2015-03-30 20:54 ` Kirill A. Shutemov 2015-03-30 21:58 ` Andrew Morton 2015-03-31 10:01 ` Rasmus Villemoes
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).