Skip to content

Commit

Permalink
memcg: null dereference on allocation failure
Browse files Browse the repository at this point in the history
The original code had a null dereference if alloc_percpu() failed.  This
was introduced in commit 711d3d2 ("memcg: cpu hotplug aware percpu
count updates")

Signed-off-by: Dan Carpenter <error27@gmail.com>
Reviewed-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Dan Carpenter authored and Linus Torvalds committed Nov 12, 2010
1 parent 1093736 commit d2e61b8
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/*
Expand Down

0 comments on commit d2e61b8

Please sign in to comment.