diff mbox

[v2] drm: Replace NULL with error value in drm_prime_pages_to_sg

Message ID 20180618060709.14290-1-andr2000@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Oleksandr Andrushchenko June 18, 2018, 6:07 a.m. UTC
From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>

Dan Carpenter has reported that there is the following static checker
warning:
	drivers/gpu/drm/drm_prime.c:317 drm_gem_map_dma_buf()
	warn: 'sgt' can also be NULL

314	sgt = obj->dev->driver->gem_prime_get_sg_table(obj);
315
316	if (!IS_ERR(sgt)) {
317		if (!dma_map_sg_attrs(attach->dev, sgt->sgl, sgt->nents, dir,

Problematic functions are xen_drm_front_gem_get_sg_table and
drm_gem_cma_prime_get_sg_table. Fix those by replacing NULL with error value.

Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/gpu/drm/drm_gem_cma_helper.c    | 2 +-
 drivers/gpu/drm/xen/xen_drm_front_gem.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Oleksandr Andrushchenko June 18, 2018, 6:08 a.m. UTC | #1
On 06/18/2018 09:07 AM, Oleksandr Andrushchenko wrote:
> From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
>
> Dan Carpenter has reported that there is the following static checker
> warning:
> 	drivers/gpu/drm/drm_prime.c:317 drm_gem_map_dma_buf()
> 	warn: 'sgt' can also be NULL
>
> 314	sgt = obj->dev->driver->gem_prime_get_sg_table(obj);
> 315
> 316	if (!IS_ERR(sgt)) {
> 317		if (!dma_map_sg_attrs(attach->dev, sgt->sgl, sgt->nents, dir,
>
> Problematic functions are xen_drm_front_gem_get_sg_table and
> drm_gem_cma_prime_get_sg_table. Fix those by replacing NULL with error value.
>
> Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Dan, could you please review?
> ---
>   drivers/gpu/drm/drm_gem_cma_helper.c    | 2 +-
>   drivers/gpu/drm/xen/xen_drm_front_gem.c | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c
> index 80a5115c3846..ce868ce288fb 100644
> --- a/drivers/gpu/drm/drm_gem_cma_helper.c
> +++ b/drivers/gpu/drm/drm_gem_cma_helper.c
> @@ -436,7 +436,7 @@ struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj)
>   
>   	sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
>   	if (!sgt)
> -		return NULL;
> +		return ERR_PTR(-ENOMEM);
>   
Forgot to patch CMA helpers, thus v2
>   	ret = dma_get_sgtable(obj->dev->dev, sgt, cma_obj->vaddr,
>   			      cma_obj->paddr, obj->size);
> diff --git a/drivers/gpu/drm/xen/xen_drm_front_gem.c b/drivers/gpu/drm/xen/xen_drm_front_gem.c
> index c85bfe7571cb..47ff019d3aef 100644
> --- a/drivers/gpu/drm/xen/xen_drm_front_gem.c
> +++ b/drivers/gpu/drm/xen/xen_drm_front_gem.c
> @@ -179,7 +179,7 @@ struct sg_table *xen_drm_front_gem_get_sg_table(struct drm_gem_object *gem_obj)
>   	struct xen_gem_object *xen_obj = to_xen_gem_obj(gem_obj);
>   
>   	if (!xen_obj->pages)
> -		return NULL;
> +		return ERR_PTR(-ENOMEM);
>   
>   	return drm_prime_pages_to_sg(xen_obj->pages, xen_obj->num_pages);
>   }
Dan Carpenter June 18, 2018, 12:29 p.m. UTC | #2
On Mon, Jun 18, 2018 at 09:07:09AM +0300, Oleksandr Andrushchenko wrote:
>  drivers/gpu/drm/drm_gem_cma_helper.c    | 2 +-
>  drivers/gpu/drm/xen/xen_drm_front_gem.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c
> index 80a5115c3846..ce868ce288fb 100644
> --- a/drivers/gpu/drm/drm_gem_cma_helper.c
> +++ b/drivers/gpu/drm/drm_gem_cma_helper.c
> @@ -436,7 +436,7 @@ struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj)
>  
>  	sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
>  	if (!sgt)
> -		return NULL;
> +		return ERR_PTR(-ENOMEM);
>  
>  	ret = dma_get_sgtable(obj->dev->dev, sgt, cma_obj->vaddr,
>  			      cma_obj->paddr, obj->size);


If dma_get_sgtable() fails then we return NULL.

Fix that and it should be good.

regards,
dan carpenter
Oleksandr Andrushchenko June 18, 2018, 12:32 p.m. UTC | #3
On 06/18/2018 03:29 PM, Dan Carpenter wrote:
> On Mon, Jun 18, 2018 at 09:07:09AM +0300, Oleksandr Andrushchenko wrote:
>>   drivers/gpu/drm/drm_gem_cma_helper.c    | 2 +-
>>   drivers/gpu/drm/xen/xen_drm_front_gem.c | 2 +-
>>   2 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c
>> index 80a5115c3846..ce868ce288fb 100644
>> --- a/drivers/gpu/drm/drm_gem_cma_helper.c
>> +++ b/drivers/gpu/drm/drm_gem_cma_helper.c
>> @@ -436,7 +436,7 @@ struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj)
>>   
>>   	sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
>>   	if (!sgt)
>> -		return NULL;
>> +		return ERR_PTR(-ENOMEM);
>>   
>>   	ret = dma_get_sgtable(obj->dev->dev, sgt, cma_obj->vaddr,
>>   			      cma_obj->paddr, obj->size);
>
> If dma_get_sgtable() fails then we return NULL.
>
> Fix that and it should be good.
You mean I can put your r-b with that fixed?
> regards,
> dan carpenter
>
Oleksandr Andrushchenko July 12, 2018, 11:58 a.m. UTC | #4
On 06/18/2018 03:32 PM, Oleksandr Andrushchenko wrote:
> On 06/18/2018 03:29 PM, Dan Carpenter wrote:
>> On Mon, Jun 18, 2018 at 09:07:09AM +0300, Oleksandr Andrushchenko wrote:
>>> drivers/gpu/drm/drm_gem_cma_helper.c    | 2 +-
>>>   drivers/gpu/drm/xen/xen_drm_front_gem.c | 2 +-
>>>   2 files changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c 
>>> b/drivers/gpu/drm/drm_gem_cma_helper.c
>>> index 80a5115c3846..ce868ce288fb 100644
>>> --- a/drivers/gpu/drm/drm_gem_cma_helper.c
>>> +++ b/drivers/gpu/drm/drm_gem_cma_helper.c
>>> @@ -436,7 +436,7 @@ struct sg_table 
>>> *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj)
>>>         sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
>>>       if (!sgt)
>>> -        return NULL;
>>> +        return ERR_PTR(-ENOMEM);
>>>         ret = dma_get_sgtable(obj->dev->dev, sgt, cma_obj->vaddr,
>>>                     cma_obj->paddr, obj->size);
>>
>> If dma_get_sgtable() fails then we return NULL.
>>
>> Fix that and it should be good.
> You mean I can put your r-b with that fixed?
ping
>> regards,
>> dan carpenter
>>
>
Dan Carpenter July 12, 2018, 12:16 p.m. UTC | #5
On Thu, Jul 12, 2018 at 02:58:00PM +0300, Oleksandr Andrushchenko wrote:
> On 06/18/2018 03:32 PM, Oleksandr Andrushchenko wrote:
> > On 06/18/2018 03:29 PM, Dan Carpenter wrote:
> > > On Mon, Jun 18, 2018 at 09:07:09AM +0300, Oleksandr Andrushchenko wrote:
> > > > drivers/gpu/drm/drm_gem_cma_helper.c    | 2 +-
> > > >   drivers/gpu/drm/xen/xen_drm_front_gem.c | 2 +-
> > > >   2 files changed, 2 insertions(+), 2 deletions(-)
> > > > 
> > > > diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c
> > > > b/drivers/gpu/drm/drm_gem_cma_helper.c
> > > > index 80a5115c3846..ce868ce288fb 100644
> > > > --- a/drivers/gpu/drm/drm_gem_cma_helper.c
> > > > +++ b/drivers/gpu/drm/drm_gem_cma_helper.c
> > > > @@ -436,7 +436,7 @@ struct sg_table
> > > > *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj)
> > > >         sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
> > > >       if (!sgt)
> > > > -        return NULL;
> > > > +        return ERR_PTR(-ENOMEM);
> > > >         ret = dma_get_sgtable(obj->dev->dev, sgt, cma_obj->vaddr,
> > > >                     cma_obj->paddr, obj->size);
> > > 
> > > If dma_get_sgtable() fails then we return NULL.
> > > 
> > > Fix that and it should be good.
> > You mean I can put your r-b with that fixed?
> ping

Yeah.  Send the v2 patch and I'll review it.

regards,
dan carpenter
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c
index 80a5115c3846..ce868ce288fb 100644
--- a/drivers/gpu/drm/drm_gem_cma_helper.c
+++ b/drivers/gpu/drm/drm_gem_cma_helper.c
@@ -436,7 +436,7 @@  struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj)
 
 	sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
 	if (!sgt)
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 
 	ret = dma_get_sgtable(obj->dev->dev, sgt, cma_obj->vaddr,
 			      cma_obj->paddr, obj->size);
diff --git a/drivers/gpu/drm/xen/xen_drm_front_gem.c b/drivers/gpu/drm/xen/xen_drm_front_gem.c
index c85bfe7571cb..47ff019d3aef 100644
--- a/drivers/gpu/drm/xen/xen_drm_front_gem.c
+++ b/drivers/gpu/drm/xen/xen_drm_front_gem.c
@@ -179,7 +179,7 @@  struct sg_table *xen_drm_front_gem_get_sg_table(struct drm_gem_object *gem_obj)
 	struct xen_gem_object *xen_obj = to_xen_gem_obj(gem_obj);
 
 	if (!xen_obj->pages)
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 
 	return drm_prime_pages_to_sg(xen_obj->pages, xen_obj->num_pages);
 }