]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/6.8.6/drm-amd-amdgpu-fix-potential-ioremap-memory-leaks-in.patch
Linux 6.8.6
[thirdparty/kernel/stable-queue.git] / releases / 6.8.6 / drm-amd-amdgpu-fix-potential-ioremap-memory-leaks-in.patch
1 From e8288ef80c0ad498e190ee529884317787e5b701 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Fri, 23 Feb 2024 17:08:16 +0530
4 Subject: drm/amd/amdgpu: Fix potential ioremap() memory leaks in
5 amdgpu_device_init()
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 From: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
11
12 [ Upstream commit eb4f139888f636614dab3bcce97ff61cefc4b3a7 ]
13
14 This ensures that the memory mapped by ioremap for adev->rmmio, is
15 properly handled in amdgpu_device_init(). If the function exits early
16 due to an error, the memory is unmapped. If the function completes
17 successfully, the memory remains mapped.
18
19 Reported by smatch:
20 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:4337 amdgpu_device_init() warn: 'adev->rmmio' from ioremap() not released on lines: 4035,4045,4051,4058,4068,4337
21
22 Cc: Christian König <christian.koenig@amd.com>
23 Cc: Alex Deucher <alexander.deucher@amd.com>
24 Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
25 Reviewed-by: Christian König <christian.koenig@amd.com>
26 Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
27 Signed-off-by: Sasha Levin <sashal@kernel.org>
28 ---
29 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 16 ++++++++++------
30 1 file changed, 10 insertions(+), 6 deletions(-)
31
32 diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
33 index d0afb9ba3789c..1eff446321bd6 100644
34 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
35 +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
36 @@ -4025,8 +4025,10 @@ int amdgpu_device_init(struct amdgpu_device *adev,
37 * early on during init and before calling to RREG32.
38 */
39 adev->reset_domain = amdgpu_reset_create_reset_domain(SINGLE_DEVICE, "amdgpu-reset-dev");
40 - if (!adev->reset_domain)
41 - return -ENOMEM;
42 + if (!adev->reset_domain) {
43 + r = -ENOMEM;
44 + goto unmap_memory;
45 + }
46
47 /* detect hw virtualization here */
48 amdgpu_detect_virtualization(adev);
49 @@ -4036,20 +4038,20 @@ int amdgpu_device_init(struct amdgpu_device *adev,
50 r = amdgpu_device_get_job_timeout_settings(adev);
51 if (r) {
52 dev_err(adev->dev, "invalid lockup_timeout parameter syntax\n");
53 - return r;
54 + goto unmap_memory;
55 }
56
57 /* early init functions */
58 r = amdgpu_device_ip_early_init(adev);
59 if (r)
60 - return r;
61 + goto unmap_memory;
62
63 amdgpu_device_set_mcbp(adev);
64
65 /* Get rid of things like offb */
66 r = drm_aperture_remove_conflicting_pci_framebuffers(adev->pdev, &amdgpu_kms_driver);
67 if (r)
68 - return r;
69 + goto unmap_memory;
70
71 /* Enable TMZ based on IP_VERSION */
72 amdgpu_gmc_tmz_set(adev);
73 @@ -4059,7 +4061,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
74 if (adev->gmc.xgmi.supported) {
75 r = adev->gfxhub.funcs->get_xgmi_info(adev);
76 if (r)
77 - return r;
78 + goto unmap_memory;
79 }
80
81 /* enable PCIE atomic ops */
82 @@ -4328,6 +4330,8 @@ int amdgpu_device_init(struct amdgpu_device *adev,
83 failed:
84 amdgpu_vf_error_trans_all(adev);
85
86 +unmap_memory:
87 + iounmap(adev->rmmio);
88 return r;
89 }
90
91 --
92 2.43.0
93