[PATCH 3/5] media: qcom: camss: vfe: call vb2_buffer_done() outside output_lock

From: Robert Ijtsma via B4 Relay

Date: Fri Nov 27 2026 - 15:27:09 EST


From: Robert Ijtsma <robertijtsma@xxxxxxxxx>

vfe_flush_buffers() currently invokes vb2_buffer_done() while holding
vfe->output_lock, unlike vfe_buf_done(). Returning buffers to vb2 can
re-enter driver callbacks or run user hooks under an IRQ-safe spinlock.

Splice pending_bufs into a local list, detach active buffer pointers and
reset gen2.active_num under output_lock, and complete the buffers after
releasing output_lock. Also drop the now-unused vfe_buf_flush_pending()
helper.

Fixes: ff11faad8a9e ("media: qcom: camss: vfe: Clear active buffer pointers after flushing")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Robert Ijtsma <robertijtsma@xxxxxxxxx>
---
drivers/media/platform/qcom/camss/camss-vfe.c | 56 +++++++++++++--------------
1 file changed, 26 insertions(+), 30 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss-vfe.c b/drivers/media/platform/qcom/camss/camss-vfe.c
index b5a8196c9145163dfa3ee1af549a4684901e2fa7..b01c7c919de459bdb6581dba81c15a176e551208 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe.c
@@ -757,23 +757,6 @@ void vfe_buf_add_pending(struct vfe_output *output,
list_add_tail(&buffer->queue, &output->pending_bufs);
}

-/*
- * vfe_buf_flush_pending - Flush all pending buffers.
- * @output: VFE output
- * @state: vb2 buffer state
- */
-static void vfe_buf_flush_pending(struct vfe_output *output,
- enum vb2_buffer_state state)
-{
- struct camss_buffer *buf;
- struct camss_buffer *t;
-
- list_for_each_entry_safe(buf, t, &output->pending_bufs, queue) {
- vb2_buffer_done(&buf->vb.vb2_buf, state);
- list_del(&buf->queue);
- }
-}
-
int vfe_put_output(struct vfe_line *line)
{
struct vfe_device *vfe = to_vfe(line);
@@ -1215,31 +1198,44 @@ int vfe_flush_buffers(struct camss_video *vid,
struct vfe_line *line = container_of(vid, struct vfe_line, video_out);
struct vfe_device *vfe = to_vfe(line);
struct vfe_output *output;
+ struct camss_buffer *buf, *t;
+ struct camss_buffer *b0, *b1, *blast;
+ LIST_HEAD(local_pending);
unsigned long flags;

output = &line->output;

spin_lock_irqsave(&vfe->output_lock, flags);

- vfe_buf_flush_pending(output, state);
+ list_splice_init(&output->pending_bufs, &local_pending);

- if (output->buf[0]) {
- vb2_buffer_done(&output->buf[0]->vb.vb2_buf, state);
- output->buf[0] = NULL;
- }
+ b0 = output->buf[0];
+ output->buf[0] = NULL;

- if (output->buf[1]) {
- vb2_buffer_done(&output->buf[1]->vb.vb2_buf, state);
- output->buf[1] = NULL;
- }
+ b1 = output->buf[1];
+ output->buf[1] = NULL;

- if (output->last_buffer) {
- vb2_buffer_done(&output->last_buffer->vb.vb2_buf, state);
- output->last_buffer = NULL;
- }
+ blast = output->last_buffer;
+ output->last_buffer = NULL;
+
+ output->gen2.active_num = 0;

spin_unlock_irqrestore(&vfe->output_lock, flags);

+ list_for_each_entry_safe(buf, t, &local_pending, queue) {
+ list_del(&buf->queue);
+ vb2_buffer_done(&buf->vb.vb2_buf, state);
+ }
+
+ if (b0)
+ vb2_buffer_done(&b0->vb.vb2_buf, state);
+
+ if (b1)
+ vb2_buffer_done(&b1->vb.vb2_buf, state);
+
+ if (blast)
+ vb2_buffer_done(&blast->vb.vb2_buf, state);
+
return 0;
}


--
2.47.3