diff mbox series

[v4] media: videobuf2-dma-sg: fix vmap callback

Message ID 20231123223205.1425234-1-m.grzeschik@pengutronix.de (mailing list archive)
State New
Headers show
Series [v4] media: videobuf2-dma-sg: fix vmap callback | expand

Commit Message

Michael Grzeschik Nov. 23, 2023, 10:32 p.m. UTC
For dmabuf import users to be able to use the vaddr from another
videobuf2-dma-sg source, the exporter needs to set a proper vaddr on
vb2_dma_sg_dmabuf_ops_vmap callback. This patch adds vmap on map if
buf->vaddr was not set.

Cc: stable@kernel.org
Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>

---
v3 -> v4: drop vunmap function and make use of vb2_dma_sg_vaddr in vmap callback
v2 -> v3: resend as a single patch
v1 -> v2: using vmap and vunmap instead of vm_map_ram and vm_unmap_ram

 drivers/media/common/videobuf2/videobuf2-dma-sg.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Tomasz Figa Nov. 27, 2023, 3:46 a.m. UTC | #1
On Fri, Nov 24, 2023 at 7:32 AM Michael Grzeschik
<m.grzeschik@pengutronix.de> wrote:
>
> For dmabuf import users to be able to use the vaddr from another
> videobuf2-dma-sg source, the exporter needs to set a proper vaddr on
> vb2_dma_sg_dmabuf_ops_vmap callback. This patch adds vmap on map if
> buf->vaddr was not set.
>
> Cc: stable@kernel.org
> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
>
> ---
> v3 -> v4: drop vunmap function and make use of vb2_dma_sg_vaddr in vmap callback
> v2 -> v3: resend as a single patch
> v1 -> v2: using vmap and vunmap instead of vm_map_ram and vm_unmap_ram
>
>  drivers/media/common/videobuf2/videobuf2-dma-sg.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
> index 28f3fdfe23a298..6975a71d740f6d 100644
> --- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c
> +++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
> @@ -487,9 +487,15 @@ vb2_dma_sg_dmabuf_ops_end_cpu_access(struct dma_buf *dbuf,
>  static int vb2_dma_sg_dmabuf_ops_vmap(struct dma_buf *dbuf,
>                                       struct iosys_map *map)
>  {
> -       struct vb2_dma_sg_buf *buf = dbuf->priv;
> +       struct vb2_dma_sg_buf *buf;
> +       void *vaddr;
> +
> +       buf = dbuf->priv;
> +       vaddr = vb2_dma_sg_vaddr(buf->vb, buf);
> +       if (!vaddr)
> +               return -EINVAL;
>
> -       iosys_map_set_vaddr(map, buf->vaddr);
> +       iosys_map_set_vaddr(map, vaddr);
>
>         return 0;
>  }
> --
> 2.39.2
>

Thanks for addressing the comments.

Acked-by: Tomasz Figa <tfiga@chromium.org>

Best regards,
Tomasz
diff mbox series

Patch

diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
index 28f3fdfe23a298..6975a71d740f6d 100644
--- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c
+++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
@@ -487,9 +487,15 @@  vb2_dma_sg_dmabuf_ops_end_cpu_access(struct dma_buf *dbuf,
 static int vb2_dma_sg_dmabuf_ops_vmap(struct dma_buf *dbuf,
 				      struct iosys_map *map)
 {
-	struct vb2_dma_sg_buf *buf = dbuf->priv;
+	struct vb2_dma_sg_buf *buf;
+	void *vaddr;
+
+	buf = dbuf->priv;
+	vaddr = vb2_dma_sg_vaddr(buf->vb, buf);
+	if (!vaddr)
+		return -EINVAL;
 
-	iosys_map_set_vaddr(map, buf->vaddr);
+	iosys_map_set_vaddr(map, vaddr);
 
 	return 0;
 }