]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.14.111/mm-cma.c-cma_declare_contiguous-correct-err-handling.patch
Linux 4.14.111
[thirdparty/kernel/stable-queue.git] / releases / 4.14.111 / mm-cma.c-cma_declare_contiguous-correct-err-handling.patch
1 From 9ed7db52cdb67bdd7e2d128d7b213ceed7d9465f Mon Sep 17 00:00:00 2001
2 From: Peng Fan <peng.fan@nxp.com>
3 Date: Tue, 5 Mar 2019 15:49:50 -0800
4 Subject: mm/cma.c: cma_declare_contiguous: correct err handling
5
6 [ Upstream commit 0d3bd18a5efd66097ef58622b898d3139790aa9d ]
7
8 In case cma_init_reserved_mem failed, need to free the memblock
9 allocated by memblock_reserve or memblock_alloc_range.
10
11 Quote Catalin's comments:
12 https://lkml.org/lkml/2019/2/26/482
13
14 Kmemleak is supposed to work with the memblock_{alloc,free} pair and it
15 ignores the memblock_reserve() as a memblock_alloc() implementation
16 detail. It is, however, tolerant to memblock_free() being called on
17 a sub-range or just a different range from a previous memblock_alloc().
18 So the original patch looks fine to me. FWIW:
19
20 Link: http://lkml.kernel.org/r/20190227144631.16708-1-peng.fan@nxp.com
21 Signed-off-by: Peng Fan <peng.fan@nxp.com>
22 Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
23 Reviewed-by: Mike Rapoport <rppt@linux.ibm.com>
24 Cc: Laura Abbott <labbott@redhat.com>
25 Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
26 Cc: Michal Hocko <mhocko@suse.com>
27 Cc: Vlastimil Babka <vbabka@suse.cz>
28 Cc: Marek Szyprowski <m.szyprowski@samsung.com>
29 Cc: Andrey Konovalov <andreyknvl@google.com>
30 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
31 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
32 Signed-off-by: Sasha Levin <sashal@kernel.org>
33 ---
34 mm/cma.c | 4 +++-
35 1 file changed, 3 insertions(+), 1 deletion(-)
36
37 diff --git a/mm/cma.c b/mm/cma.c
38 index 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 --
58 2.19.1
59