diff --git a/arch/x86/lib/tables.c b/arch/x86/lib/tables.c index 1779bb3e11ae56e25afd31b5ad7d083cdab05587..ea834a5035f52a202c58859469d8d94ebbb813e7 100644 --- a/arch/x86/lib/tables.c +++ b/arch/x86/lib/tables.c @@ -3,6 +3,8 @@ * Copyright (C) 2015, Bin Meng */ +#define LOG_CATEGORY LOGC_BOARD + #include #include #include @@ -96,13 +98,20 @@ int write_tables(void) return log_msg_ret("bloblist", -ENOBUFS); } rom_table_end = table->write(rom_table_start); - rom_table_end = ALIGN(rom_table_end, ROM_TABLE_ALIGN); + if (!rom_table_end) { + log_err("Can't create configuration table %d\n", i); + return -EINTR; + } if (IS_ENABLED(CONFIG_SEABIOS)) { table_size = rom_table_end - rom_table_start; high_table = (u32)(ulong)high_table_malloc(table_size); if (high_table) { - table->write(high_table); + if (!table->write(high_table)) { + log_err("Can't create configuration table %d\n", + i); + return -EINTR; + } cfg_tables[i].start = high_table; cfg_tables[i].size = table_size; diff --git a/include/smbios.h b/include/smbios.h index fc49fc10b9d7074c8d4c547d2c7cfa79d33689bc..aa6b6f38495b282d67c16f25862274958364876f 100644 --- a/include/smbios.h +++ b/include/smbios.h @@ -229,8 +229,11 @@ static inline void fill_smbios_header(void *table, int type, * This writes SMBIOS table at a given address. * * @addr: start address to write SMBIOS table. If this is not - * 16-byte-aligned then it will be aligned before the table is written - * @return: end address of SMBIOS table (and start address for next entry) + * 16-byte-aligned then it will be aligned before the table is + * written. + * Return: end address of SMBIOS table (and start address for next entry) + * or NULL in case of an error + * */ ulong write_smbios_table(ulong addr); diff --git a/lib/efi_loader/efi_smbios.c b/lib/efi_loader/efi_smbios.c index 719d3e8880ab8ef1fe6f1842f92d5bc5a864147f..2eb4cb1c1af65cf1093889df4961e557c6ec4a40 100644 --- a/lib/efi_loader/efi_smbios.c +++ b/lib/efi_loader/efi_smbios.c @@ -5,6 +5,8 @@ * Copyright (c) 2016 Alexander Graf */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include @@ -43,14 +45,13 @@ efi_status_t efi_smbios_register(void) * Generate SMBIOS tables - we know that efi_allocate_pages() returns * a 4k-aligned address, so it is safe to assume that * write_smbios_table() will write the table at that address. - * - * Note that on sandbox, efi_allocate_pages() unfortunately returns a - * pointer even though it uses a uint64_t type. Convert it. */ assert(!(dmi_addr & 0xf)); dmi = (void *)(uintptr_t)dmi_addr; - write_smbios_table(map_to_sysmem(dmi)); - - /* And expose them to our EFI payload */ - return efi_install_configuration_table(&smbios_guid, dmi); + if (write_smbios_table(map_to_sysmem(dmi))) + /* Install SMBIOS information as configuration table */ + return efi_install_configuration_table(&smbios_guid, dmi); + efi_free_pages(dmi_addr, 1); + log_err("Cannot create SMBIOS table\n"); + return EFI_SUCCESS; } diff --git a/lib/smbios.c b/lib/smbios.c index a892716d15940a96f4d93545ed11ea2a89e92fbc..d7f4999e8b2aee21c745b97a7383a7d16f16078e 100644 --- a/lib/smbios.c +++ b/lib/smbios.c @@ -530,7 +530,8 @@ ulong write_smbios_table(ulong addr) */ printf("WARNING: SMBIOS table_address overflow %llx\n", (unsigned long long)table_addr); - table_addr = 0; + addr = 0; + goto out; } se->struct_table_address = table_addr; @@ -541,6 +542,7 @@ ulong write_smbios_table(ulong addr) isize = sizeof(struct smbios_entry) - SMBIOS_INTERMEDIATE_OFFSET; se->intermediate_checksum = table_compute_checksum(istart, isize); se->checksum = table_compute_checksum(se, sizeof(struct smbios_entry)); +out: unmap_sysmem(se); return addr;