mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: raspberrypi: cfe: guard against empty dma_queue when scheduling
@ 2026-12-03 11:42 Haoran Wang
  0 siblings, 0 replies; only message in thread
From: Haoran Wang @ 2026-12-03 11:42 UTC (permalink / raw)
  To: Tomi Valkeinen, Raspberry Pi Kernel Maintenance
  Cc: Mauro Carvalho Chehab, linux-media, linux-rpi-kernel, linux-kernel

cfe_schedule_next_csi2_job() and cfe_schedule_next_pisp_job() call
list_first_entry() on node->dma_queue without checking that the queue
is non-empty.  Both run only when cfe->job_ready is true, which
cfe_check_job_ready() establishes by requiring every enabled node to
have a non-empty queue, so the invariant currently holds but there is
no guard at the scheduling site.  If it is ever broken, list_first_entry()
returns a pointer into struct cfe_node instead of a struct cfe_buffer,
list_del() corrupts the empty list head and the CSI2 path programs a
garbage DMA address into the hardware.

Use list_first_entry_or_null() and skip the node, or abort the FE
submit for the PISP path, if the queue is unexpectedly empty.  A broken
invariant then yields a WARN_ON() instead of wild dereferences, list
corruption and a bogus DMA address.

This was found by static analysis and the trigger is theoretical, so
the change is a defensive guard at the scheduling site only.

Fixes: 6edb685abb2a ("media: raspberrypi: Add support for RP1-CFE")
Signed-off-by: Haoran Wang <haoranwangsec@gmail.com>
---
 drivers/media/platform/raspberrypi/rp1-cfe/cfe.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/raspberrypi/rp1-cfe/cfe.c b/drivers/media/platform/raspberrypi/rp1-cfe/cfe.c
index 8375ed3e97b9..9d0ac4262bb4 100644
--- a/drivers/media/platform/raspberrypi/rp1-cfe/cfe.c
+++ b/drivers/media/platform/raspberrypi/rp1-cfe/cfe.c
@@ -532,8 +532,10 @@ static void cfe_schedule_next_csi2_job(struct cfe_device *cfe)
 		if (!check_state(cfe, NODE_STREAMING, i))
 			continue;
 
-		buf = list_first_entry(&node->dma_queue, struct cfe_buffer,
-				       list);
+		buf = list_first_entry_or_null(&node->dma_queue,
+					       struct cfe_buffer, list);
+		if (WARN_ON(!buf))
+			continue;
 		node->next_frm = buf;
 		list_del(&buf->list);
 
@@ -565,8 +567,10 @@ static void cfe_schedule_next_pisp_job(struct cfe_device *cfe)
 		if (!check_state(cfe, NODE_STREAMING, i))
 			continue;
 
-		buf = list_first_entry(&node->dma_queue, struct cfe_buffer,
-				       list);
+		buf = list_first_entry_or_null(&node->dma_queue,
+					       struct cfe_buffer, list);
+		if (WARN_ON(!buf))
+			return;
 
 		trace_cfe_fe_schedule(node->id, &buf->vb.vb2_buf);
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-03 11:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03 11:42 [PATCH] media: raspberrypi: cfe: guard against empty dma_queue when scheduling Haoran Wang

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

all inboxes | Powered by JetHome®