mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil+cisco@kernel.org>
To: Jai Luthra <jai.luthra@ideasonboard.com>,
	Florian Fainelli <florian.fainelli@broadcom.com>,
	Tomasz Figa <tfiga@chromium.org>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Raspberry Pi Kernel Maintenance <kernel-list@raspberrypi.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Kieran Bingham <kieran.bingham@ideasonboard.com>,
	Dave Stevenson <dave.stevenson@raspberrypi.com>,
	Naushir Patuck <naush@raspberrypi.com>,
	Stefan Wahren <wahrenst@gmx.net>,
	Paul Elder <paul.elder@ideasonboard.com>,
	linux-media@vger.kernel.org,
	linux-rpi-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 07/10] media: videobuf2: Allow exporting of a struct dmabuf
Date: Thu, 5 Nov 2026 13:13:57 +0100	[thread overview]
Message-ID: <0923d843-b621-495e-8573-d55c65eb5e27@kernel.org> (raw)
In-Reply-To: <20260917-b4-vchiq-isp-v5-7-2d8870add2c0@ideasonboard.com>

On 9/17/26 10:23, Jai Luthra wrote:
> From: Dave Stevenson <dave.stevenson@raspberrypi.com>
> 
> videobuf2 only allowed exporting a dmabuf as a file descriptor,
> but there are instances where having the struct dma_buf is
> useful within the kernel.
> 
> Split the current implementation into two, one step which
> exports a struct dma_buf, and the second which converts that
> into an fd.
> 
> Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
> Tested-by: Paul Elder <paul.elder@ideasonboard.com>
> Signed-off-by: Jai Luthra <jai.luthra@ideasonboard.com>

Reviewed-by: Hans Verkuil <hverkuil+cisco@kernel.org>

Regards,

	Hans

> ---
> Changes in v5:
> - Update documentation of return type to only ERR_PTR and not NULL
> Changes in v4:
> - Return a pointer to struct dmabuf instead of passing it as a double
>   pointer argument and returning an int for errors (Laurent)
> - Document the return type (Paul)
> ---
>  drivers/media/common/videobuf2/videobuf2-core.c | 45 ++++++++++++++++---------
>  include/media/videobuf2-core.h                  | 16 +++++++++
>  2 files changed, 45 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
> index 5e318165659f..7b99d39d7cb1 100644
> --- a/drivers/media/common/videobuf2/videobuf2-core.c
> +++ b/drivers/media/common/videobuf2/videobuf2-core.c
> @@ -2419,50 +2419,63 @@ 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, struct vb2_buffer *vb,
> -		    unsigned int plane, unsigned int flags)
> +struct dma_buf *vb2_core_expbuf_dmabuf(struct vb2_queue *q,
> +				       struct vb2_buffer *vb,
> +				       unsigned int plane, unsigned int flags)
>  {
>  	struct vb2_plane *vb_plane;
> -	int ret;
> -	struct dma_buf *dbuf;
> +	struct dma_buf *dmabuf;
>  
>  	if (q->memory != VB2_MEMORY_MMAP) {
>  		dprintk(q, 1, "queue is not currently set up for mmap\n");
> -		return -EINVAL;
> +		return ERR_PTR(-EINVAL);
>  	}
>  
>  	if (!q->mem_ops->get_dmabuf) {
>  		dprintk(q, 1, "queue does not support DMA buffer exporting\n");
> -		return -EINVAL;
> +		return ERR_PTR(-EINVAL);
>  	}
>  
>  	if (flags & ~(O_CLOEXEC | O_ACCMODE)) {
> -		dprintk(q, 1, "queue does support only O_CLOEXEC and access mode flags\n");
> -		return -EINVAL;
> +		dprintk(q, 1, "queue supports only O_CLOEXEC and access mode flags\n");
> +		return ERR_PTR(-EINVAL);
>  	}
>  
>  	if (plane >= vb->num_planes) {
>  		dprintk(q, 1, "buffer plane out of range\n");
> -		return -EINVAL;
> +		return ERR_PTR(-EINVAL);
>  	}
>  
>  	if (vb2_fileio_is_active(q)) {
>  		dprintk(q, 1, "expbuf: file io in progress\n");
> -		return -EBUSY;
> +		return ERR_PTR(-EBUSY);
>  	}
>  
>  	vb_plane = &vb->planes[plane];
>  
> -	dbuf = call_ptr_memop(get_dmabuf,
> -			      vb,
> -			      vb_plane->mem_priv,
> -			      flags & O_ACCMODE);
> -	if (IS_ERR_OR_NULL(dbuf)) {
> +	dmabuf = call_ptr_memop(get_dmabuf, vb, vb_plane->mem_priv,
> +				flags & O_ACCMODE);
> +	if (IS_ERR_OR_NULL(dmabuf)) {
>  		dprintk(q, 1, "failed to export buffer %d, plane %d\n",
>  			vb->index, plane);
> -		return -EINVAL;
> +		if (!dmabuf)
> +			dmabuf = ERR_PTR(-EINVAL);
>  	}
>  
> +	return dmabuf;
> +}
> +EXPORT_SYMBOL_GPL(vb2_core_expbuf_dmabuf);
> +
> +int vb2_core_expbuf(struct vb2_queue *q, int *fd, struct vb2_buffer *vb,
> +		    unsigned int plane, unsigned int flags)
> +{
> +	struct dma_buf *dbuf;
> +	int ret;
> +
> +	dbuf = vb2_core_expbuf_dmabuf(q, vb, plane, flags);
> +	if (IS_ERR(dbuf))
> +		return PTR_ERR(dbuf);
> +
>  	ret = dma_buf_fd(dbuf, flags & ~O_ACCMODE);
>  	if (ret < 0) {
>  		dprintk(q, 3, "buffer %d, plane %d failed to export (%d)\n",
> diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
> index feda638d0064..45bfe8a2a12a 100644
> --- a/include/media/videobuf2-core.h
> +++ b/include/media/videobuf2-core.h
> @@ -954,6 +954,22 @@ int vb2_core_streamon(struct vb2_queue *q, unsigned int type);
>   */
>  int vb2_core_streamoff(struct vb2_queue *q, unsigned int type);
>  
> +/**
> + * vb2_core_expbuf_dmabuf() - Export a buffer as a dma_buf structure
> + * @q:		pointer to &struct vb2_queue with videobuf2 queue
> + * @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
> + *		include/uapi/asm-generic/fcntl.h.
> + *		Currently, the only used flag is %O_CLOEXEC.
> + *		is supported, refer to manual of open syscall for more details.
> + *
> + * Return: returns a pointer to &struct dma_buf on success; an ERR_PTR otherwise.
> + */
> +struct dma_buf *vb2_core_expbuf_dmabuf(struct vb2_queue *q,
> +				       struct vb2_buffer *vb,
> +				       unsigned int plane, unsigned int flags);
> +
>  /**
>   * vb2_core_expbuf() - Export a buffer as a file descriptor.
>   * @q:		pointer to &struct vb2_queue with videobuf2 queue.
> 


  reply	other threads:[~2026-11-05 12:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17  8:23 [PATCH v5 00/10] media: Add support for Broadcom/RPi BCM2835 ISP Jai Luthra
2026-09-17  8:23 ` [PATCH v5 01/10] media: videobuf2-core: Move type check out of vb2_core_expbuf() Jai Luthra
2026-10-02 10:56   ` Paul Elder
2026-11-04 11:49   ` Jai Luthra
2026-11-05 12:09   ` Hans Verkuil
2026-09-17  8:23 ` [PATCH v5 02/10] platform/raspberrypi: vchiq-mmal: Include missing headers Jai Luthra
2026-09-17  8:23 ` [PATCH v5 03/10] platform/raspberrypi: vchiq-mmal: Move headers to include/linux Jai Luthra
2026-09-17  8:23 ` [PATCH v5 04/10] platform/raspberrypi: vchiq-mmal: Support ISP parameters and stats Jai Luthra
2026-09-17  8:23 ` [PATCH v5 05/10] platform/raspberrypi: vchiq-mmal: Support bayer and gray formats Jai Luthra
2026-10-02 10:33   ` Paul Elder
2026-09-17  8:23 ` [PATCH v5 06/10] platform/raspberrypi: vchiq: Add helpers for vchiq driver data Jai Luthra
2026-09-17  8:23 ` [PATCH v5 07/10] media: videobuf2: Allow exporting of a struct dmabuf Jai Luthra
2026-11-05 12:13   ` Hans Verkuil [this message]
2026-09-17  8:23 ` [PATCH v5 08/10] media: platform: broadcom: Move unicam driver to subdir Jai Luthra
2026-09-17  8:23 ` [PATCH v5 09/10] media: platform: broadcom: Add bcm2835-isp driver Jai Luthra
2026-10-02 10:52   ` Paul Elder
2026-09-17  8:23 ` [PATCH v5 10/10] platform/raspberrypi: vchiq: Load bcm2835_isp driver from vchiq Jai Luthra
2026-10-05 16:13 ` [PATCH v5 00/10] media: Add support for Broadcom/RPi BCM2835 ISP Dave Stevenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0923d843-b621-495e-8573-d55c65eb5e27@kernel.org \
    --to=hverkuil+cisco@kernel.org \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=florian.fainelli@broadcom.com \
    --cc=jai.luthra@ideasonboard.com \
    --cc=kernel-list@raspberrypi.com \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mchehab@kernel.org \
    --cc=naush@raspberrypi.com \
    --cc=paul.elder@ideasonboard.com \
    --cc=tfiga@chromium.org \
    --cc=wahrenst@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®