diff mbox series

[1/3] dma-buf: Allow heap that doesn't provide map_buf/unmap_buf

Message ID 20250410-uio-dma-v1-1-6468ace2c786@bootlin.com
State New
Headers show
Series uio/dma-buf: Give UIO users access to DMA addresses. | expand

Commit Message

Bastien Curutchet April 10, 2025, 2:53 p.m. UTC
dma_buf_export() rejects the creation of dma_buf that don't implement
the map/unmap_buf operations while these operations aren't needed if the
buffer isn't shared by the user.

Allow dma_buf to be created even if these operations aren't implemented.
Add a check of their existence before using them.

Signed-off-by: Bastien Curutchet <bastien.curutchet@bootlin.com>
---
 drivers/dma-buf/dma-buf.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
index 5baa83b855156516a0a766bee0789b122473efb3..398418bd9731ad7a3a1f12eaea6a155fa77a22fe 100644
--- a/drivers/dma-buf/dma-buf.c
+++ b/drivers/dma-buf/dma-buf.c
@@ -631,8 +631,6 @@  struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
 	int ret;
 
 	if (WARN_ON(!exp_info->priv || !exp_info->ops
-		    || !exp_info->ops->map_dma_buf
-		    || !exp_info->ops->unmap_dma_buf
 		    || !exp_info->ops->release))
 		return ERR_PTR(-EINVAL);
 
@@ -796,6 +794,9 @@  static struct sg_table *__map_dma_buf(struct dma_buf_attachment *attach,
 	struct sg_table *sg_table;
 	signed long ret;
 
+	if (!attach->dmabuf->ops->map_dma_buf)
+		return ERR_PTR(-EINVAL);
+
 	sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction);
 	if (IS_ERR_OR_NULL(sg_table))
 		return sg_table;
@@ -1002,7 +1003,8 @@  static void __unmap_dma_buf(struct dma_buf_attachment *attach,
 	/* uses XOR, hence this unmangles */
 	mangle_sg_table(sg_table);
 
-	attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, direction);
+	if (attach->dmabuf->ops->unmap_dma_buf)
+		attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, direction);
 }
 
 /**