diff mbox series

[RFC,1/3] media: videobuf2: WARN if !vb2_queue.buf_ops

Message ID 20240603152548.107158-2-jacopo.mondi@ideasonboard.com (mailing list archive)
State New
Headers show
Series media: videobuf2: Allow driver to override vb2_queue.buf_ops | expand

Commit Message

Jacopo Mondi June 3, 2024, 3:25 p.m. UTC
The videobuf2 framework unconditionally set 'struct vb2_queue.buf_ops'
to 'v4l2_buf_ops' in vb2_queue_init_name() and does not allow drivers to
overwrite it.

The framework then assumes all 'buf_ops' operations to be present and
valid.

To prepare for allowing drivers to override the 'buf_ops' members
implementation but still guarantee all members are correctly populated
and valid, WARN() if any of the 'buf_ops' operations is not available in
the function call wrappers.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 drivers/media/common/videobuf2/videobuf2-core.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
index b6bf8f232f48..8ceae97a0f08 100644
--- a/drivers/media/common/videobuf2/videobuf2-core.c
+++ b/drivers/media/common/videobuf2/videobuf2-core.c
@@ -187,15 +187,19 @@  module_param(debug, int, 0644);
 #define call_bufop(q, op, args...)					\
 ({									\
 	int ret = 0;							\
-	if (q && q->buf_ops && q->buf_ops->op)				\
-		ret = q->buf_ops->op(args);				\
+	if (q) {							\
+		if (!WARN_ON(!q->buf_ops) && !WARN_ON(!q->buf_ops->op))	\
+			ret = q->buf_ops->op(args);			\
+	}								\
 	ret;								\
 })
 
 #define call_void_bufop(q, op, args...)					\
 ({									\
-	if (q && q->buf_ops && q->buf_ops->op)				\
-		q->buf_ops->op(args);					\
+	if (q) {							\
+		if (!WARN_ON(!q->buf_ops) && !WARN_ON(!q->buf_ops->op))	\
+			q->buf_ops->op(args);				\
+	}								\
 })
 
 static void __vb2_queue_cancel(struct vb2_queue *q);