diff options
author | Dan Carpenter <error27@gmail.com> | 2010-11-11 17:05:12 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-11-12 10:55:31 -0500 |
commit | d2e61b8dc99fdb36e0fd176e25365f69afda4ff9 (patch) | |
tree | 580325e7a44fc02d985bca17a1d7601e6ed81cb9 | |
parent | 1093736b3c34319b8f1825a4423414d9cf397d73 (diff) |
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 <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>
-rw-r--r-- | mm/memcontrol.c | 16 |
1 files changed, 9 insertions, 7 deletions
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) | |||
4208 | 4208 | ||
4209 | memset(mem, 0, size); | 4209 | memset(mem, 0, size); |
4210 | mem->stat = alloc_percpu(struct mem_cgroup_stat_cpu); | 4210 | mem->stat = alloc_percpu(struct mem_cgroup_stat_cpu); |
4211 | if (!mem->stat) { | 4211 | if (!mem->stat) |
4212 | if (size < PAGE_SIZE) | 4212 | goto out_free; |
4213 | kfree(mem); | ||
4214 | else | ||
4215 | vfree(mem); | ||
4216 | mem = NULL; | ||
4217 | } | ||
4218 | spin_lock_init(&mem->pcp_counter_lock); | 4213 | spin_lock_init(&mem->pcp_counter_lock); |
4219 | return mem; | 4214 | return mem; |
4215 | |||
4216 | out_free: | ||
4217 | if (size < PAGE_SIZE) | ||
4218 | kfree(mem); | ||
4219 | else | ||
4220 | vfree(mem); | ||
4221 | return NULL; | ||
4220 | } | 4222 | } |
4221 | 4223 | ||
4222 | /* | 4224 | /* |