Thread (19 messages) 19 messages, 4 authors, 2021-01-13
STALE1973d REVIEWED: 1 (0M)
Revisions (11)
  1. v4 [diff vs current]
  2. v9 [diff vs current]
  3. v10 [diff vs current]
  4. v11 [diff vs current]
  5. v13 [diff vs current]
  6. v14 current
  7. v15 [diff vs current]
  8. v16 [diff vs current]
  9. v17 [diff vs current]
  10. v18 [diff vs current]
  11. v19 [diff vs current]

[PATCH v14 5/6] arm64: Free DTB buffer if fdt_open_into() fails

From: Lakshmi Ramasubramanian <hidden>
Date: 2021-01-04 19:27:35
Also in: linux-arm-kernel, linux-devicetree, lkml
Subsystem: arm64 port (aarch64 architecture), the rest · Maintainers: Catalin Marinas, Will Deacon, Linus Torvalds

create_dtb() function allocates memory for the device tree blob (DTB)
and calls fdt_open_into(). If this call fails the memory allocated
for the DTB is not freed before returning from create_dtb() thereby
leaking memory.

Call vfree() to free the memory allocated for the DTB if fdt_open_into()
fails.

Co-developed-by: Prakhar Srivastava <redacted>
Signed-off-by: Prakhar Srivastava <redacted>
Signed-off-by: Lakshmi Ramasubramanian <redacted>
Reviewed-by: Thiago Jung Bauermann <redacted>
---
 arch/arm64/kernel/machine_kexec_file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
index 7da22bb7b9d5..2664b63bb118 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -65,8 +65,10 @@ static int create_dtb(struct kimage *image,
 
 		/* duplicate a device tree blob */
 		ret = fdt_open_into(initial_boot_params, buf, buf_size);
-		if (ret)
+		if (ret) {
+			vfree(buf);
 			return -EINVAL;
+		}
 
 		ret = of_kexec_setup_new_fdt(image, buf, initrd_load_addr,
 					     initrd_len, cmdline);
-- 
2.29.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help