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.

Signed-off-by: Salah Triki <salah.tr...@gmail.com>
Fixes: 1cc823011a23f ("drm/amdgpu: Store additional numa node information")
Cc: Alex Deucher <alexander.deuc...@amd.com>
Cc: Christian König <christian.koe...@amd.com>
Cc: David Airlie <airl...@gmail.com>
Cc: Simona Vetter <sim...@ffwll.ch>
Cc: amd-...@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org
Cc: linux-ker...@vger.kernel.org
Cc: sta...@vger.kernel.org
---
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(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
index f5466c592d94..b4a3e4d3e957 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
@@ -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;
-- 
2.43.0

Reply via email to