diff mbox series

[1/2] drm/etnaviv: fix etnaviv_cmdbuf_suballoc_new return value

Message ID 20190705171536.26727-1-l.stach@pengutronix.de (mailing list archive)
State New, archived
Headers show
Series [1/2] drm/etnaviv: fix etnaviv_cmdbuf_suballoc_new return value | expand

Commit Message

Lucas Stach July 5, 2019, 5:15 p.m. UTC
The call site expects to get either a valid suballoc or an error
pointer, so a NULL return will not be treated as an error. Make
sure to always return a proper error pointer in case something goes
wrong.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Philipp Zabel July 24, 2019, 10:51 a.m. UTC | #1
On Fri, 2019-07-05 at 19:15 +0200, Lucas Stach wrote:
> The call site expects to get either a valid suballoc or an error
> pointer, so a NULL return will not be treated as an error. Make
> sure to always return a proper error pointer in case something goes
> wrong.
> 
> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

regards
Philipp

>  drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c b/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c
> index bb4900bc1c4c..7b77992f31c4 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c
> @@ -48,8 +48,10 @@ etnaviv_cmdbuf_suballoc_new(struct etnaviv_gpu * gpu)
>  
>  	suballoc->vaddr = dma_alloc_wc(gpu->dev, SUBALLOC_SIZE,
>  				       &suballoc->paddr, GFP_KERNEL);
> -	if (!suballoc->vaddr)
> +	if (!suballoc->vaddr) {
> +		ret = -ENOMEM;
>  		goto free_suballoc;
> +	}
>  
>  	ret = etnaviv_iommu_get_suballoc_va(gpu, suballoc->paddr,
>  					    &suballoc->vram_node, SUBALLOC_SIZE,
> @@ -64,7 +66,7 @@ etnaviv_cmdbuf_suballoc_new(struct etnaviv_gpu * gpu)
>  free_suballoc:
>  	kfree(suballoc);
>  
> -	return NULL;
> +	return ERR_PTR(ret);
>  }
>  
>  void etnaviv_cmdbuf_suballoc_destroy(struct etnaviv_cmdbuf_suballoc *suballoc)
Guido Günther Aug. 2, 2019, 8:19 a.m. UTC | #2
Hi,
On Fri, Jul 05, 2019 at 07:15:35PM +0200, Lucas Stach wrote:
> The call site expects to get either a valid suballoc or an error
> pointer, so a NULL return will not be treated as an error. Make
> sure to always return a proper error pointer in case something goes
> wrong.
> 
> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
> ---
>  drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c b/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c
> index bb4900bc1c4c..7b77992f31c4 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c
> @@ -48,8 +48,10 @@ etnaviv_cmdbuf_suballoc_new(struct etnaviv_gpu * gpu)
>  
>  	suballoc->vaddr = dma_alloc_wc(gpu->dev, SUBALLOC_SIZE,
>  				       &suballoc->paddr, GFP_KERNEL);
> -	if (!suballoc->vaddr)
> +	if (!suballoc->vaddr) {
> +		ret = -ENOMEM;
>  		goto free_suballoc;
> +	}
>  
>  	ret = etnaviv_iommu_get_suballoc_va(gpu, suballoc->paddr,
>  					    &suballoc->vram_node, SUBALLOC_SIZE,
> @@ -64,7 +66,7 @@ etnaviv_cmdbuf_suballoc_new(struct etnaviv_gpu * gpu)
>  free_suballoc:
>  	kfree(suballoc);
>  
> -	return NULL;
> +	return ERR_PTR(ret);
>  }
>  
>  void etnaviv_cmdbuf_suballoc_destroy(struct etnaviv_cmdbuf_suballoc
>  *suballoc)

Reviewed-by: Guido Günther <agx@sigxcpu.org>

Cheers,
 -- Guido

> -- 
> 2.20.1
> 
> _______________________________________________
> etnaviv mailing list
> etnaviv@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/etnaviv
diff mbox series

Patch

diff --git a/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c b/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c
index bb4900bc1c4c..7b77992f31c4 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c
@@ -48,8 +48,10 @@  etnaviv_cmdbuf_suballoc_new(struct etnaviv_gpu * gpu)
 
 	suballoc->vaddr = dma_alloc_wc(gpu->dev, SUBALLOC_SIZE,
 				       &suballoc->paddr, GFP_KERNEL);
-	if (!suballoc->vaddr)
+	if (!suballoc->vaddr) {
+		ret = -ENOMEM;
 		goto free_suballoc;
+	}
 
 	ret = etnaviv_iommu_get_suballoc_va(gpu, suballoc->paddr,
 					    &suballoc->vram_node, SUBALLOC_SIZE,
@@ -64,7 +66,7 @@  etnaviv_cmdbuf_suballoc_new(struct etnaviv_gpu * gpu)
 free_suballoc:
 	kfree(suballoc);
 
-	return NULL;
+	return ERR_PTR(ret);
 }
 
 void etnaviv_cmdbuf_suballoc_destroy(struct etnaviv_cmdbuf_suballoc *suballoc)