aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/v4l2-core/videobuf2-core.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2014-06-03 17:53:25 -0400
committerMauro Carvalho Chehab <m.chehab@samsung.com>2014-07-17 15:19:04 -0400
commit4bb7267dc41247810815e8b15f0e9fb1456c8d8c (patch)
tree04379e02986bc6de1d6d395a9f66b33c27cef9b0 /drivers/media/v4l2-core/videobuf2-core.c
parent9241650d62f79a3da01f1d5e8ebd195083330b75 (diff)
[media] v4l: vb2: Add fatal error condition flag
When a fatal error occurs that render the device unusable, the only options for a driver to signal the error condition to userspace is to set the V4L2_BUF_FLAG_ERROR flag when dequeuing buffers and to return an error from the buffer prepare handler when queuing buffers. The buffer error flag indicates a transient error and can't be used by applications to detect fatal errors. Returning an error from vb2_qbuf() is thus the only real indication that a fatal error occurred. However, this is difficult to handle for multithreaded applications that requeue buffers from a thread other than the control thread. In particular the poll() call in the control thread will not notify userspace of the error. This patch adds an explicit mechanism to report fatal errors to userspace. Drivers can call the vb2_queue_error() function to signal a fatal error. From this moment on, buffer preparation will return -EIO to userspace, and vb2_poll() will set the POLLERR flag and return immediately. The error flag is cleared when cancelling the queue, either at stream off time (through vb2_streamoff) or when releasing the queue with vb2_queue_release(). Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Diffstat (limited to 'drivers/media/v4l2-core/videobuf2-core.c')
-rw-r--r--drivers/media/v4l2-core/videobuf2-core.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index 1fc85fb964ce..a5c41cc65d1c 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1606,6 +1606,11 @@ static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
1606 return -EINVAL; 1606 return -EINVAL;
1607 } 1607 }
1608 1608
1609 if (q->error) {
1610 dprintk(1, "fatal error occurred on queue\n");
1611 return -EIO;
1612 }
1613
1609 vb->state = VB2_BUF_STATE_PREPARING; 1614 vb->state = VB2_BUF_STATE_PREPARING;
1610 vb->v4l2_buf.timestamp.tv_sec = 0; 1615 vb->v4l2_buf.timestamp.tv_sec = 0;
1611 vb->v4l2_buf.timestamp.tv_usec = 0; 1616 vb->v4l2_buf.timestamp.tv_usec = 0;
@@ -1903,6 +1908,11 @@ static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking)
1903 return -EINVAL; 1908 return -EINVAL;
1904 } 1909 }
1905 1910
1911 if (q->error) {
1912 dprintk(1, "Queue in error state, will not wait for buffers\n");
1913 return -EIO;
1914 }
1915
1906 if (!list_empty(&q->done_list)) { 1916 if (!list_empty(&q->done_list)) {
1907 /* 1917 /*
1908 * Found a buffer that we were waiting for. 1918 * Found a buffer that we were waiting for.
@@ -1928,7 +1938,8 @@ static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking)
1928 */ 1938 */
1929 dprintk(3, "will sleep waiting for buffers\n"); 1939 dprintk(3, "will sleep waiting for buffers\n");
1930 ret = wait_event_interruptible(q->done_wq, 1940 ret = wait_event_interruptible(q->done_wq,
1931 !list_empty(&q->done_list) || !q->streaming); 1941 !list_empty(&q->done_list) || !q->streaming ||
1942 q->error);
1932 1943
1933 /* 1944 /*
1934 * We need to reevaluate both conditions again after reacquiring 1945 * We need to reevaluate both conditions again after reacquiring
@@ -2125,6 +2136,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
2125 q->streaming = 0; 2136 q->streaming = 0;
2126 q->start_streaming_called = 0; 2137 q->start_streaming_called = 0;
2127 q->queued_count = 0; 2138 q->queued_count = 0;
2139 q->error = 0;
2128 2140
2129 /* 2141 /*
2130 * Remove all buffers from videobuf's list... 2142 * Remove all buffers from videobuf's list...
@@ -2202,6 +2214,27 @@ static int vb2_internal_streamon(struct vb2_queue *q, enum v4l2_buf_type type)
2202} 2214}
2203 2215
2204/** 2216/**
2217 * vb2_queue_error() - signal a fatal error on the queue
2218 * @q: videobuf2 queue
2219 *
2220 * Flag that a fatal unrecoverable error has occurred and wake up all processes
2221 * waiting on the queue. Polling will now set POLLERR and queuing and dequeuing
2222 * buffers will return -EIO.
2223 *
2224 * The error flag will be cleared when cancelling the queue, either from
2225 * vb2_streamoff or vb2_queue_release. Drivers should thus not call this
2226 * function before starting the stream, otherwise the error flag will remain set
2227 * until the queue is released when closing the device node.
2228 */
2229void vb2_queue_error(struct vb2_queue *q)
2230{
2231 q->error = 1;
2232
2233 wake_up_all(&q->done_wq);
2234}
2235EXPORT_SYMBOL_GPL(vb2_queue_error);
2236
2237/**
2205 * vb2_streamon - start streaming 2238 * vb2_streamon - start streaming
2206 * @q: videobuf2 queue 2239 * @q: videobuf2 queue
2207 * @type: type argument passed from userspace to vidioc_streamon handler 2240 * @type: type argument passed from userspace to vidioc_streamon handler
@@ -2560,9 +2593,9 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
2560 2593
2561 /* 2594 /*
2562 * There is nothing to wait for if no buffer has been queued and the 2595 * There is nothing to wait for if no buffer has been queued and the
2563 * queue isn't streaming. 2596 * queue isn't streaming, or if the error flag is set.
2564 */ 2597 */
2565 if (list_empty(&q->queued_list) && !vb2_is_streaming(q)) 2598 if ((list_empty(&q->queued_list) && !vb2_is_streaming(q)) || q->error)
2566 return res | POLLERR; 2599 return res | POLLERR;
2567 2600
2568 if (list_empty(&q->done_list)) 2601 if (list_empty(&q->done_list))