U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Yuho Choi <oss.patchbox@gmail.com>
To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>,
	Priyanka Jain <priyanka.jain@nxp.com>,
	Ashish Kumar <Ashish.Kumar@nxp.com>
Cc: Tom Rini <trini@konsulko.com>, Peng Fan <peng.fan@nxp.com>,
	u-boot@lists.u-boot-project.org,
	Yuho Choi <oss.patchbox@gmail.com>
Subject: [PATCH] board: nxp: fix memory leak and check calloc in ft_board_setup
Date: Thu, 22 Oct 2026 23:02:39 -0400	[thread overview]
Message-ID: <20261023030353.153360-1-oss.patchbox@gmail.com> (raw)

In ft_board_setup() for NXP Layerscape platforms (LS1088A, LS2080A,
and LX2160A), base and size arrays are allocated via calloc() to pass
DRAM bank parameters to fdt_fixup_memory_banks().

On LS2080A and LX2160A, the return values of calloc() are not checked
for NULL, which can cause a NULL pointer dereference if allocation fails.
Furthermore, on all three platforms, base and size are never freed after
fdt_fixup_memory_banks() only consumes these arrays during the call and
does not retain them. However, neither array is freed after the call,
leaking memory regardless of whether the FDT update succeeds.

Fix these issues by validating the calloc() return values where missing
and freeing both base and size after fdt_fixup_memory_banks().

Fixes: cf0bbbd1ee7b ("drivers: net: mc: Report extra memory to Linux")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
 board/nxp/ls1088a/ls1088a.c       |  3 +++
 board/nxp/ls2080ardb/ls2080ardb.c | 11 +++++++++++
 board/nxp/lx2160a/lx2160a.c       | 11 +++++++++++
 3 files changed, 25 insertions(+)

diff --git a/board/nxp/ls1088a/ls1088a.c b/board/nxp/ls1088a/ls1088a.c
index 8ea76fe3760..29598cd487b 100644
--- a/board/nxp/ls1088a/ls1088a.c
+++ b/board/nxp/ls1088a/ls1088a.c
@@ -986,6 +986,9 @@ int ft_board_setup(void *blob, struct bd_info *bd)
 
 	fdt_fixup_memory_banks(blob, base, size, total_memory_banks);
 
+	free(base);
+	free(size);
+
 	fdt_fsl_mc_fixup_iommu_map_entry(blob);
 
 	fsl_fdt_fixup_flash(blob);
diff --git a/board/nxp/ls2080ardb/ls2080ardb.c b/board/nxp/ls2080ardb/ls2080ardb.c
index 9dec818280b..d9f23b72fa0 100644
--- a/board/nxp/ls2080ardb/ls2080ardb.c
+++ b/board/nxp/ls2080ardb/ls2080ardb.c
@@ -484,7 +484,14 @@ int ft_board_setup(void *blob, struct bd_info *bd)
 	total_memory_banks = CONFIG_NR_DRAM_BANKS + mc_memory_bank;
 
 	base = calloc(total_memory_banks, sizeof(u64));
+	if (!base)
+		return -ENOMEM;
+
 	size = calloc(total_memory_banks, sizeof(u64));
+	if (!size) {
+		free(base);
+		return -ENOMEM;
+	}
 
 	/* fixup DT for the two GPP DDR banks */
 	base[0] = gd->dram[0].start;
@@ -514,6 +521,9 @@ int ft_board_setup(void *blob, struct bd_info *bd)
 
 	fdt_fixup_memory_banks(blob, base, size, total_memory_banks);
 
+	free(base);
+	free(size);
+
 	fdt_fsl_mc_fixup_iommu_map_entry(blob);
 
 	fsl_fdt_fixup_dr_usb(blob, bd);
diff --git a/board/nxp/lx2160a/lx2160a.c b/board/nxp/lx2160a/lx2160a.c
index 10729dfaf24..330d720e9bc 100644
--- a/board/nxp/lx2160a/lx2160a.c
+++ b/board/nxp/lx2160a/lx2160a.c
@@ -804,7 +804,14 @@ int ft_board_setup(void *blob, struct bd_info *bd)
 	total_memory_banks = CONFIG_NR_DRAM_BANKS + mc_memory_bank;
 
 	base = calloc(total_memory_banks, sizeof(u64));
+	if (!base)
+		return -ENOMEM;
+
 	size = calloc(total_memory_banks, sizeof(u64));
+	if (!size) {
+		free(base);
+		return -ENOMEM;
+	}
 
 	/* fixup DT for the three GPP DDR banks */
 	for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
@@ -837,6 +844,9 @@ int ft_board_setup(void *blob, struct bd_info *bd)
 
 	fdt_fixup_memory_banks(blob, base, size, total_memory_banks);
 
+	free(base);
+	free(size);
+
 #ifdef CONFIG_USB_HOST
 	fsl_fdt_fixup_dr_usb(blob, bd);
 #endif
-- 
2.43.0

                 reply	other threads:[~2026-10-23  4:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261023030353.153360-1-oss.patchbox@gmail.com \
    --to=oss.patchbox@gmail.com \
    --cc=Ashish.Kumar@nxp.com \
    --cc=meenakshi.aggarwal@nxp.com \
    --cc=peng.fan@nxp.com \
    --cc=priyanka.jain@nxp.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox