Skip to contentSkip to conversation

dma-buf: Make mmap callback actually optional

PATCH In review Andrew F. Davis 4 participants 5 messages Mar 29, 2019 – Apr 3, 2019 DMA buffer sharing framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dma-buf: Make mmap callback actually optional

The docs state the callback is optional but it is not, make it optional.

---
 drivers/dma-buf/dma-buf.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/dma-buf/dma-buf.c +9 -2
index 7c858020d14b..4d4ae9fe9ac8 100644
@@ -90,6 +90,10 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma)
 
 	dmabuf = file->private_data;
 
+	/* check if buffer supports mmap */
+	if (!dmabuf->ops->mmap)
+		return -EINVAL;
+
 	/* check for overflowing the buffer's size */
 	if (vma->vm_pgoff + vma_pages(vma) >
 	    dmabuf->size >> PAGE_SHIFT)
@@ -404,8 +408,7 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
 			  || !exp_info->ops
 			  || !exp_info->ops->map_dma_buf
 			  || !exp_info->ops->unmap_dma_buf
-			  || !exp_info->ops->release
-			  || !exp_info->ops->mmap)) {
+			  || !exp_info->ops->release)) {
 		return ERR_PTR(-EINVAL);
 	}
 
@@ -906,6 +909,10 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
 	if (WARN_ON(!dmabuf || !vma))
 		return -EINVAL;
 
+	/* check if buffer supports mmap */
+	if (!dmabuf->ops->mmap)
+		return -EINVAL;
+
 	/* check for offset overflow */
 	if (pgoff + vma_pages(vma) < pgoff)
 		return -EOVERFLOW;
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Andrew F. Davis

The docs state the callback is optional but it is not, make it optional.

There's a bunch of dummy mmap implementations we could remove with this, would be nice to follow up.

Quoted 47 lines
---
 drivers/dma-buf/dma-buf.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/dma-buf/dma-buf.c +9 -2
index 7c858020d14b..4d4ae9fe9ac8 100644
@@ -90,6 +90,10 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma)
 
 	dmabuf = file->private_data;
 
+	/* check if buffer supports mmap */
+	if (!dmabuf->ops->mmap)
+		return -EINVAL;
+
 	/* check for overflowing the buffer's size */
 	if (vma->vm_pgoff + vma_pages(vma) >
 	    dmabuf->size >> PAGE_SHIFT)
@@ -404,8 +408,7 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
 			  || !exp_info->ops
 			  || !exp_info->ops->map_dma_buf
 			  || !exp_info->ops->unmap_dma_buf
-			  || !exp_info->ops->release
-			  || !exp_info->ops->mmap)) {
+			  || !exp_info->ops->release)) {
 		return ERR_PTR(-EINVAL);
 	}
 
@@ -906,6 +909,10 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
 	if (WARN_ON(!dmabuf || !vma))
 		return -EINVAL;
 
+	/* check if buffer supports mmap */
+	if (!dmabuf->ops->mmap)
+		return -EINVAL;
+
 	/* check for offset overflow */
 	if (pgoff + vma_pages(vma) < pgoff)
 		return -EOVERFLOW;
Signature · 6 lines
2.21.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw
Quoted 8 lines · Daniel Vetter
Quoted 3 lines · Andrew F. Davis

The docs state the callback is optional but it is not, make it optional.

There's a bunch of dummy mmap implementations we could remove with this, would be nice to follow up.

Was cleaning up some dummy kmap implementations when I found that many had dummy mmap also, so plan was if this goes in I'll be able to zap them both in one go. That or actually add valid kmap where appropriate. Either way will be following up.

Andrew

Quoted 50 lines
Quoted 47 lines
---
 drivers/dma-buf/dma-buf.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/dma-buf/dma-buf.c +9 -2
index 7c858020d14b..4d4ae9fe9ac8 100644
@@ -90,6 +90,10 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma)
 
 	dmabuf = file->private_data;
 
+	/* check if buffer supports mmap */
+	if (!dmabuf->ops->mmap)
+		return -EINVAL;
+
 	/* check for overflowing the buffer's size */
 	if (vma->vm_pgoff + vma_pages(vma) >
 	    dmabuf->size >> PAGE_SHIFT)
@@ -404,8 +408,7 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
 			  || !exp_info->ops
 			  || !exp_info->ops->map_dma_buf
 			  || !exp_info->ops->unmap_dma_buf
-			  || !exp_info->ops->release
-			  || !exp_info->ops->mmap)) {
+			  || !exp_info->ops->release)) {
 		return ERR_PTR(-EINVAL);
 	}
 
@@ -906,6 +909,10 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
 	if (WARN_ON(!dmabuf || !vma))
 		return -EINVAL;
 
+	/* check if buffer supports mmap */
+	if (!dmabuf->ops->mmap)
+		return -EINVAL;
+
 	/* check for offset overflow */
 	if (pgoff + vma_pages(vma) < pgoff)
 		return -EOVERFLOW;
Signature · 6 lines
2.21.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#3 lore raw
In reply to Andrew F. Davis

Am 29.03.19 um 17:52 schrieb Andrew F. Davis:

Quoted 3 lines

The docs state the callback is optional but it is not, make it optional.

Quoted 40 lines
---
  drivers/dma-buf/dma-buf.c | 11 +++++++++--
  1 file changed, 9 insertions(+), 2 deletions(-)
drivers/dma-buf/dma-buf.c +9 -2
index 7c858020d14b..4d4ae9fe9ac8 100644
@@ -90,6 +90,10 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma)
 
  	dmabuf = file->private_data;
 
+	/* check if buffer supports mmap */
+	if (!dmabuf->ops->mmap)
+		return -EINVAL;
+
  	/* check for overflowing the buffer's size */
  	if (vma->vm_pgoff + vma_pages(vma) >
  	    dmabuf->size >> PAGE_SHIFT)
@@ -404,8 +408,7 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
  			  || !exp_info->ops
  			  || !exp_info->ops->map_dma_buf
  			  || !exp_info->ops->unmap_dma_buf
-			  || !exp_info->ops->release
-			  || !exp_info->ops->mmap)) {
+			  || !exp_info->ops->release)) {
  		return ERR_PTR(-EINVAL);
  	}
 
@@ -906,6 +909,10 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
  	if (WARN_ON(!dmabuf || !vma))
  		return -EINVAL;
 
+	/* check if buffer supports mmap */
+	if (!dmabuf->ops->mmap)
+		return -EINVAL;
+
  	/* check for offset overflow */
  	if (pgoff + vma_pages(vma) < pgoff)
  		return -EOVERFLOW;
maintainer
#4 lore raw

Hi Andrew,

Quoted 7 lines · Christian König

Am 29.03.19 um 17:52 schrieb Andrew F. Davis:

Quoted 3 lines

The docs state the callback is optional but it is not, make it optional.

Thanks for the patch; I will queue it up within this week (at a conference atm, but will squeeze out time for doing this).

Quoted 34 lines
Quoted 34 lines
---
  drivers/dma-buf/dma-buf.c | 11 +++++++++--
  1 file changed, 9 insertions(+), 2 deletions(-)
drivers/dma-buf/dma-buf.c +5 -2
index 7c858020d14b..4d4ae9fe9ac8 100644
@@ -90,6 +90,10 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma)
 
      dmabuf = file->private_data;
 
+     /* check if buffer supports mmap */
+     if (!dmabuf->ops->mmap)
+             return -EINVAL;
+
      /* check for overflowing the buffer's size */
      if (vma->vm_pgoff + vma_pages(vma) >
          dmabuf->size >> PAGE_SHIFT)
@@ -404,8 +408,7 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
                        || !exp_info->ops
                        || !exp_info->ops->map_dma_buf
                        || !exp_info->ops->unmap_dma_buf
-                       || !exp_info->ops->release
-                       || !exp_info->ops->mmap)) {
+                       || !exp_info->ops->release)) {
              return ERR_PTR(-EINVAL);
      }
 
@@ -906,6 +909,10 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
      if (WARN_ON(!dmabuf || !vma))
              return -EINVAL;
 
Quoted 8 lines

drivers/dma-buf/dma-buf.c int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, · line 918

Quoted 7 lines
drivers/dma-buf/dma-buf.c +4 -0
+     /* check if buffer supports mmap */
+     if (!dmabuf->ops->mmap)
+             return -EINVAL;
+
      /* check for offset overflow */
      if (pgoff + vma_pages(vma) < pgoff)
              return -EOVERFLOW;

Best,
Sumit.