From: Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx> The check for the number of buffers requested against the maximum, VB2_MAX_FRAME, was performed before checking queue's minimum number of buffers. Reverse the order, thus ensuring that under no circumstances num_buffers exceeds VB2_MAX_FRAME here. Also add a warning of the condition. Signed-off-by: Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx> Signed-off-by: Mauro Carvalho Chehab <mchehab@xxxxxxxxxxxxxxxx> --- drivers/media/common/videobuf/videobuf2-core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/common/videobuf/videobuf2-core.c b/drivers/media/common/videobuf/videobuf2-core.c index 1793bdb1fe54..ba04103f2f32 100644 --- a/drivers/media/common/videobuf/videobuf2-core.c +++ b/drivers/media/common/videobuf/videobuf2-core.c @@ -700,8 +700,9 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, /* * Make sure the requested values and current defaults are sane. */ - num_buffers = min_t(unsigned int, *count, VB2_MAX_FRAME); - num_buffers = max_t(unsigned int, num_buffers, q->min_buffers_needed); + WARN_ON(q->min_buffers_needed > VB2_MAX_FRAME); + num_buffers = max_t(unsigned int, *count, q->min_buffers_needed); + num_buffers = min_t(unsigned int, num_buffers, VB2_MAX_FRAME); memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); q->memory = memory; -- 2.14.3