]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amd/pm: use kcalloc in phm table copy helpers
authorCandice Li <candice.li@amd.com>
Wed, 20 May 2026 04:14:37 +0000 (12:14 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 3 Jun 2026 17:53:03 +0000 (13:53 -0400)
Use kcalloc() so multiplication overflow is detected
and allocation fails safely for phm table copy helpers.

Signed-off-by: Candice Li <candice.li@amd.com>
Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu_helper.c

index 30d83e18db4074dcae8f357696979a8abfe29110..085b100821b9782493af2f89e9f6b79da549a727 100644 (file)
@@ -49,11 +49,10 @@ int phm_copy_clock_limits_array(
        const uint32_t *pptable_array,
        uint32_t power_saving_clock_count)
 {
-       uint32_t array_size, i;
+       uint32_t i;
        uint32_t *table;
 
-       array_size = sizeof(uint32_t) * power_saving_clock_count;
-       table = kzalloc(array_size, GFP_KERNEL);
+       table = kcalloc(power_saving_clock_count, sizeof(uint32_t), GFP_KERNEL);
        if (NULL == table)
                return -ENOMEM;
 
@@ -71,11 +70,10 @@ int phm_copy_overdrive_settings_limits_array(
        const uint32_t *pptable_array,
        uint32_t od_setting_count)
 {
-       uint32_t array_size, i;
+       uint32_t i;
        uint32_t *table;
 
-       array_size = sizeof(uint32_t) * od_setting_count;
-       table = kzalloc(array_size, GFP_KERNEL);
+       table = kcalloc(od_setting_count, sizeof(uint32_t), GFP_KERNEL);
        if (NULL == table)
                return -ENOMEM;