From: Dan Carpenter Date: Thu, 11 Nov 2010 22:05:12 +0000 (-0800) Subject: memcg: null dereference on allocation failure X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=d2e61b8dc99fdb36e0fd176e25365f69afda4ff9;p=GitHub%2Fmt8127%2Fandroid_kernel_alcatel_ttab.git memcg: null dereference on allocation failure The original code had a null dereference if alloc_percpu() failed. This was introduced in commit 711d3d2c9bc3 ("memcg: cpu hotplug aware percpu count updates") Signed-off-by: Dan Carpenter Reviewed-by: Balbir Singh Acked-by: KAMEZAWA Hiroyuki Acked-by: Daisuke Nishimura Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 9a99cfaf0a19..2efa8ea07ff7 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; } /*