[media] vb2: Move buffer cache synchronisation to prepare from queue
authorSakari Ailus <sakari.ailus@linux.intel.com>
Wed, 31 May 2017 14:17:26 +0000 (11:17 -0300)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Thu, 8 Jun 2017 17:52:02 +0000 (14:52 -0300)
The buffer cache should be synchronised in buffer preparation, not when
the buffer is queued to the device. Fix this.

Mmap buffers do not need cache synchronisation since they are always
coherent.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/v4l2-core/videobuf2-core.c

index 9f3ce3b..3107e21 100644 (file)
@@ -1227,23 +1227,19 @@ err:
 static void __enqueue_in_driver(struct vb2_buffer *vb)
 {
        struct vb2_queue *q = vb->vb2_queue;
-       unsigned int plane;
 
        vb->state = VB2_BUF_STATE_ACTIVE;
        atomic_inc(&q->owned_by_drv_count);
 
        trace_vb2_buf_queue(q, vb);
 
-       /* sync buffers */
-       for (plane = 0; plane < vb->num_planes; ++plane)
-               call_void_memop(vb, prepare, vb->planes[plane].mem_priv);
-
        call_void_vb_qop(vb, buf_queue, vb);
 }
 
 static int __buf_prepare(struct vb2_buffer *vb, const void *pb)
 {
        struct vb2_queue *q = vb->vb2_queue;
+       unsigned int plane;
        int ret;
 
        if (q->error) {
@@ -1268,11 +1264,19 @@ static int __buf_prepare(struct vb2_buffer *vb, const void *pb)
                ret = -EINVAL;
        }
 
-       if (ret)
+       if (ret) {
                dprintk(1, "buffer preparation failed: %d\n", ret);
-       vb->state = ret ? VB2_BUF_STATE_DEQUEUED : VB2_BUF_STATE_PREPARED;
+               vb->state = VB2_BUF_STATE_DEQUEUED;
+               return ret;
+       }
 
-       return ret;
+       /* sync buffers */
+       for (plane = 0; plane < vb->num_planes; ++plane)
+               call_void_memop(vb, prepare, vb->planes[plane].mem_priv);
+
+       vb->state = VB2_BUF_STATE_PREPARED;
+
+       return 0;
 }
 
 int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb)