Commit ce468670 authored by Satendra Singh Thakur's avatar Satendra Singh Thakur Committed by Mauro Carvalho Chehab

media: vb2: Fix a bug about unnecessary calls to queue cancel and free

Currently, there's a logic with checks if *count is non-zero,
q->num_buffers is zero and q->memory is different than memory.

That's flawed when the device is initialized, or after the
queues are freed, as it does, unnecessary calls to
__vb2_queue_cancel() and  __vb2_queue_free().

That can be avoided by making sure that q->memory is set to
VB2_MEMORY_UNKNOWN at vb2_core_queue_init(), and adding such
check at the loop.

[mchehab@s-opensource.com: fix checkpatch issues and improve the
 patch, by setting q->memory to zero at vb2_core_queue_init]
Signed-off-by: default avatarSatendra Singh Thakur <satendra.t@samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
Acked-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent 0097ff8e
...@@ -524,7 +524,7 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) ...@@ -524,7 +524,7 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
q->num_buffers -= buffers; q->num_buffers -= buffers;
if (!q->num_buffers) { if (!q->num_buffers) {
q->memory = 0; q->memory = VB2_MEMORY_UNKNOWN;
INIT_LIST_HEAD(&q->queued_list); INIT_LIST_HEAD(&q->queued_list);
} }
return 0; return 0;
...@@ -666,7 +666,8 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, ...@@ -666,7 +666,8 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
return -EBUSY; return -EBUSY;
} }
if (*count == 0 || q->num_buffers != 0 || q->memory != memory) { if (*count == 0 || q->num_buffers != 0 ||
(q->memory != VB2_MEMORY_UNKNOWN && q->memory != memory)) {
/* /*
* We already have buffers allocated, so first check if they * We already have buffers allocated, so first check if they
* are not in use and can be freed. * are not in use and can be freed.
...@@ -1999,6 +2000,8 @@ int vb2_core_queue_init(struct vb2_queue *q) ...@@ -1999,6 +2000,8 @@ int vb2_core_queue_init(struct vb2_queue *q)
mutex_init(&q->mmap_lock); mutex_init(&q->mmap_lock);
init_waitqueue_head(&q->done_wq); init_waitqueue_head(&q->done_wq);
q->memory = VB2_MEMORY_UNKNOWN;
if (q->buf_struct_size == 0) if (q->buf_struct_size == 0)
q->buf_struct_size = sizeof(struct vb2_buffer); q->buf_struct_size = sizeof(struct vb2_buffer);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment