ACPI: CPPC: Add NULL pointer check to cppc_get_perf()
PATCH 1/1 ACPI: CPPC: Add NULL pointer check to cppc_get_perf()
From: Rafael J. Wysocki <[email protected]>
Check cpc_desc against NULL in cppc_get_perf(), so it doesn't crash down the road if cpc_desc is NULL.
--- drivers/acpi/cppc_acpi.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/acpi/cppc_acpi.c +5 -0
@@ -1000,6 +1000,11 @@ static int cppc_get_perf(int cpunum, enustruct cpc_desc *cpc_desc =per_cpu (cpc_desc_ptr, cpunum);struct cpc_register_resource *reg = &cpc_desc->cpc_regs[reg_idx]; +if (!cpc_desc) { +pr_debug ("No CPC descriptor for CPU:%d\n" , cpunum); +return -ENODEV ; + } +if (CPC_IN_PCC (reg)) {int pcc_ss_id =per_cpu (cpu_pcc_subspace_idx, cpunum);struct cppc_pcc_data *pcc_ss_data =NULL ;
PATCH v2 1/1 ACPI: CPPC: Add NULL pointer check to cppc_get_perf()
From: Rafael J. Wysocki <[email protected]>
Subject: [PATCH] ACPI: CPPC: Add NULL pointer check to cppc_get_perf()
Check cpc_desc against NULL in cppc_get_perf(), so it doesn't crash down the road if cpc_desc is NULL.
---
-> v2: Check cpc_desc against NULL before using it to initialize reg.
--- drivers/acpi/cppc_acpi.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/acpi/cppc_acpi.c +8 -1
@@ -998,7 +998,14 @@ static int cpc_write(int cpu, struct cpcstatic int cppc_get_perf (int cpunum,enum cppc_regs reg_idx,u64 *perf) {struct cpc_desc *cpc_desc =per_cpu (cpc_desc_ptr, cpunum); -struct cpc_register_resource *reg = &cpc_desc->cpc_regs[reg_idx]; +struct cpc_register_resource *reg; + +if (!cpc_desc) { +pr_debug ("No CPC descriptor for CPU:%d\n" , cpunum); +return -ENODEV ; + } + + reg = &cpc_desc->cpc_regs[reg_idx];if (CPC_IN_PCC (reg)) {int pcc_ss_id =per_cpu (cpu_pcc_subspace_idx, cpunum);
Quoted 11 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Subject: [PATCH] ACPI: CPPC: Add NULL pointer check tocppc_get_perf()Check
cpc_descagainst NULL incppc_get_perf(), so it doesn't crash down the road ifcpc_descis NULL.Fixes 0654cf05d17b ("ACPI: CPPC: Introduce cppc_get_nominal_perf()")Reported-by Kai-Heng Feng <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>Cc 5.15+ <[email protected]> # 5.15+
Sorry for the late test, I bricked my previous ADL rig.
Quoted 31 lines
---
-> v2: Check
cpc_descagainst NULL before using it to initialize reg.--- drivers/acpi/cppc_acpi.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)Index:
linux-pm/drivers/acpi/cppc_acpi.c
===================================================================drivers/acpi/cppc_acpi.c +8
-1@@ -998,7 +998,14 @@ static int cpc_write(int cpu, struct cpcstatic int cppc_get_perf (int cpunum,enum cppc_regs reg_idx,u64 *perf) {struct cpc_desc *cpc_desc =per_cpu (cpc_desc_ptr, cpunum); -struct cpc_register_resource *reg = &cpc_desc->cpc_regs[reg_idx]; +struct cpc_register_resource *reg; + +if (!cpc_desc) { +pr_debug ("No CPC descriptor for CPU:%d\n" , cpunum); +return -ENODEV ; + } + + reg = &cpc_desc->cpc_regs[reg_idx];if (CPC_IN_PCC (reg)) {int pcc_ss_id =per_cpu (cpu_pcc_subspace_idx, cpunum);