[PATCH] drm: tegra: fix memory leak in error handling path

cgel.zte@gmail.com posted 1 patch 4 years, 2 months ago
drivers/gpu/drm/tegra/nvdec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] drm: tegra: fix memory leak in error handling path
Posted by cgel.zte@gmail.com 4 years, 2 months ago
From: Lv Ruyi <lv.ruyi@zte.com.cn>

Before leave the nvdec_load_firmware, we shuold free virt which is alloced
by dma_alloc_coherent, so change "return err" to "goto cleanup".

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
---
 drivers/gpu/drm/tegra/nvdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/tegra/nvdec.c b/drivers/gpu/drm/tegra/nvdec.c
index 79e1e88203cf..a14863346bfa 100644
--- a/drivers/gpu/drm/tegra/nvdec.c
+++ b/drivers/gpu/drm/tegra/nvdec.c
@@ -209,7 +209,7 @@ static int nvdec_load_firmware(struct nvdec *nvdec)
 
 		err = dma_mapping_error(nvdec->dev, iova);
 		if (err < 0)
-			return err;
+			goto cleanup;
 	} else {
 		virt = tegra_drm_alloc(tegra, size, &iova);
 	}
-- 
2.25.1
Re: [PATCH] drm: tegra: fix memory leak in error handling path
Posted by Jon Hunter 4 years, 2 months ago
On 29/03/2022 11:37, cgel.zte@gmail.com wrote:
> From: Lv Ruyi <lv.ruyi@zte.com.cn>
> 
> Before leave the nvdec_load_firmware, we shuold free virt which is alloced

s/shuold/should
s/alloced/allocated

> by dma_alloc_coherent, so change "return err" to "goto cleanup".
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
> ---
>   drivers/gpu/drm/tegra/nvdec.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/tegra/nvdec.c b/drivers/gpu/drm/tegra/nvdec.c
> index 79e1e88203cf..a14863346bfa 100644
> --- a/drivers/gpu/drm/tegra/nvdec.c
> +++ b/drivers/gpu/drm/tegra/nvdec.c
> @@ -209,7 +209,7 @@ static int nvdec_load_firmware(struct nvdec *nvdec)
>   
>   		err = dma_mapping_error(nvdec->dev, iova);
>   		if (err < 0)
> -			return err;
> +			goto cleanup;


Actually, I think that the correct fix here would be the same as what 
was done for VIC ...

https://lore.kernel.org/linux-mm/6b86f6e530b504a5eee864af10e2ae1570d7b645.1639157090.git.robin.murphy@arm.com/

Jon

-- 
nvpublic