hv: fixup: a minor refine about tpm2_fixup

Check the return value of get_mod_by_tag before use it.

Tracked-On: #6380
Signed-off-by: Fei Li <fei1.li@intel.com>
This commit is contained in:
Fei Li 2021-08-11 13:43:58 +08:00 committed by wenlingz
parent e5aa63b08e
commit 7dd877f8eb

View File

@ -39,44 +39,48 @@ static void tpm2_fixup(uint16_t vm_id)
struct abi_module *mod; struct abi_module *mod;
mod = get_mod_by_tag(abi, config->acpi_config.acpi_mod_tag); mod = get_mod_by_tag(abi, config->acpi_config.acpi_mod_tag);
if (mod != NULL) {
tpm2 = get_acpi_mod_entry(ACPI_SIG_TPM2, mod->start);
native = get_acpi_tbl(ACPI_SIG_TPM2);
tpm2 = get_acpi_mod_entry(ACPI_SIG_TPM2, mod->start); if (config->pt_tpm2) {
native = get_acpi_tbl(ACPI_SIG_TPM2); if ((tpm2 != NULL) && (native != NULL)) {
/* Native has different start method */
need_fix = tpm2->start_method != native->start_method;
if (config->pt_tpm2) { /* Native has event log */
if ((tpm2 != NULL) && (native != NULL)) { if (native->header.length ==
/* Native has different start method */ sizeof(struct acpi_table_tpm2)) {
need_fix = tpm2->start_method != native->start_method; need_fix |= tpm2->header.length == 0x34U;
need_fix |= strncmp((char *)tpm2->start_method_spec_para,
(char *)native->start_method_spec_para,
sizeof(tpm2->start_method_spec_para)) != 0;
need_fix |= tpm2->laml != native->laml;
need_fix |= tpm2->lasa != native->lasa;
}
/* Native has event log */ if (need_fix) {
if (native->header.length == pr_err("%s tpm2 fix start method and event log field", __FUNCTION__);
sizeof(struct acpi_table_tpm2)) { tpm2->start_method = native->start_method;
need_fix |= tpm2->header.length == 0x34U; tpm2->header.length = native->header.length;
need_fix |= strncmp((char *)tpm2->start_method_spec_para, (char *)native->start_method_spec_para, tpm2->header.revision = native->header.revision;
sizeof(tpm2->start_method_spec_para)) != 0; memcpy_s(&tpm2->start_method_spec_para,
need_fix |= tpm2->laml != native->laml; sizeof(native->start_method_spec_para),
need_fix |= tpm2->lasa != native->lasa; &native->start_method_spec_para,
sizeof(native->start_method_spec_para));
tpm2->laml = native->laml;
tpm2->lasa = config->mmiodevs[0].mmiores[1].base_gpa;
tpm2->header.checksum = 0;
checksum = calculate_checksum8(tpm2, sizeof(struct acpi_table_tpm2));
tpm2->header.checksum = checksum;
config->mmiodevs[0].mmiores[1].base_hpa = native->lasa;
config->mmiodevs[0].mmiores[1].size = tpm2->laml;
}
} else {
pr_err("VM or native can't find TPM2 ACPI table");
} }
if (need_fix) {
pr_err("%s tpm2 fix start method and event log field", __FUNCTION__);
tpm2->start_method = native->start_method;
tpm2->header.length = native->header.length;
tpm2->header.revision = native->header.revision;
memcpy_s(&native->start_method_spec_para, sizeof(native->start_method_spec_para),
&tpm2->start_method_spec_para, sizeof(native->start_method_spec_para));
tpm2->laml = native->laml;
tpm2->lasa = config->mmiodevs[0].mmiores[1].base_gpa;
tpm2->header.checksum = 0;
checksum = calculate_checksum8(tpm2, sizeof(struct acpi_table_tpm2));
tpm2->header.checksum = checksum;
config->mmiodevs[0].mmiores[1].base_hpa = native->lasa;
config->mmiodevs[0].mmiores[1].size = tpm2->laml;
}
} else {
pr_err("VM or native can't find TPM2 ACPI table");
} }
} }
} }