Skip to contentSkip to conversation

drm/amdgpu: check return value of xa_store()

PATCH New Salah Triki 1 participant 1 message Jul 31, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/amdgpu: check return value of xa_store()

The xa_store() function can fail due to memory allocation issues or other internal errors. Currently, the return value of xa_store() is not checked, which can lead to a memory leak if it fails to store numa_info.

This patch checks the return value of xa_store(). If an error is detected, the allocated numa_info is freed, and NULL is returned to indicate the failure, preventing a memory leak and ensuring proper error handling.

Fixes 1cc823011a23f ("drm/amdgpu: Store additional numa node information")
Cc Alex Deucher <[email protected]>
Cc Christian König <[email protected]>
Cc David Airlie <[email protected]>
Cc Simona Vetter <[email protected]>

---
Changes in v2:
- Improve description
- Add tags Fixes and Cc

 drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +6 -2
index f5466c592d94..b4a3e4d3e957 100644
@@ -876,7 +876,7 @@ static inline uint64_t amdgpu_acpi_get_numa_size(int nid)
 
 static struct amdgpu_numa_info *amdgpu_acpi_get_numa_info(uint32_t pxm)
 {
-	struct amdgpu_numa_info *numa_info;
+	struct amdgpu_numa_info *numa_info, *old;
 	int nid;
 
 	numa_info = xa_load(&numa_info_xa, pxm);
@@ -898,7 +898,11 @@ static struct amdgpu_numa_info *amdgpu_acpi_get_numa_info(uint32_t pxm)
 		} else {
 			numa_info->size = amdgpu_acpi_get_numa_size(nid);
 		}
-		xa_store(&numa_info_xa, numa_info->pxm, numa_info, GFP_KERNEL);
+		old = xa_store(&numa_info_xa, numa_info->pxm, numa_info, GFP_KERNEL);
+		if (xa_is_err(old)) {
+			kfree(numa_info);
+			return NULL;
+		}
 	}
 
 	return numa_info;
Signature · 1 line
2.43.0