public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: amphion: fix potential NULL deref in vpu_core_parse_dt()
@ 2025-04-11 18:43 Chenyuan Yang
  2025-04-11 21:20 ` Nicolas Dufresne
  2025-04-12 15:15 ` Markus Elfring
  0 siblings, 2 replies; 6+ messages in thread
From: Chenyuan Yang @ 2025-04-11 18:43 UTC (permalink / raw)
  To: ming.qian, eagle.zhou, mchehab, shijie.qin, hverkuil
  Cc: linux-media, linux-kernel, Chenyuan Yang

The result of memremap() may be NULL on failure, leading to a null
dereference in the subsequent memset(). Add explicit checks after
each memremap() call: if the firmware region fails to map, return
immediately; if the RPC region fails, unmap the firmware window before
returning.

This is similar to the commit 966d47e1f27c
("efi: fix potential NULL deref in efi_mem_reserve_persistent").

This is found by our static analysis tool KNighter.

Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
Fixes: 9f599f351e86 ("media: amphion: add vpu core driver")
---
 drivers/media/platform/amphion/vpu_core.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/media/platform/amphion/vpu_core.c b/drivers/media/platform/amphion/vpu_core.c
index 8df85c14ab3f..26568987586d 100644
--- a/drivers/media/platform/amphion/vpu_core.c
+++ b/drivers/media/platform/amphion/vpu_core.c
@@ -586,7 +586,18 @@ static int vpu_core_parse_dt(struct vpu_core *core, struct device_node *np)
 	}
 
 	core->fw.virt = memremap(core->fw.phys, core->fw.length, MEMREMAP_WC);
+	if (!core->fw.virt) {
+		dev_err(core->dev, "failed to remap fw region\n");
+		of_node_put(node);
+		return -ENOMEM;
+	}
 	core->rpc.virt = memremap(core->rpc.phys, core->rpc.length, MEMREMAP_WC);
+	if (!core->rpc.virt) {
+		dev_err(core->dev, "failed to remap rpc region\n");
+		memunmap(core->fw.virt);
+		of_node_put(node);
+		return -ENOMEM;
+	}
 	memset(core->rpc.virt, 0, core->rpc.length);
 
 	ret = vpu_iface_check_memory_region(core, core->rpc.phys, core->rpc.length);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-04-23  7:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-11 18:43 [PATCH] media: amphion: fix potential NULL deref in vpu_core_parse_dt() Chenyuan Yang
2025-04-11 21:20 ` Nicolas Dufresne
2025-04-22 21:13   ` Nicolas Dufresne
2025-04-23  7:19     ` [EXT] " Ming Qian
2025-04-12 15:15 ` Markus Elfring
2025-04-22 21:16   ` Nicolas Dufresne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox