On Wed Oct 15 10:53:24 2025 +0300, Laurent Pinchart wrote:
> The v4l2_m2m_get_vq() never returns a NULL pointer, as the internal
> get_queue_ctx() helper always returns a non-NULL pointer. Many drivers
> check the return value against NULL, due to a combination of old code
> and cargo-cult programming. Even v4l2-mem2mem.c contains unneeded NULL
> checks.
> 
> Clarify the API by documenting explicitly that a NULL check is not
> needed, and simplify the code by removing the unneeded NULL checks from
> v4l2-mem2mem.c.
> 
> Signed-off-by: Laurent Pinchart <[email protected]>
> Reviewed-by: Stefan Klug <[email protected]>
> Signed-off-by: Hans Verkuil <[email protected]>

Patch committed.

Thanks,
Hans Verkuil

 drivers/media/v4l2-core/v4l2-mem2mem.c | 12 +-----------
 include/media/v4l2-mem2mem.h           |  3 +++
 2 files changed, 4 insertions(+), 11 deletions(-)

---

diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c 
b/drivers/media/v4l2-core/v4l2-mem2mem.c
index 21acd9bc8607..9fa8833e445f 100644
--- a/drivers/media/v4l2-core/v4l2-mem2mem.c
+++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
@@ -123,13 +123,7 @@ static struct v4l2_m2m_queue_ctx *get_queue_ctx(struct 
v4l2_m2m_ctx *m2m_ctx,
 struct vb2_queue *v4l2_m2m_get_vq(struct v4l2_m2m_ctx *m2m_ctx,
                                       enum v4l2_buf_type type)
 {
-       struct v4l2_m2m_queue_ctx *q_ctx;
-
-       q_ctx = get_queue_ctx(m2m_ctx, type);
-       if (!q_ctx)
-               return NULL;
-
-       return &q_ctx->q;
+       return &get_queue_ctx(m2m_ctx, type)->q;
 }
 EXPORT_SYMBOL(v4l2_m2m_get_vq);
 
@@ -1285,8 +1279,6 @@ void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx,
        unsigned long flags;
 
        q_ctx = get_queue_ctx(m2m_ctx, vbuf->vb2_buf.vb2_queue->type);
-       if (!q_ctx)
-               return;
 
        spin_lock_irqsave(&q_ctx->rdy_spinlock, flags);
        list_add_tail(&b->list, &q_ctx->rdy_queue);
@@ -1388,8 +1380,6 @@ int v4l2_m2m_ioctl_remove_bufs(struct file *file, void 
*priv,
        struct v4l2_fh *fh = file_to_v4l2_fh(file);
        struct vb2_queue *q = v4l2_m2m_get_vq(fh->m2m_ctx, remove->type);
 
-       if (!q)
-               return -EINVAL;
        if (q->type != remove->type)
                return -EINVAL;
 
diff --git a/include/media/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h
index 500f81f399df..c82445929c68 100644
--- a/include/media/v4l2-mem2mem.h
+++ b/include/media/v4l2-mem2mem.h
@@ -153,6 +153,9 @@ void *v4l2_m2m_get_curr_priv(struct v4l2_m2m_dev *m2m_dev);
  *
  * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
  * @type: type of the V4L2 buffer, as defined by enum &v4l2_buf_type
+ *
+ * This function returns the capture queue when @type is a capture type, and 
the
+ * output queue otherwise. It never returns a NULL pointer.
  */
 struct vb2_queue *v4l2_m2m_get_vq(struct v4l2_m2m_ctx *m2m_ctx,
                                       enum v4l2_buf_type type);
_______________________________________________
linuxtv-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to