[PATCH] dma-buf: return -EINVAL if dmabuf object is NULL

Christian König christian.koenig at amd.com
Wed Aug 18 12:31:34 UTC 2021


Am 18.08.21 um 14:17 schrieb Sa, Nuno:
>> From: Christian König <christian.koenig at amd.com>
>> Sent: Wednesday, August 18, 2021 2:10 PM
>> To: Sa, Nuno <Nuno.Sa at analog.com>; linaro-mm-sig at lists.linaro.org;
>> dri-devel at lists.freedesktop.org; linux-media at vger.kernel.org
>> Cc: Rob Clark <rob at ti.com>; Sumit Semwal
>> <sumit.semwal at linaro.org>
>> Subject: Re: [PATCH] dma-buf: return -EINVAL if dmabuf object is
>> NULL
>>
>> [External]
>>
>> To be honest I think the if(WARN_ON(!dmabuf)) return -EINVAL
>> handling
>> here is misleading in the first place.
>>
>> Returning -EINVAL on a hard coding error is not good practice and
>> should
>> probably be removed from the DMA-buf subsystem in general.
> Would you say to just return 0 then? I don't think that having the
> dereference is also good..

No, just run into the dereference.

Passing NULL as the core object you are working on is a hard coding 
error and not something we should bubble up as recoverable error.

> I used -EINVAL to be coherent with the rest of the code.

I rather suggest to remove the check elsewhere as well.

Christian.

>
> - Nuno Sá
>
>> Christian.
>>
>> Am 18.08.21 um 13:58 schrieb Nuno Sá:
>>> On top of warning about a NULL object, we also want to return with a
>>> proper error code (as done in 'dma_buf_begin_cpu_access()').
>> Otherwise,
>>> we will get a NULL pointer dereference.
>>>
>>> Fixes: fc13020e086b ("dma-buf: add support for kernel cpu access")
>>> Signed-off-by: Nuno Sá <nuno.sa at analog.com>
>>> ---
>>>    drivers/dma-buf/dma-buf.c | 3 ++-
>>>    1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-
>> buf.c
>>> index 63d32261b63f..8ec7876dd523 100644
>>> --- a/drivers/dma-buf/dma-buf.c
>>> +++ b/drivers/dma-buf/dma-buf.c
>>> @@ -1231,7 +1231,8 @@ int dma_buf_end_cpu_access(struct
>> dma_buf *dmabuf,
>>>    {
>>>    	int ret = 0;
>>>
>>> -	WARN_ON(!dmabuf);
>>> +	if (WARN_ON(!dmabuf))
>>> +		return -EINVAL;
>>>
>>>    	might_lock(&dmabuf->resv->lock.base);
>>>



More information about the dri-devel mailing list