linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dma-buf: Make mmap callback actually optional
@ 2019-03-29 16:52 Andrew F. Davis
  2019-04-01  7:13 ` Daniel Vetter
  2019-04-01 13:38 ` Christian König
  0 siblings, 2 replies; 5+ messages in thread
From: Andrew F. Davis @ 2019-03-29 16:52 UTC (permalink / raw)
  To: Sumit Semwal; +Cc: dri-devel, linux-kernel, Andrew F . Davis

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

Signed-off-by: Andrew F. Davis <afd@ti.com>
---
 drivers/dma-buf/dma-buf.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
index 7c858020d14b..4d4ae9fe9ac8 100644
--- a/drivers/dma-buf/dma-buf.c
+++ b/drivers/dma-buf/dma-buf.c
@@ -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;
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] dma-buf: Make mmap callback actually optional
  2019-03-29 16:52 [PATCH] dma-buf: Make mmap callback actually optional Andrew F. Davis
@ 2019-04-01  7:13 ` Daniel Vetter
  2019-04-01 13:27   ` Andrew F. Davis
  2019-04-01 13:38 ` Christian König
  1 sibling, 1 reply; 5+ messages in thread
From: Daniel Vetter @ 2019-04-01  7:13 UTC (permalink / raw)
  To: Andrew F. Davis; +Cc: Sumit Semwal, linux-kernel, dri-devel

On Fri, Mar 29, 2019 at 11:52:01AM -0500, Andrew F. Davis wrote:
> The docs state the callback is optional but it is not, make it optional.
> 
> Signed-off-by: Andrew F. Davis <afd@ti.com>

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

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

> ---
>  drivers/dma-buf/dma-buf.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> index 7c858020d14b..4d4ae9fe9ac8 100644
> --- a/drivers/dma-buf/dma-buf.c
> +++ b/drivers/dma-buf/dma-buf.c
> @@ -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;
> -- 
> 2.21.0
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] dma-buf: Make mmap callback actually optional
  2019-04-01  7:13 ` Daniel Vetter
@ 2019-04-01 13:27   ` Andrew F. Davis
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew F. Davis @ 2019-04-01 13:27 UTC (permalink / raw)
  To: Sumit Semwal, linux-kernel, dri-devel

On 4/1/19 2:13 AM, Daniel Vetter wrote:
> On Fri, Mar 29, 2019 at 11:52:01AM -0500, Andrew F. Davis wrote:
>> The docs state the callback is optional but it is not, make it optional.
>>
>> Signed-off-by: Andrew F. Davis <afd@ti.com>
> 
> 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

> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> 
>> ---
>>  drivers/dma-buf/dma-buf.c | 11 +++++++++--
>>  1 file changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
>> index 7c858020d14b..4d4ae9fe9ac8 100644
>> --- a/drivers/dma-buf/dma-buf.c
>> +++ b/drivers/dma-buf/dma-buf.c
>> @@ -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;
>> -- 
>> 2.21.0
>>
>> _______________________________________________
>> dri-devel mailing list
>> dri-devel@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/dri-devel
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] dma-buf: Make mmap callback actually optional
  2019-03-29 16:52 [PATCH] dma-buf: Make mmap callback actually optional Andrew F. Davis
  2019-04-01  7:13 ` Daniel Vetter
@ 2019-04-01 13:38 ` Christian König
  2019-04-03  6:30   ` Sumit Semwal
  1 sibling, 1 reply; 5+ messages in thread
From: Christian König @ 2019-04-01 13:38 UTC (permalink / raw)
  To: Andrew F. Davis, Sumit Semwal; +Cc: linux-kernel, dri-devel

Am 29.03.19 um 17:52 schrieb Andrew F. Davis:
> The docs state the callback is optional but it is not, make it optional.
>
> Signed-off-by: Andrew F. Davis <afd@ti.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/dma-buf/dma-buf.c | 11 +++++++++--
>   1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> index 7c858020d14b..4d4ae9fe9ac8 100644
> --- a/drivers/dma-buf/dma-buf.c
> +++ b/drivers/dma-buf/dma-buf.c
> @@ -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;


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] dma-buf: Make mmap callback actually optional
  2019-04-01 13:38 ` Christian König
@ 2019-04-03  6:30   ` Sumit Semwal
  0 siblings, 0 replies; 5+ messages in thread
From: Sumit Semwal @ 2019-04-03  6:30 UTC (permalink / raw)
  To: Christian Koenig; +Cc: Andrew F. Davis, LKML, DRI mailing list

Hi Andrew,

On Mon, 1 Apr 2019 at 20:38, Christian König
<ckoenig.leichtzumerken@gmail.com> wrote:
>
> Am 29.03.19 um 17:52 schrieb Andrew F. Davis:
> > The docs state the callback is optional but it is not, make it optional.
> >
> > Signed-off-by: Andrew F. Davis <afd@ti.com>
>
> Reviewed-by: Christian König <christian.koenig@amd.com>

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

>
> > ---
> >   drivers/dma-buf/dma-buf.c | 11 +++++++++--
> >   1 file changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> > index 7c858020d14b..4d4ae9fe9ac8 100644
> > --- a/drivers/dma-buf/dma-buf.c
> > +++ b/drivers/dma-buf/dma-buf.c
> > @@ -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;
>

Best,
Sumit.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-04-03  6:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-29 16:52 [PATCH] dma-buf: Make mmap callback actually optional Andrew F. Davis
2019-04-01  7:13 ` Daniel Vetter
2019-04-01 13:27   ` Andrew F. Davis
2019-04-01 13:38 ` Christian König
2019-04-03  6:30   ` Sumit Semwal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).