Skip to content

Commit 45f3763

Browse files
Lifeng Zhengrafaeljw
authored andcommitted
ACPI: CPPC: Optimize cppc_get_perf()
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 ensure the pointer 'perf' is no null. 3. Add a check to verify if the register is supported to be read before using it. The logic is: (1) If the register is of the integer type, check whether the register is optional and its value is 0. If yes, the register is not supported. (2) If the register is of other types, a null one is not supported. 4. Return the result of cpc_read() instead of 0. Reviewed-by: Pierre Gondois <[email protected]> Signed-off-by: Lifeng Zheng <[email protected]> Reviewed-by: Mario Limonciello <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent e3d7935 commit 45f3763

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

drivers/acpi/cppc_acpi.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,27 +1184,39 @@ static int cppc_get_perf(int cpunum, enum cppc_regs reg_idx, u64 *perf)
11841184
struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpunum);
11851185
struct cpc_register_resource *reg;
11861186

1187+
if (perf == NULL)
1188+
return -EINVAL;
1189+
11871190
if (!cpc_desc) {
11881191
pr_debug("No CPC descriptor for CPU:%d\n", cpunum);
11891192
return -ENODEV;
11901193
}
11911194

11921195
reg = &cpc_desc->cpc_regs[reg_idx];
11931196

1197+
if ((reg->type == ACPI_TYPE_INTEGER && IS_OPTIONAL_CPC_REG(reg_idx) &&
1198+
!reg->cpc_entry.int_value) || (reg->type != ACPI_TYPE_INTEGER &&
1199+
IS_NULL_REG(&reg->cpc_entry.reg))) {
1200+
pr_debug("CPC register is not supported\n");
1201+
return -EOPNOTSUPP;
1202+
}
1203+
11941204
if (CPC_IN_PCC(reg)) {
11951205
int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpunum);
11961206
struct cppc_pcc_data *pcc_ss_data = NULL;
1197-
int ret = 0;
1207+
int ret;
11981208

1199-
if (pcc_ss_id < 0)
1200-
return -EIO;
1209+
if (pcc_ss_id < 0) {
1210+
pr_debug("Invalid pcc_ss_id\n");
1211+
return -ENODEV;
1212+
}
12011213

12021214
pcc_ss_data = pcc_data[pcc_ss_id];
12031215

12041216
down_write(&pcc_ss_data->pcc_lock);
12051217

12061218
if (send_pcc_cmd(pcc_ss_id, CMD_READ) >= 0)
1207-
cpc_read(cpunum, reg, perf);
1219+
ret = cpc_read(cpunum, reg, perf);
12081220
else
12091221
ret = -EIO;
12101222

@@ -1213,9 +1225,7 @@ static int cppc_get_perf(int cpunum, enum cppc_regs reg_idx, u64 *perf)
12131225
return ret;
12141226
}
12151227

1216-
cpc_read(cpunum, reg, perf);
1217-
1218-
return 0;
1228+
return cpc_read(cpunum, reg, perf);
12191229
}
12201230

12211231
/**

0 commit comments

Comments
 (0)