[PATCH v4 01/10] media: videobuf2-core: Move type check out of vb2_core_expbuf()

From: Jai Luthra

Date: Wed Sep 16 2026 - 11:28:07 EST


vb2_core_expbuf() takes the type of the exportbuffer as an argument and
checks if it matches the type of the vb2 queue. Move that check to the
caller (vb2_expbuf).

There is only one other user of this, which is dvb-core, where the check
was anyway redundant as it passed the vb2 queue type instead. So update
it too.

Signed-off-by: Jai Luthra <jai.luthra@xxxxxxxxxxxxxxxx>
Suggested-by: Laurent Pinchart <laurent.pinchart@xxxxxxxxxxxxxxxx>
Link: https://lore.kernel.org/all/20260910150454.GP1892234%40killaraus.ideasonboard.com
---
Changes in v4:
- New patch in v4
---
drivers/media/common/videobuf2/videobuf2-core.c | 9 ++-------
drivers/media/common/videobuf2/videobuf2-v4l2.c | 8 ++++++--
drivers/media/dvb-core/dvb_vb2.c | 3 +--
include/media/videobuf2-core.h | 5 ++---
4 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
index b0a6084f1757..5e318165659f 100644
--- a/drivers/media/common/videobuf2/videobuf2-core.c
+++ b/drivers/media/common/videobuf2/videobuf2-core.c
@@ -2419,8 +2419,8 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long offset,
return 0;
}

-int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
- struct vb2_buffer *vb, unsigned int plane, unsigned int flags)
+int vb2_core_expbuf(struct vb2_queue *q, int *fd, struct vb2_buffer *vb,
+ unsigned int plane, unsigned int flags)
{
struct vb2_plane *vb_plane;
int ret;
@@ -2441,11 +2441,6 @@ int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
return -EINVAL;
}

- if (type != q->type) {
- dprintk(q, 1, "invalid buffer type\n");
- return -EINVAL;
- }
-
if (plane >= vb->num_planes) {
dprintk(q, 1, "buffer plane out of range\n");
return -EINVAL;
diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c
index 5a1ee5eb9c0f..aee1a9244a7b 100644
--- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
+++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
@@ -877,14 +877,18 @@ int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
{
struct vb2_buffer *vb;

+ if (eb->type != q->type) {
+ dprintk(q, 1, "invalid buffer type\n");
+ return -EINVAL;
+ }
+
vb = vb2_get_buffer(q, eb->index);
if (!vb) {
dprintk(q, 1, "can't find the requested buffer %u\n", eb->index);
return -EINVAL;
}

- return vb2_core_expbuf(q, &eb->fd, eb->type, vb,
- eb->plane, eb->flags);
+ return vb2_core_expbuf(q, &eb->fd, vb, eb->plane, eb->flags);
}
EXPORT_SYMBOL_GPL(vb2_expbuf);

diff --git a/drivers/media/dvb-core/dvb_vb2.c b/drivers/media/dvb-core/dvb_vb2.c
index 672b0efdca21..fe7a6554b30e 100644
--- a/drivers/media/dvb-core/dvb_vb2.c
+++ b/drivers/media/dvb-core/dvb_vb2.c
@@ -357,8 +357,7 @@ int dvb_vb2_expbuf(struct dvb_vb2_ctx *ctx, struct dmx_exportbuffer *exp)
return -EINVAL;
}

- ret = vb2_core_expbuf(&ctx->vb_q, &exp->fd, q->type, vb2,
- 0, exp->flags);
+ ret = vb2_core_expbuf(&ctx->vb_q, &exp->fd, vb2, 0, exp->flags);
if (ret) {
dprintk(1, "[%s] index=%d errno=%d\n", ctx->name,
exp->index, ret);
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 4b4f4c15c53a..feda638d0064 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -959,7 +959,6 @@ int vb2_core_streamoff(struct vb2_queue *q, unsigned int type);
* @q: pointer to &struct vb2_queue with videobuf2 queue.
* @fd: pointer to the file descriptor associated with DMABUF
* (set by driver).
- * @type: buffer type.
* @vb: pointer to struct &vb2_buffer.
* @plane: index of the plane to be exported, 0 for single plane queues
* @flags: file flags for newly created file, as defined at
@@ -973,8 +972,8 @@ int vb2_core_streamoff(struct vb2_queue *q, unsigned int type);
*
* Return: returns zero on success; an error code otherwise.
*/
-int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
- struct vb2_buffer *vb, unsigned int plane, unsigned int flags);
+int vb2_core_expbuf(struct vb2_queue *q, int *fd, struct vb2_buffer *vb,
+ unsigned int plane, unsigned int flags);

/**
* vb2_core_queue_init() - initialize a videobuf2 queue

--
2.55.0