Skip to content

Commit d118b18

Browse files
arndbalexdeucher
authored andcommitted
drm/amd/pm: avoid large variable on kernel stack
The activity_monitor_external[] array is too big to fit on the kernel stack, resulting in this warning with clang: drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu13/smu_v13_0_7_ppt.c:1438:12: error: stack frame size (1040) exceeds limit (1024) in 'smu_v13_0_7_get_power_profile_mode' [-Werror,-Wframe-larger-than] Use dynamic allocation instead. It should also be possible to have single element here instead of the array, but this seems easier. v2: fix up argument to sizeof() (Alex) Fixes: 334682a ("drm/amd/pm: enable workload type change on smu_v13_0_7") Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 1a799c4 commit d118b18

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,14 +1440,20 @@ static int smu_v13_0_7_get_power_limit(struct smu_context *smu,
14401440

14411441
static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf)
14421442
{
1443-
DpmActivityMonitorCoeffIntExternal_t activity_monitor_external[PP_SMC_POWER_PROFILE_COUNT];
1443+
DpmActivityMonitorCoeffIntExternal_t *activity_monitor_external;
14441444
uint32_t i, j, size = 0;
14451445
int16_t workload_type = 0;
14461446
int result = 0;
14471447

14481448
if (!buf)
14491449
return -EINVAL;
14501450

1451+
activity_monitor_external = kcalloc(PP_SMC_POWER_PROFILE_COUNT,
1452+
sizeof(*activity_monitor_external),
1453+
GFP_KERNEL);
1454+
if (!activity_monitor_external)
1455+
return -ENOMEM;
1456+
14511457
size += sysfs_emit_at(buf, size, " ");
14521458
for (i = 0; i <= PP_SMC_POWER_PROFILE_WINDOW3D; i++)
14531459
size += sysfs_emit_at(buf, size, "%-14s%s", amdgpu_pp_profile_name[i],
@@ -1460,15 +1466,17 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf
14601466
workload_type = smu_cmn_to_asic_specific_index(smu,
14611467
CMN2ASIC_MAPPING_WORKLOAD,
14621468
i);
1463-
if (workload_type < 0)
1464-
return -EINVAL;
1469+
if (workload_type < 0) {
1470+
result = -EINVAL;
1471+
goto out;
1472+
}
14651473

14661474
result = smu_cmn_update_table(smu,
14671475
SMU_TABLE_ACTIVITY_MONITOR_COEFF, workload_type,
14681476
(void *)(&activity_monitor_external[i]), false);
14691477
if (result) {
14701478
dev_err(smu->adev->dev, "[%s] Failed to get activity monitor!", __func__);
1471-
return result;
1479+
goto out;
14721480
}
14731481
}
14741482

@@ -1496,7 +1504,10 @@ do { \
14961504
PRINT_DPM_MONITOR(Fclk_BoosterFreq);
14971505
#undef PRINT_DPM_MONITOR
14981506

1499-
return size;
1507+
result = size;
1508+
out:
1509+
kfree(activity_monitor_external);
1510+
return result;
15001511
}
15011512

15021513
static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *input, uint32_t size)

0 commit comments

Comments
 (0)