[AMD Official Use Only - AMD Internal Distribution Only]

Reviewed-by: Ce Sun <cesun...@amd.com>





Best Regards,
Sun,Ce
________________________________
From: Lazar, Lijo <lijo.la...@amd.com>
Sent: Tuesday, September 2, 2025 2:22 PM
To: amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>
Cc: Zhang, Hawking <hawking.zh...@amd.com>; Deucher, Alexander 
<alexander.deuc...@amd.com>; Sun, Ce(Overlord) <ce....@amd.com>
Subject: [PATCH] drm/amdgpu: Release hive reference properly

xgmi hive reference is taken on function entry, but not released
correctly for all paths. Use __free() to release reference properly.

Signed-off-by: Lijo Lazar <lijo.la...@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 7 +++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h   | 5 +++++
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 7783272a7930..5d128414c283 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -6924,7 +6924,8 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev 
*pdev, pci_channel_sta
 {
         struct drm_device *dev = pci_get_drvdata(pdev);
         struct amdgpu_device *adev = drm_to_adev(dev);
-       struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev);
+       struct amdgpu_hive_info *hive __free(xgmi_put_hive) =
+               amdgpu_get_xgmi_hive(adev);
         struct amdgpu_reset_context reset_context;
         struct list_head device_list;

@@ -6963,10 +6964,8 @@ pci_ers_result_t amdgpu_pci_error_detected(struct 
pci_dev *pdev, pci_channel_sta
                 amdgpu_device_recovery_get_reset_lock(adev, &device_list);
                 amdgpu_device_halt_activities(adev, NULL, &reset_context, 
&device_list,
                                               hive, false);
-               if (hive) {
+               if (hive)
                         mutex_unlock(&hive->hive_lock);
-                       amdgpu_put_xgmi_hive(hive);
-               }
                 return PCI_ERS_RESULT_NEED_RESET;
         case pci_channel_io_perm_failure:
                 /* Permanent error, prepare for device removal */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h
index bba0b26fee8f..5bec657acf96 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h
@@ -126,4 +126,9 @@ uint32_t amdgpu_xgmi_get_max_bandwidth(struct amdgpu_device 
*adev);

 void amgpu_xgmi_set_max_speed_width(struct amdgpu_device *adev,
                                     uint16_t max_speed, uint8_t max_width);
+
+/* Cleanup macro for use with __free(xgmi_put_hive) */
+DEFINE_FREE(xgmi_put_hive, struct amdgpu_hive_info *,
+           if (_T) amdgpu_put_xgmi_hive(_T));
+
 #endif
--
2.49.0

Reply via email to