Commit b20b0368 authored by Mathieu Desnoyers's avatar Mathieu Desnoyers Committed by Andrew Morton

mm: fix memory leak on mm_init error handling

commit f1a79412 ("mm: convert mm's rss stats into percpu_counter")
introduces a memory leak by missing a call to destroy_context() when a
percpu_counter fails to allocate.

Before introducing the per-cpu counter allocations, init_new_context() was
the last call that could fail in mm_init(), and thus there was no need to
ever invoke destroy_context() in the error paths.  Adding the following
percpu counter allocations adds error paths after init_new_context(),
which means its associated destroy_context() needs to be called when
percpu counters fail to allocate.

Link: https://lkml.kernel.org/r/20230330133822.66271-1-mathieu.desnoyers@efficios.com
Fixes: f1a79412 ("mm: convert mm's rss stats into percpu_counter")
Signed-off-by: default avatarMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Acked-by: default avatarShakeel Butt <shakeelb@google.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 1007843a
...@@ -1174,6 +1174,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p, ...@@ -1174,6 +1174,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p,
fail_pcpu: fail_pcpu:
while (i > 0) while (i > 0)
percpu_counter_destroy(&mm->rss_stat[--i]); percpu_counter_destroy(&mm->rss_stat[--i]);
destroy_context(mm);
fail_nocontext: fail_nocontext:
mm_free_pgd(mm); mm_free_pgd(mm);
fail_nopgd: fail_nopgd:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment