* [PATCH -next] drm/amdgpu/sdma: add missing release_firmware() in amdgpu_sdma_init_microcode()
@ 2022-09-29 14:20 Yang Yingliang
2022-09-30 14:53 ` Alex Deucher
0 siblings, 1 reply; 2+ messages in thread
From: Yang Yingliang @ 2022-09-29 14:20 UTC (permalink / raw)
To: dri-devel, amd-gfx
Cc: alexander.deucher, Likun.Gao, yangyingliang, Hawking.Zhang
In some error path in amdgpu_sdma_init_microcode(), release_firmware() is
not called, the memory allocated in request_firmware() will be leaked,
calling amdgpu_sdma_destroy_inst_ctx() which calls release_firmware() to
avoid memory leak.
Fixes: 60704abdddd9 ("drm/amdgpu: add function to init SDMA microcode")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
index 3949b7e3907f..43cf8632cc1a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
@@ -222,8 +222,10 @@ int amdgpu_sdma_init_microcode(struct amdgpu_device *adev,
adev->sdma.instance[instance].fw->data;
version_major = le16_to_cpu(header->header_version_major);
- if ((duplicate && instance) || (!duplicate && version_major > 1))
- return -EINVAL;
+ if ((duplicate && instance) || (!duplicate && version_major > 1)) {
+ err = -EINVAL;
+ goto out;
+ }
err = amdgpu_sdma_init_inst_ctx(&adev->sdma.instance[instance]);
if (err)
@@ -272,7 +274,7 @@ int amdgpu_sdma_init_microcode(struct amdgpu_device *adev,
ALIGN(le32_to_cpu(sdma_hdr->ctl_ucode_size_bytes), PAGE_SIZE);
break;
default:
- return -EINVAL;
+ err = -EINVAL;
}
}
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH -next] drm/amdgpu/sdma: add missing release_firmware() in amdgpu_sdma_init_microcode()
2022-09-29 14:20 [PATCH -next] drm/amdgpu/sdma: add missing release_firmware() in amdgpu_sdma_init_microcode() Yang Yingliang
@ 2022-09-30 14:53 ` Alex Deucher
0 siblings, 0 replies; 2+ messages in thread
From: Alex Deucher @ 2022-09-30 14:53 UTC (permalink / raw)
To: Yang Yingliang
Cc: alexander.deucher, Likun.Gao, amd-gfx, dri-devel, Hawking.Zhang
Applied. Thanks.
On Thu, Sep 29, 2022 at 10:04 AM Yang Yingliang
<yangyingliang@huawei.com> wrote:
>
> In some error path in amdgpu_sdma_init_microcode(), release_firmware() is
> not called, the memory allocated in request_firmware() will be leaked,
> calling amdgpu_sdma_destroy_inst_ctx() which calls release_firmware() to
> avoid memory leak.
>
> Fixes: 60704abdddd9 ("drm/amdgpu: add function to init SDMA microcode")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
> index 3949b7e3907f..43cf8632cc1a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
> @@ -222,8 +222,10 @@ int amdgpu_sdma_init_microcode(struct amdgpu_device *adev,
> adev->sdma.instance[instance].fw->data;
> version_major = le16_to_cpu(header->header_version_major);
>
> - if ((duplicate && instance) || (!duplicate && version_major > 1))
> - return -EINVAL;
> + if ((duplicate && instance) || (!duplicate && version_major > 1)) {
> + err = -EINVAL;
> + goto out;
> + }
>
> err = amdgpu_sdma_init_inst_ctx(&adev->sdma.instance[instance]);
> if (err)
> @@ -272,7 +274,7 @@ int amdgpu_sdma_init_microcode(struct amdgpu_device *adev,
> ALIGN(le32_to_cpu(sdma_hdr->ctl_ucode_size_bytes), PAGE_SIZE);
> break;
> default:
> - return -EINVAL;
> + err = -EINVAL;
> }
> }
>
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-09-30 14:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-29 14:20 [PATCH -next] drm/amdgpu/sdma: add missing release_firmware() in amdgpu_sdma_init_microcode() Yang Yingliang
2022-09-30 14:53 ` Alex Deucher
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.