CHROMIUM: v4l2-m2m: drop rdy_queue on STREAMOFF
authorJohn Sheu <sheu@chromium.org>
Thu, 13 Dec 2012 01:35:08 +0000 (17:35 -0800)
committerChromeBot <chrome-bot@google.com>
Sat, 12 Jan 2013 02:15:15 +0000 (18:15 -0800)
When a v4l2-m2m context gets a STREAMOFF call on either its CAPTURE or
OUTPUT queues, we should:
* Drop the corresponding rdy_queue, since a subsequent STREAMON expects
  an empty queue.
* Deschedule the context, as it now has at least one empty queue and
  cannot run.

Signed-off-by: John Sheu <sheu@google.com>
BUG=chrome-os-partner:10057
TEST=build, run on exynos

Change-Id: Id3994907ccb6a6ee7af187e0a5d3e55cda94c76b
Reviewed-on: https://gerrit.chromium.org/gerrit/39643
Reviewed-by: Pawel Osciak <posciak@chromium.org>
Commit-Queue: John Sheu <sheu@chromium.org>
Tested-by: John Sheu <sheu@chromium.org>
drivers/media/video/v4l2-mem2mem.c

index 8cad5ac..3f88199 100644 (file)
@@ -405,10 +405,35 @@ EXPORT_SYMBOL_GPL(v4l2_m2m_streamon);
 int v4l2_m2m_streamoff(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
                       enum v4l2_buf_type type)
 {
-       struct vb2_queue *vq;
+       struct v4l2_m2m_dev *m2m_dev;
+       struct v4l2_m2m_queue_ctx *q_ctx;
+       unsigned long flags_job, flags;
+       int ret;
 
-       vq = v4l2_m2m_get_vq(m2m_ctx, type);
-       return vb2_streamoff(vq, type);
+       q_ctx = get_queue_ctx(m2m_ctx, type);
+       ret = vb2_streamoff(&q_ctx->q, type);
+       if (ret)
+               return ret;
+
+       m2m_dev = m2m_ctx->m2m_dev;
+       spin_lock_irqsave(&m2m_dev->job_spinlock, flags_job);
+       /* We should not be scheduled anymore, since we're dropping a queue. */
+       INIT_LIST_HEAD(&m2m_ctx->queue);
+       m2m_ctx->job_flags = 0;
+
+       spin_lock_irqsave(&q_ctx->rdy_spinlock, flags);
+       /* Drop queue, since streamoff returns device to the same state as after
+        * calling reqbufs. */
+       INIT_LIST_HEAD(&q_ctx->rdy_queue);
+       spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
+
+       if (m2m_dev->curr_ctx == m2m_ctx) {
+               m2m_dev->curr_ctx = NULL;
+               wake_up(&m2m_ctx->finished);
+       }
+       spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
+
+       return 0;
 }
 EXPORT_SYMBOL_GPL(v4l2_m2m_streamoff);