]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.14.111/mm-cma.c-cma_declare_contiguous-correct-err-handling.patch
drop drm patch
[thirdparty/kernel/stable-queue.git] / releases / 4.14.111 / mm-cma.c-cma_declare_contiguous-correct-err-handling.patch
CommitLineData
04fd09d4
SL
1From 9ed7db52cdb67bdd7e2d128d7b213ceed7d9465f Mon Sep 17 00:00:00 2001
2From: Peng Fan <peng.fan@nxp.com>
3Date: Tue, 5 Mar 2019 15:49:50 -0800
4Subject: mm/cma.c: cma_declare_contiguous: correct err handling
5
6[ Upstream commit 0d3bd18a5efd66097ef58622b898d3139790aa9d ]
7
8In case cma_init_reserved_mem failed, need to free the memblock
9allocated by memblock_reserve or memblock_alloc_range.
10
11Quote Catalin's comments:
12 https://lkml.org/lkml/2019/2/26/482
13
14Kmemleak is supposed to work with the memblock_{alloc,free} pair and it
15ignores the memblock_reserve() as a memblock_alloc() implementation
16detail. It is, however, tolerant to memblock_free() being called on
17a sub-range or just a different range from a previous memblock_alloc().
18So the original patch looks fine to me. FWIW:
19
20Link: http://lkml.kernel.org/r/20190227144631.16708-1-peng.fan@nxp.com
21Signed-off-by: Peng Fan <peng.fan@nxp.com>
22Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
23Reviewed-by: Mike Rapoport <rppt@linux.ibm.com>
24Cc: Laura Abbott <labbott@redhat.com>
25Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
26Cc: Michal Hocko <mhocko@suse.com>
27Cc: Vlastimil Babka <vbabka@suse.cz>
28Cc: Marek Szyprowski <m.szyprowski@samsung.com>
29Cc: Andrey Konovalov <andreyknvl@google.com>
30Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
31Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
32Signed-off-by: Sasha Levin <sashal@kernel.org>
33---
34 mm/cma.c | 4 +++-
35 1 file changed, 3 insertions(+), 1 deletion(-)
36
37diff --git a/mm/cma.c b/mm/cma.c
38index 022e52bd8370..5749c9b3b5d0 100644
39--- a/mm/cma.c
40+++ b/mm/cma.c
41@@ -348,12 +348,14 @@ int __init cma_declare_contiguous(phys_addr_t base,
42
43 ret = cma_init_reserved_mem(base, size, order_per_bit, name, res_cma);
44 if (ret)
45- goto err;
46+ goto free_mem;
47
48 pr_info("Reserved %ld MiB at %pa\n", (unsigned long)size / SZ_1M,
49 &base);
50 return 0;
51
52+free_mem:
53+ memblock_free(base, size);
54 err:
55 pr_err("Failed to reserve %ld MiB\n", (unsigned long)size / SZ_1M);
56 return ret;
57--
582.19.1
59