From: Andrew Morton <akpm@linux-foundation.org>
To: Chen Gang <xili_gchen_5257@hotmail.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
riel@redhat.com, Michal Hocko <mhocko@suse.cz>,
sasha.levin@oracle.com, linux-mm@kvack.org,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] mm: mmap: Simplify the failure return working flow
Date: Tue, 18 Aug 2015 15:57:08 -0700 [thread overview]
Message-ID: <20150818155708.8d10dac3736d547083c44500@linux-foundation.org> (raw)
In-Reply-To: <BLU436-SMTP37E3EE1A24E7A3EEEDBFA7B9780@phx.gbl>
On Wed, 19 Aug 2015 06:27:58 +0800 Chen Gang <xili_gchen_5257@hotmail.com> wrote:
> From: Chen Gang <xili_gchen_5257@hotmail.com>
As sent, this patch is From:you@hotmail and Signed-off-by:you@gmail.
This is peculiar. I'm assuming that it should have been From:you@gmail and
I have made that change to my copy of the patch.
You can do this yourself by putting an explicit From: line at the start
of the changelog.
> @@ -2958,23 +2957,23 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
> *need_rmap_locks = (new_vma->vm_pgoff <= vma->vm_pgoff);
> } else {
> new_vma = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
> - if (new_vma) {
> - *new_vma = *vma;
> - new_vma->vm_start = addr;
> - new_vma->vm_end = addr + len;
> - new_vma->vm_pgoff = pgoff;
> - if (vma_dup_policy(vma, new_vma))
> - goto out_free_vma;
> - INIT_LIST_HEAD(&new_vma->anon_vma_chain);
> - if (anon_vma_clone(new_vma, vma))
> - goto out_free_mempol;
> - if (new_vma->vm_file)
> - get_file(new_vma->vm_file);
> - if (new_vma->vm_ops && new_vma->vm_ops->open)
> - new_vma->vm_ops->open(new_vma);
> - vma_link(mm, new_vma, prev, rb_link, rb_parent);
> - *need_rmap_locks = false;
> - }
> + if (!new_vma)
> + return NULL;
> + *new_vma = *vma;
> + new_vma->vm_start = addr;
> + new_vma->vm_end = addr + len;
> + new_vma->vm_pgoff = pgoff;
> + if (vma_dup_policy(vma, new_vma))
> + goto out_free_vma;
> + INIT_LIST_HEAD(&new_vma->anon_vma_chain);
> + if (anon_vma_clone(new_vma, vma))
> + goto out_free_mempol;
> + if (new_vma->vm_file)
> + get_file(new_vma->vm_file);
> + if (new_vma->vm_ops && new_vma->vm_ops->open)
> + new_vma->vm_ops->open(new_vma);
> + vma_link(mm, new_vma, prev, rb_link, rb_parent);
> + *need_rmap_locks = false;
> }
> return new_vma;
Embedding a return deep inside the function isn't good. It can lead to
resource leaks, locking leaks etc as the code evolves. This is the
main reason why the kernel uses goto, IMO: single-entry, single-exit.
So,
--- a/mm/mmap.c~mm-mmap-simplify-the-failure-return-working-flow-fix
+++ a/mm/mmap.c
@@ -2952,7 +2952,7 @@ struct vm_area_struct *copy_vma(struct v
} else {
new_vma = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
if (!new_vma)
- return NULL;
+ goto out;
*new_vma = *vma;
new_vma->vm_start = addr;
new_vma->vm_end = addr + len;
@@ -2971,10 +2971,11 @@ struct vm_area_struct *copy_vma(struct v
}
return new_vma;
- out_free_mempol:
+out_free_mempol:
mpol_put(vma_policy(new_vma));
- out_free_vma:
+out_free_vma:
kmem_cache_free(vm_area_cachep, new_vma);
+out:
return NULL;
}
_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2015-08-18 22:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-18 22:27 Chen Gang
2015-08-18 22:57 ` Andrew Morton [this message]
[not found] <55D5275D.7020406@hotmail.com>
[not found] ` <COL130-W46B6A43FC26795B43939E0B9660@phx.gbl>
[not found] ` <55D52C9A.5060705@hotmail.com>
2015-08-20 1:26 ` gchen gchen
[not found] ` <55D52CDE.8060700@hotmail.com>
2015-08-20 1:27 ` gchen gchen
2015-08-20 7:45 ` Michal Hocko
[not found] ` <55D593C2.3040105@hotmail.com>
2015-08-20 8:48 ` gchen gchen
2015-08-23 17:28 ` Chen Gang
2015-08-23 16:20 gang.chen.5i5j
2015-08-23 16:28 gang.chen.5i5j
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150818155708.8d10dac3736d547083c44500@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.cz \
--cc=riel@redhat.com \
--cc=sasha.levin@oracle.com \
--cc=xili_gchen_5257@hotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox