Commit a5329016 authored by Peng Fan's avatar Peng Fan Committed by Greg Kroah-Hartman

mm/cma.c: cma_declare_contiguous: correct err handling

[ Upstream commit 0d3bd18a5efd66097ef58622b898d3139790aa9d ]

In case cma_init_reserved_mem failed, need to free the memblock
allocated by memblock_reserve or memblock_alloc_range.

Quote Catalin's comments:

Kmemleak is supposed to work with the memblock_{alloc,free} pair and it
ignores the memblock_reserve() as a memblock_alloc() implementation
detail. It is, however, tolerant to memblock_free() being called on
a sub-range or just a different range from a previous memblock_alloc().
So the original patch looks fine to me. FWIW:

Link: Peng Fan's avatarPeng Fan <>
Reviewed-by: default avatarCatalin Marinas <>
Reviewed-by: default avatarMike Rapoport <>
Cc: Laura Abbott <>
Cc: Joonsoo Kim <>
Cc: Michal Hocko <>
Cc: Vlastimil Babka <>
Cc: Marek Szyprowski <>
Cc: Andrey Konovalov <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
Signed-off-by: default avatarSasha Levin <>
parent 02241b9c
......@@ -348,12 +348,14 @@ int __init cma_declare_contiguous(phys_addr_t base,
ret = cma_init_reserved_mem(base, size, order_per_bit, name, res_cma);
if (ret)
goto err;
goto free_mem;
pr_info("Reserved %ld MiB at %pa\n", (unsigned long)size / SZ_1M,
return 0;
memblock_free(base, size);
pr_err("Failed to reserve %ld MiB\n", (unsigned long)size / SZ_1M);
return ret;
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment