[PATCH 2/4] media: Store v4l2_fh in the vb_queue

From: Detlev Casanova

Date: Wed Sep 16 2026 - 10:36:46 EST


To be able to show the fd in the debug fs, add the v4l2_fh pointer to the
queue so that vb2 allocations can retrieve it.

Signed-off-by: Detlev Casanova <detlev.casanova@xxxxxxxxxxxxx>
---
drivers/media/common/videobuf2/v4l2-allocator.c | 16 +++++++++++-----
drivers/media/common/videobuf2/videobuf2-dma-contig.c | 1 +
include/media/v4l2-allocator.h | 2 +-
include/media/videobuf2-core.h | 1 +
4 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/media/common/videobuf2/v4l2-allocator.c b/drivers/media/common/videobuf2/v4l2-allocator.c
index 9dde9d4a342b..935fbbacd667 100644
--- a/drivers/media/common/videobuf2/v4l2-allocator.c
+++ b/drivers/media/common/videobuf2/v4l2-allocator.c
@@ -108,8 +108,8 @@ void v4l2_allocator_cleanup(struct v4l2_device *v4l2_dev)
}
EXPORT_SYMBOL_GPL(v4l2_allocator_cleanup);

-static int v4l2_allocator_add(struct v4l2_device *v4l2_dev, size_t size,
- dma_addr_t dma_addr, const char *name)
+static int v4l2_allocator_add(struct v4l2_device *v4l2_dev, size_t size, dma_addr_t dma_addr,
+ struct v4l2_fh *fh, const char *name)
{
struct v4l2_allocator *allocator = v4l2_dev->v4l2_allocator;
struct v4l2_allocator_entry *entry;
@@ -125,7 +125,13 @@ static int v4l2_allocator_add(struct v4l2_device *v4l2_dev, size_t size,
entry->dma_addr = dma_addr;
strscpy(entry->name, name, sizeof(entry->name));
get_task_comm(entry->creator, current->group_leader);
- entry->tgid = current->tgid;
+ if (fh) {
+ entry->fd = fh->fd;
+ entry->tgid = fh->tgid;
+ } else {
+ entry->fd = 0;
+ entry->tgid = current->tgid;
+ }

mutex_lock(&allocator->lock);
list_add(&entry->list, &allocator->list);
@@ -156,12 +162,12 @@ static void v4l2_allocator_remove(struct v4l2_device *v4l2_dev, size_t size, dma

void *v4l2_dma_alloc_attrs(struct v4l2_device *v4l2_dev, struct device *dev,
size_t size, dma_addr_t *dma_handle,
- gfp_t flag, unsigned long attrs, const char *name)
+ gfp_t flag, unsigned long attrs, struct v4l2_fh *fh, const char *name)
{
void *ret = dma_alloc_attrs(dev, size, dma_handle, flag, attrs);

if (ret && v4l2_dev)
- v4l2_allocator_add(v4l2_dev, size, *dma_handle, name);
+ v4l2_allocator_add(v4l2_dev, size, *dma_handle, fh, name);

return ret;
}
diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
index b6b7ddc96b9c..30e136dd02b7 100644
--- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c
+++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
@@ -205,6 +205,7 @@ static int vb2_dc_alloc_coherent(struct vb2_dc_buf *buf)
&buf->dma_addr,
GFP_KERNEL | q->gfp_flags,
buf->attrs,
+ q->v4l2_fh,
name);
if (!buf->cookie)
return -ENOMEM;
diff --git a/include/media/v4l2-allocator.h b/include/media/v4l2-allocator.h
index f3fe0da10321..cdf0569bea0a 100644
--- a/include/media/v4l2-allocator.h
+++ b/include/media/v4l2-allocator.h
@@ -19,7 +19,7 @@ void v4l2_allocator_cleanup(struct v4l2_device *v4l2_dev);

void *v4l2_dma_alloc_attrs(struct v4l2_device *v4l2_dev, struct device *dev,
size_t size, dma_addr_t *dma_handle,
- gfp_t flag, unsigned long attrs, const char *name);
+ gfp_t flag, unsigned long attrs, struct v4l2_fh *fh, const char *name);

void v4l2_dma_free_attrs(struct v4l2_device *v4l2_dev, struct device *dev,
size_t size, void *cpu_addr,
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 83a5aea34f3c..aa47f1c7c9d1 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -604,6 +604,7 @@ struct vb2_queue {
unsigned int io_modes;
struct device *dev;
struct v4l2_device *v4l2_dev;
+ struct v4l2_fh *v4l2_fh;
unsigned long dma_attrs;
unsigned int bidirectional:1;
unsigned int fileio_read_once:1;

--
2.55.0