]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-6.1/drm-amd-amdgpu-fix-potential-ioremap-memory-leaks-in.patch
Fixes for 6.1
[thirdparty/kernel/stable-queue.git] / queue-6.1 / drm-amd-amdgpu-fix-potential-ioremap-memory-leaks-in.patch
1 From a4ace0cab6b18623e4b692fdd6a1dd917720a0b0 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 b11690a816e73..e4eb906806a51 100644
34 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
35 +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
36 @@ -3713,8 +3713,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 @@ -3722,18 +3724,18 @@ 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 /* Get rid of things like offb */
64 r = drm_aperture_remove_conflicting_pci_framebuffers(adev->pdev, &amdgpu_kms_driver);
65 if (r)
66 - return r;
67 + goto unmap_memory;
68
69 /* Enable TMZ based on IP_VERSION */
70 amdgpu_gmc_tmz_set(adev);
71 @@ -3743,7 +3745,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
72 if (adev->gmc.xgmi.supported) {
73 r = adev->gfxhub.funcs->get_xgmi_info(adev);
74 if (r)
75 - return r;
76 + goto unmap_memory;
77 }
78
79 /* enable PCIE atomic ops */
80 @@ -3999,6 +4001,8 @@ int amdgpu_device_init(struct amdgpu_device *adev,
81 failed:
82 amdgpu_vf_error_trans_all(adev);
83
84 +unmap_memory:
85 + iounmap(adev->rmmio);
86 return r;
87 }
88
89 --
90 2.43.0
91