RE: [PATCH] drm/amdgpu: Fix memory leak in amdgpu_ras_init()

From: Zhou1, Tao

Date: Thu Jan 29 2026 - 22:20:51 EST


[AMD Official Use Only - AMD Internal Distribution Only]

Thanks for the catch,

Reviewed-by: Tao Zhou <tao.zhou1@xxxxxxx>

> -----Original Message-----
> From: Zilin Guan <zilin@xxxxxxxxxx>
> Sent: Thursday, January 29, 2026 4:35 PM
> To: Deucher, Alexander <Alexander.Deucher@xxxxxxx>
> Cc: Koenig, Christian <Christian.Koenig@xxxxxxx>; airlied@xxxxxxxxx;
> simona@xxxxxxxx; Zhou1, Tao <Tao.Zhou1@xxxxxxx>; Zhang, Hawking
> <Hawking.Zhang@xxxxxxx>; Chai, Thomas <YiPeng.Chai@xxxxxxx>; Xie,
> Patrick <Gangliang.Xie@xxxxxxx>; Yang, Stanley <Stanley.Yang@xxxxxxx>;
> amd-gfx@xxxxxxxxxxxxxxxxxxxxx; dri-devel@xxxxxxxxxxxxxxxxxxxxx; linux-
> kernel@xxxxxxxxxxxxxxx; jianhao.xu@xxxxxxxxxx; Zilin Guan <zilin@xxxxxxxxxx>
> Subject: [PATCH] drm/amdgpu: Fix memory leak in amdgpu_ras_init()
>
> When amdgpu_nbio_ras_sw_init() fails in amdgpu_ras_init(), the function returns
> directly without freeing the allocated con structure, leading to a memory leak.
>
> Fix this by jumping to the release_con label to properly clean up the allocated
> memory before returning the error code.
>
> Compile tested only. Issue found using a prototype static analysis tool and code
> review.
>
> Fixes: fdc94d3a8c88 ("drm/amdgpu: Rework pcie_bif ras sw_init")
> Signed-off-by: Zilin Guan <zilin@xxxxxxxxxx>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> index 2a6cf7963dde..8de9f68f7bea 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> @@ -4343,7 +4343,7 @@ int amdgpu_ras_init(struct amdgpu_device *adev)
> * to handle fatal error */
> r = amdgpu_nbio_ras_sw_init(adev);
> if (r)
> - return r;
> + goto release_con;
>
> if (adev->nbio.ras &&
> adev->nbio.ras->init_ras_controller_interrupt) {
> --
> 2.34.1