Skip to content

Commit 60580e0

Browse files
Frank van der Lindenakpm00
authored andcommitted
mm/cma: report base address of single range correctly
The cma_declare_contiguous_nid code was refactored by commit c009da4 ("mm, cma: support multiple contiguous ranges, if requested"), so that it could use an internal function to attempt a single range area first, and then try a multi-range one. However, that meant that the actual base address used for the !fixed case (base == 0) wasn't available one level up to be printed in the informational message, and it would always end up printing a base address of 0 in the boot message. Make the internal function take a phys_addr_t pointer to the base address, so that the value is available to the caller. [fvdl@google.com: v2] Link: https://lkml.kernel.org/r/20250408164000.3215690-1-fvdl@google.com Link: https://lkml.kernel.org/r/20250407165435.2567898-1-fvdl@google.com Fixes: c009da4 ("mm, cma: support multiple contiguous ranges, if requested") Signed-off-by: Frank van der Linden <fvdl@google.com> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org> Closes: https://lore.kernel.org/linux-mm/CAMuHMdVWviQ7O9yBFE3f=ev0eVb1CnsQvR6SKtEROBbM6z7g3w@mail.gmail.com/ Tested-by: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Muchun Song <muchun.song@linux.dev> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 90abee6 commit 60580e0

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

mm/cma.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
struct cma cma_areas[MAX_CMA_AREAS];
3636
unsigned int cma_area_count;
3737

38-
static int __init __cma_declare_contiguous_nid(phys_addr_t base,
38+
static int __init __cma_declare_contiguous_nid(phys_addr_t *basep,
3939
phys_addr_t size, phys_addr_t limit,
4040
phys_addr_t alignment, unsigned int order_per_bit,
4141
bool fixed, const char *name, struct cma **res_cma,
@@ -370,7 +370,7 @@ int __init cma_declare_contiguous_multi(phys_addr_t total_size,
370370
phys_addr_t align, unsigned int order_per_bit,
371371
const char *name, struct cma **res_cma, int nid)
372372
{
373-
phys_addr_t start, end;
373+
phys_addr_t start = 0, end;
374374
phys_addr_t size, sizesum, sizeleft;
375375
struct cma_init_memrange *mrp, *mlp, *failed;
376376
struct cma_memrange *cmrp;
@@ -384,7 +384,7 @@ int __init cma_declare_contiguous_multi(phys_addr_t total_size,
384384
/*
385385
* First, try it the normal way, producing just one range.
386386
*/
387-
ret = __cma_declare_contiguous_nid(0, total_size, 0, align,
387+
ret = __cma_declare_contiguous_nid(&start, total_size, 0, align,
388388
order_per_bit, false, name, res_cma, nid);
389389
if (ret != -ENOMEM)
390390
goto out;
@@ -580,7 +580,7 @@ int __init cma_declare_contiguous_nid(phys_addr_t base,
580580
{
581581
int ret;
582582

583-
ret = __cma_declare_contiguous_nid(base, size, limit, alignment,
583+
ret = __cma_declare_contiguous_nid(&base, size, limit, alignment,
584584
order_per_bit, fixed, name, res_cma, nid);
585585
if (ret != 0)
586586
pr_err("Failed to reserve %ld MiB\n",
@@ -592,14 +592,14 @@ int __init cma_declare_contiguous_nid(phys_addr_t base,
592592
return ret;
593593
}
594594

595-
static int __init __cma_declare_contiguous_nid(phys_addr_t base,
595+
static int __init __cma_declare_contiguous_nid(phys_addr_t *basep,
596596
phys_addr_t size, phys_addr_t limit,
597597
phys_addr_t alignment, unsigned int order_per_bit,
598598
bool fixed, const char *name, struct cma **res_cma,
599599
int nid)
600600
{
601601
phys_addr_t memblock_end = memblock_end_of_DRAM();
602-
phys_addr_t highmem_start;
602+
phys_addr_t highmem_start, base = *basep;
603603
int ret;
604604

605605
/*
@@ -722,12 +722,15 @@ static int __init __cma_declare_contiguous_nid(phys_addr_t base,
722722
}
723723

724724
ret = cma_init_reserved_mem(base, size, order_per_bit, name, res_cma);
725-
if (ret)
725+
if (ret) {
726726
memblock_phys_free(base, size);
727+
return ret;
728+
}
727729

728730
(*res_cma)->nid = nid;
731+
*basep = base;
729732

730-
return ret;
733+
return 0;
731734
}
732735

733736
static void cma_debug_show_areas(struct cma *cma)

0 commit comments

Comments
 (0)