From: Lang Yu <lang.yu@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: Alex Deucher <alexander.deucher@amd.com>,
Huang Rui <ray.huang@amd.com>, Lang Yu <lang.yu@amd.com>,
Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
Subject: [PATCH 2/2] drm/amd/display: refine error handling for dm_dmub_sw_init()
Date: Tue, 14 Dec 2021 16:13:17 +0800 [thread overview]
Message-ID: <20211214081317.337359-2-lang.yu@amd.com> (raw)
In-Reply-To: <20211214081317.337359-1-lang.yu@amd.com>
To avoid potential memory leaks, refine error handling for
dm_dmub_sw_init().
Signed-off-by: Lang Yu <lang.yu@amd.com>
---
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 37 ++++++++++++++-----
1 file changed, 27 insertions(+), 10 deletions(-)
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 8f6766542c73..ef6800dc0215 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -1890,19 +1890,19 @@ static int dm_dmub_sw_init(struct amdgpu_device *adev)
default:
/* ASIC doesn't support DMUB. */
- return 0;
+ return -EINVAL;
}
r = request_firmware_direct(&adev->dm.dmub_fw, fw_name_dmub, adev->dev);
if (r) {
DRM_ERROR("DMUB firmware loading failed: %d\n", r);
- return 0;
+ return r;
}
r = amdgpu_ucode_validate(adev->dm.dmub_fw);
if (r) {
DRM_ERROR("Couldn't validate DMUB firmware: %d\n", r);
- return 0;
+ goto release_firmware;
}
hdr = (const struct dmcub_firmware_header_v1_0 *)adev->dm.dmub_fw->data;
@@ -1926,7 +1926,8 @@ static int dm_dmub_sw_init(struct amdgpu_device *adev)
if (!dmub_srv) {
DRM_ERROR("Failed to allocate DMUB service!\n");
- return -ENOMEM;
+ r = -ENOMEM;
+ goto release_firmware;
}
memset(&create_params, 0, sizeof(create_params));
@@ -1939,7 +1940,8 @@ static int dm_dmub_sw_init(struct amdgpu_device *adev)
status = dmub_srv_create(dmub_srv, &create_params);
if (status != DMUB_STATUS_OK) {
DRM_ERROR("Error creating DMUB service: %d\n", status);
- return -EINVAL;
+ r = -EINVAL;
+ goto free_dmub_srv;
}
/* Calculate the size of all the regions for the DMUB service. */
@@ -1963,7 +1965,8 @@ static int dm_dmub_sw_init(struct amdgpu_device *adev)
if (status != DMUB_STATUS_OK) {
DRM_ERROR("Error calculating DMUB region info: %d\n", status);
- return -EINVAL;
+ r = -EINVAL;
+ goto free_dmub_srv;
}
/*
@@ -1975,8 +1978,7 @@ static int dm_dmub_sw_init(struct amdgpu_device *adev)
&adev->dm.dmub_bo_gpu_addr,
&adev->dm.dmub_bo_cpu_addr);
if (r)
- return r;
-
+ goto free_dmub_srv;
/* Rebase the regions on the framebuffer address. */
memset(&fb_params, 0, sizeof(fb_params));
fb_params.cpu_addr = adev->dm.dmub_bo_cpu_addr;
@@ -1990,16 +1992,31 @@ static int dm_dmub_sw_init(struct amdgpu_device *adev)
if (!fb_info) {
DRM_ERROR(
"Failed to allocate framebuffer info for DMUB service!\n");
- return -ENOMEM;
+ r = -ENOMEM;
+ goto free_dmub_bo;
}
status = dmub_srv_calc_fb_info(dmub_srv, &fb_params, fb_info);
if (status != DMUB_STATUS_OK) {
DRM_ERROR("Error calculating DMUB FB info: %d\n", status);
- return -EINVAL;
+ r = -EINVAL;
+ goto free_dmub_bo;
}
return 0;
+
+free_dmub_bo:
+ amdgpu_bo_free_kernel(&adev->dm.dmub_bo,
+ &adev->dm.dmub_bo_gpu_addr,
+ &adev->dm.dmub_bo_cpu_addr);
+free_dmub_srv:
+ kfree(adev->dm.dmub_srv);
+ adev->dm.dmub_srv = NULL;
+release_firmware:
+ release_firmware(adev->dm.dmub_fw);
+ adev->dm.dmub_fw = NULL;
+
+ return r;
}
static int dm_sw_init(void *handle)
--
2.25.1
prev parent reply other threads:[~2021-12-14 8:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-14 8:13 [PATCH 1/2] drm/amd/display: fix a potential dmub_srv memory leak Lang Yu
2021-12-14 8:13 ` Lang Yu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211214081317.337359-2-lang.yu@amd.com \
--to=lang.yu@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=nicholas.kazlauskas@amd.com \
--cc=ray.huang@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.