[PATCH v5 2/8] ACPI: CPPC: Optimize cppc_get_perf()

From: Lifeng Zheng
Date: Thu Feb 06 2025 - 08:15:04 EST


Optimize cppc_get_perf() with three changes:

1. Change the error kind to "no such device" when pcc_ss_id < 0, as other
register value getting functions.

2. Add a check to verify if the register is a mandatory or cpc supported
one before using it.

3. Return the result of cpc_read() instead of 0.

Signed-off-by: Lifeng Zheng <zhenglifeng1@xxxxxxxxxx>
---
drivers/acpi/cppc_acpi.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index 39f019e265da..db22f8f107db 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -1201,20 +1201,27 @@ static int cppc_get_perf(int cpunum, enum cppc_regs reg_idx, u64 *perf)

reg = &cpc_desc->cpc_regs[reg_idx];

+ if (IS_OPTIONAL_CPC_REG(reg_idx) && !CPC_SUPPORTED(reg)) {
+ pr_debug("CPC register (reg_idx=%d) is not supported\n", reg_idx);
+ return -EOPNOTSUPP;
+ }
+
if (CPC_IN_PCC(reg)) {
int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpunum);
struct cppc_pcc_data *pcc_ss_data = NULL;
- int ret = 0;
+ int ret;

- if (pcc_ss_id < 0)
- return -EIO;
+ if (pcc_ss_id < 0) {
+ pr_debug("Invalid pcc_ss_id\n");
+ return -ENODEV;
+ }

pcc_ss_data = pcc_data[pcc_ss_id];

down_write(&pcc_ss_data->pcc_lock);

if (send_pcc_cmd(pcc_ss_id, CMD_READ) >= 0)
- cpc_read(cpunum, reg, perf);
+ ret = cpc_read(cpunum, reg, perf);
else
ret = -EIO;

@@ -1223,9 +1230,7 @@ static int cppc_get_perf(int cpunum, enum cppc_regs reg_idx, u64 *perf)
return ret;
}

- cpc_read(cpunum, reg, perf);
-
- return 0;
+ return cpc_read(cpunum, reg, perf);
}

/**
--
2.33.0