[PATCH 1/3] dma-buf: Allow heap that doesn't provide map_buf/unmap_buf
Bastien Curutchet
bastien.curutchet at bootlin.com
Thu Apr 10 14:53:18 UTC 2025
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 at bootlin.com>
---
drivers/dma-buf/dma-buf.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
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);
}
/**
--
2.49.0
More information about the dri-devel
mailing list