lkml.org 
[lkml]   [2010]   [Oct]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [patch] memcg: null dereference on allocation failure
(I add Andrew to CC-list)

On Thu, 28 Oct 2010 13:12:41 +0200
Dan Carpenter <error27@gmail.com> wrote:

> 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>
>

Acked-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>

> 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;
> }
>
> /*


\
 
 \ /
  Last update: 2010-10-29 02:49    [W:2.493 / U:0.264 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site