acpi: Add missing cbfs_unmap()

cbfs_map() can allocate memory, so cbfs_unmap() should be
called before leaving the function.

BUG=b:278264488
TEST=Built and run with additional debugs on Skyrim device
to confirm that data are correctly unmapped

Change-Id: Ibf7ba6842f42404ad8bb415f8e7fda10403cbe2e
Signed-off-by: Grzegorz Bernacki <bernacki@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/74715
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Jakub Czapiga <jacz@semihalf.com>
Reviewed-by: Tim Van Patten <timvp@google.com>
This commit is contained in:
Grzegorz Bernacki 2023-04-21 13:19:58 +00:00 committed by Matt DeVillier
parent f127becbf1
commit 042ac352ea
1 changed files with 11 additions and 0 deletions

View File

@ -1905,6 +1905,7 @@ unsigned long write_acpi_tables(unsigned long start)
|| dsdt_file->length < sizeof(acpi_header_t) || dsdt_file->length < sizeof(acpi_header_t)
|| memcmp(dsdt_file->signature, "DSDT", 4) != 0) { || memcmp(dsdt_file->signature, "DSDT", 4) != 0) {
printk(BIOS_ERR, "Invalid DSDT file, skipping ACPI tables\n"); printk(BIOS_ERR, "Invalid DSDT file, skipping ACPI tables\n");
cbfs_unmap(dsdt_file);
return current; return current;
} }
@ -1914,6 +1915,7 @@ unsigned long write_acpi_tables(unsigned long start)
|| slic_file->length < sizeof(acpi_header_t) || slic_file->length < sizeof(acpi_header_t)
|| (memcmp(slic_file->signature, "SLIC", 4) != 0 || (memcmp(slic_file->signature, "SLIC", 4) != 0
&& memcmp(slic_file->signature, "MSDM", 4) != 0))) { && memcmp(slic_file->signature, "MSDM", 4) != 0))) {
cbfs_unmap(slic_file);
slic_file = 0; slic_file = 0;
} }
@ -1998,8 +2000,17 @@ unsigned long write_acpi_tables(unsigned long start)
current += slic_file->length; current += slic_file->length;
current = acpi_align_current(current); current = acpi_align_current(current);
acpi_add_table(rsdp, slic); acpi_add_table(rsdp, slic);
cbfs_unmap(slic_file);
} }
/*
* cbfs_unmap() uses mem_pool_free() which works correctly only
* if freeing is done in reverse order than memory allocation.
* This is why unmapping of dsdt_file must be done after
* unmapping slic file.
*/
cbfs_unmap(dsdt_file);
printk(BIOS_DEBUG, "ACPI: * SSDT\n"); printk(BIOS_DEBUG, "ACPI: * SSDT\n");
ssdt = (acpi_header_t *)current; ssdt = (acpi_header_t *)current;
acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR); acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);