static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size)
{
struct pp_hwmgr *hwmgr = handle;
+ void *hardcode_pp_table;
int ret = -ENOMEM;
- if (!hwmgr || !hwmgr->pm_en)
- return -EINVAL;
-
- if (size > hwmgr->soft_pp_table_size)
+ if (!hwmgr || !hwmgr->pm_en || !buf || !size || size > U32_MAX)
return -EINVAL;
- if (!hwmgr->hardcode_pp_table) {
- hwmgr->hardcode_pp_table = kmemdup(hwmgr->soft_pp_table,
- hwmgr->soft_pp_table_size,
- GFP_KERNEL);
- if (!hwmgr->hardcode_pp_table)
- return ret;
- }
-
- memcpy(hwmgr->hardcode_pp_table, buf, size);
+ hardcode_pp_table = kmemdup(buf, size, GFP_KERNEL);
+ if (!hardcode_pp_table)
+ return ret;
+ kfree(hwmgr->hardcode_pp_table);
+ hwmgr->hardcode_pp_table = hardcode_pp_table;
hwmgr->soft_pp_table = hwmgr->hardcode_pp_table;
+ hwmgr->soft_pp_table_size = size;
ret = amd_powerplay_reset(handle);
if (ret)