From: Balbir Singh <balbir@linux.vnet.ibm.com>
To: Dan Carpenter <error27@gmail.com>,
Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [patch] memcg: null dereference on allocation failure
Date: Thu, 28 Oct 2010 21:22:07 +0530 [thread overview]
Message-ID: <20101028155207.GB3769@balbir.in.ibm.com> (raw)
In-Reply-To: <20101028111241.GC6062@bicker>
* Dan Carpenter <error27@gmail.com> [2010-10-28 13:12:41]:
> The original code had a null dereference if alloc_percpu() failed.
> This was introduced in 711d3d2c9bc3 "memcg: cpu hotplug aware percpu
> count updates"
>
> Signed-off-by: Dan Carpenter <error27@gmail.com>
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 9a99cfa..2efa8ea 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -4208,15 +4208,17 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
>
> memset(mem, 0, size);
> mem->stat = alloc_percpu(struct mem_cgroup_stat_cpu);
> - if (!mem->stat) {
> - if (size < PAGE_SIZE)
> - kfree(mem);
> - else
> - vfree(mem);
> - mem = NULL;
> - }
> + if (!mem->stat)
> + goto out_free;
> spin_lock_init(&mem->pcp_counter_lock);
> return mem;
> +
> +out_free:
> + if (size < PAGE_SIZE)
> + kfree(mem);
> + else
> + vfree(mem);
> + return NULL;
> }
Good catch!
Reviewed-by: Balbir Singh <balbir@linux.vnet.ibm.com>
--
Three Cheers,
Balbir
--
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:[~2010-10-28 15:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-28 11:12 Dan Carpenter
2010-10-28 15:52 ` Balbir Singh [this message]
2010-10-28 23:39 ` KAMEZAWA Hiroyuki
2010-10-29 0:38 ` Daisuke Nishimura
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=20101028155207.GB3769@balbir.in.ibm.com \
--to=balbir@linux.vnet.ibm.com \
--cc=error27@gmail.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nishimura@mxp.nes.nec.co.jp \
/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