]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
[media] v4l: vb2: Add a function to discard all DONE buffers
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Mon, 10 Mar 2014 00:42:52 +0000 (21:42 -0300)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Sun, 25 May 2014 14:37:49 +0000 (11:37 -0300)
When suspending a device while a video stream is active all buffers
marked as done but not dequeued yet will be kept across suspend and
given back to userspace after resume. This will result in outdated
buffers being dequeued.

Introduce a new vb2 function to mark all done buffers as erroneous
instead, to be used by drivers at resume time.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Sakari Ailus <sakari.ailus@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
drivers/media/v4l2-core/videobuf2-core.c
include/media/videobuf2-core.h

index 349e659d75fb861359165665638fad93a2293631..7c4489c4236502042fc1fcb3a0ff545f2f7639a7 100644 (file)
@@ -1199,6 +1199,30 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
 }
 EXPORT_SYMBOL_GPL(vb2_buffer_done);
 
+/**
+ * vb2_discard_done() - discard all buffers marked as DONE
+ * @q:         videobuf2 queue
+ *
+ * This function is intended to be used with suspend/resume operations. It
+ * discards all 'done' buffers as they would be too old to be requested after
+ * resume.
+ *
+ * Drivers must stop the hardware and synchronize with interrupt handlers and/or
+ * delayed works before calling this function to make sure no buffer will be
+ * touched by the driver and/or hardware.
+ */
+void vb2_discard_done(struct vb2_queue *q)
+{
+       struct vb2_buffer *vb;
+       unsigned long flags;
+
+       spin_lock_irqsave(&q->done_lock, flags);
+       list_for_each_entry(vb, &q->done_list, done_entry)
+               vb->state = VB2_BUF_STATE_ERROR;
+       spin_unlock_irqrestore(&q->done_lock, flags);
+}
+EXPORT_SYMBOL_GPL(vb2_discard_done);
+
 /**
  * __fill_vb2_buffer() - fill a vb2_buffer with information provided in a
  * v4l2_buffer by the userspace. The caller has already verified that struct
index bca25dc53f9d204ef0773db521dbeba797705728..8fab6fa0dbfb08c7c8f272f7fa751db780a169a5 100644 (file)
@@ -432,6 +432,7 @@ void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no);
 void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no);
 
 void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);
+void vb2_discard_done(struct vb2_queue *q);
 int vb2_wait_for_all_buffers(struct vb2_queue *q);
 
 int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b);