From 7dd877f8eb7042d932eb2e933b8bfaef5693a0f5 Mon Sep 17 00:00:00 2001 From: Fei Li Date: Wed, 11 Aug 2021 13:43:58 +0800 Subject: [PATCH] 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 --- hypervisor/quirks/acrn_vm_fixup.c | 72 ++++++++++++++++--------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/hypervisor/quirks/acrn_vm_fixup.c b/hypervisor/quirks/acrn_vm_fixup.c index 7f91368df..e3a4d1eba 100644 --- a/hypervisor/quirks/acrn_vm_fixup.c +++ b/hypervisor/quirks/acrn_vm_fixup.c @@ -39,44 +39,48 @@ static void tpm2_fixup(uint16_t vm_id) struct abi_module *mod; 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); - native = get_acpi_tbl(ACPI_SIG_TPM2); + if (config->pt_tpm2) { + if ((tpm2 != NULL) && (native != NULL)) { + /* Native has different start method */ + need_fix = tpm2->start_method != native->start_method; - if (config->pt_tpm2) { - if ((tpm2 != NULL) && (native != NULL)) { - /* Native has different start method */ - need_fix = tpm2->start_method != native->start_method; + /* Native has event log */ + if (native->header.length == + sizeof(struct acpi_table_tpm2)) { + 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 (native->header.length == - sizeof(struct acpi_table_tpm2)) { - 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; + 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(&tpm2->start_method_spec_para, + sizeof(native->start_method_spec_para), + &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"); } } }