drm/amdgpu: Fix resource leaks
Subsystems (2)
PATCH v2 1/1 drm/amdgpu: Fix resource leaks
There are multiple resource leaks due to ioremap() being used and iounmap never being called in multiple possible error paths.
Change ioremap() to devm_ioremap() to fix all resource leaks at once.
Detected by Smatch:drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:4834 amdgpu_device_init() warn:
'adev->rmmio' from ioremap() not released on lines:
4539,4549,4563,4574,4592,4834.
---
v2:
- Removed unused variable idx.
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -11
@@ -4520,7 +4520,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,for (i =0 ; i <AMD_IP_BLOCK_TYPE_NUM ; i++)atomic_set (&adev->pm.pwr_state[i],POWER_STATE_UNKNOWN ); - adev->rmmio =ioremap (adev->rmmio_base, adev->rmmio_size); + adev->rmmio =devm_ioremap (adev->dev, adev->rmmio_base, adev->rmmio_size);if (!adev->rmmio)return -ENOMEM ;
@@ -4843,8 +4843,6 @@ static void amdgpu_device_unmap_mmio(struct amdgpu_device *adev)/* Unmap all mapped bars - Doorbell, registers and VRAM */ amdgpu_doorbell_fini (adev); -iounmap (adev->rmmio); - adev->rmmio =NULL ;if (adev->mman.aper_base_kaddr)iounmap (adev->mman.aper_base_kaddr); adev->mman.aper_base_kaddr =NULL ;
@@ -4927,7 +4925,7 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)void amdgpu_device_fini_sw (struct amdgpu_device *adev) { -int i, idx; +int i;bool px;amdgpu_device_ip_fini (adev);
@@ -4970,13 +4968,6 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)if ((adev->pdev->class >>8 ) ==PCI_CLASS_DISPLAY_VGA )vga_client_unregister (adev->pdev); -if (drm_dev_enter (adev_to_drm (adev), &idx)) { - -iounmap (adev->rmmio); - adev->rmmio =NULL ; -drm_dev_exit (idx); - } -if (IS_ENABLED (CONFIG_PERF_EVENTS ))amdgpu_pmu_fini (adev);if (adev->discovery.bin)
Signature · 1 line
2.53.0
Quoted 6 lines · Ethan Tidmore
There are multiple resource leaks due to
ioremap()being used and iounmap never being called in multiple possible error paths.Change
ioremap()todevm_ioremap()to fix all resource leaks at once.
Quoted 8 lines
Detected by Smatch:
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:4834amdgpu_device_init()warn:
'adev->rmmio' fromioremap()not released on lines:
4539,4549,4563,4574,4592,4834.Fixes d38ceaf99ed01 ("drm/amdgpu: add core driver (v4)")Signed-off-by Ethan Tidmore <[email protected]>---
Friendly ping.
Thanks,
ET