From: jsg Date: Mon, 9 Sep 2024 09:39:49 +0000 (+0000) Subject: drm/amd/pm: check negtive return for table entries X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=99a23135b329436a52ac233cae51a5119c525659;p=openbsd drm/amd/pm: check negtive return for table entries From Jesse Zhang 7e8d106ca98aac5ba4fc8816e64fea994ab83d54 in linux-6.6.y/6.6.50 f76059fe14395b37ba8d997eb0381b1b9e80a939 in mainline linux --- diff --git a/sys/dev/pci/drm/amd/pm/powerplay/hwmgr/pp_psm.c b/sys/dev/pci/drm/amd/pm/powerplay/hwmgr/pp_psm.c index f4bd8e9357e..18f00038d84 100644 --- a/sys/dev/pci/drm/amd/pm/powerplay/hwmgr/pp_psm.c +++ b/sys/dev/pci/drm/amd/pm/powerplay/hwmgr/pp_psm.c @@ -30,9 +30,8 @@ int psm_init_power_state_table(struct pp_hwmgr *hwmgr) { int result; unsigned int i; - unsigned int table_entries; struct pp_power_state *state; - int size; + int size, table_entries; if (hwmgr->hwmgr_func->get_num_of_pp_table_entries == NULL) return 0; @@ -40,15 +39,19 @@ int psm_init_power_state_table(struct pp_hwmgr *hwmgr) if (hwmgr->hwmgr_func->get_power_state_size == NULL) return 0; - hwmgr->num_ps = table_entries = hwmgr->hwmgr_func->get_num_of_pp_table_entries(hwmgr); + table_entries = hwmgr->hwmgr_func->get_num_of_pp_table_entries(hwmgr); - hwmgr->ps_size = size = hwmgr->hwmgr_func->get_power_state_size(hwmgr) + + size = hwmgr->hwmgr_func->get_power_state_size(hwmgr) + sizeof(struct pp_power_state); - if (table_entries == 0 || size == 0) { + if (table_entries <= 0 || size == 0) { pr_warn("Please check whether power state management is supported on this asic\n"); + hwmgr->num_ps = 0; + hwmgr->ps_size = 0; return 0; } + hwmgr->num_ps = table_entries; + hwmgr->ps_size = size; hwmgr->ps = kcalloc(table_entries, size, GFP_KERNEL); if (hwmgr->ps == NULL)