]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/amd/ras: Reduce stack usage in ras_umc_handle_bad_pages()
authorSrinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Fri, 5 Dec 2025 12:07:57 +0000 (17:37 +0530)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 8 Dec 2025 19:25:37 +0000 (14:25 -0500)
ras_umc_handle_bad_pages() function used a large local array:
  struct eeprom_umc_record records[MAX_ECC_NUM_PER_RETIREMENT];

Move this array off the stack by allocating it with kcalloc()
and freeing it before return.

This reduces the stack frame size of ras_umc_handle_bad_pages()
and avoids the frame size warning.

Fixes the below:
drivers/gpu/drm/amd/amdgpu/../ras/rascore/ras_umc.c:498:5: warning: stack frame size (1208) exceeds limit (1024) in 'ras_umc_handle_bad_pages' [-Wframe-larger-than]

v2: Removed the duplicate ras_umc_get_new_records() invocation. (Lijo)

Cc: Tao Zhou <tao.zhou1@amd.com>
Cc: Hawking Zhang <Hawking.Zhang@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Reviewed-by: Tao Zhou <tao.zhou1@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/ras/rascore/ras_umc.c

index 4dae64c424a2475eaaecc6d66e7722594c22d842..a0fdc3fda76164b5ab66398984e8e58d556cdb14 100644 (file)
@@ -497,27 +497,40 @@ exit:
 
 int ras_umc_handle_bad_pages(struct ras_core_context *ras_core, void *data)
 {
-       struct eeprom_umc_record records[MAX_ECC_NUM_PER_RETIREMENT];
+       struct eeprom_umc_record *records;
        int count, ret;
 
-       memset(records, 0, sizeof(records));
-       count = ras_umc_get_new_records(ras_core, records, ARRAY_SIZE(records));
-       if (count <= 0)
-               return -ENODATA;
+       records = kcalloc(MAX_ECC_NUM_PER_RETIREMENT,
+                         sizeof(*records), GFP_KERNEL);
+       if (!records)
+               return -ENOMEM;
+
+       count = ras_umc_get_new_records(ras_core, records,
+                                       MAX_ECC_NUM_PER_RETIREMENT);
+       if (count <= 0) {
+               ret = -ENODATA;
+               goto out;
+       }
 
        ret = ras_umc_add_bad_pages(ras_core, records, count, false);
        if (ret) {
                RAS_DEV_ERR(ras_core->dev, "Failed to add ras bad page!\n");
-               return -EINVAL;
+               ret = -EINVAL;
+               goto out;
        }
 
        ret = ras_umc_save_bad_pages(ras_core);
        if (ret) {
                RAS_DEV_ERR(ras_core->dev, "Failed to save ras bad page\n");
-               return -EINVAL;
+               ret = -EINVAL;
+               goto out;
        }
 
-       return 0;
+       ret = 0;
+
+out:
+       kfree(records);
+       return ret;
 }
 
 int ras_umc_sw_init(struct ras_core_context *ras_core)