From patchwork Wed Jul 8 03:32:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240985 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Tue, 7 Jul 2020 21:32:24 -0600 Subject: [PATCH v2 23/44] x86: Add error checking for csrt table generation In-Reply-To: <20200708033246.2626378-1-sjg@chromium.org> References: <20200708033246.2626378-1-sjg@chromium.org> Message-ID: <20200708033246.2626378-13-sjg@chromium.org> Generation of this table can fail, so update the function to return an error code. Reviewed-by: Bin Meng Reviewed-by: Wolfgang Wallner Signed-off-by: Simon Glass --- (no changes since v1) Changes in v1: - Add new patch to add error checking for csrt table generation arch/x86/lib/acpi_table.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c index 8219376e17..d2bc3386eb 100644 --- a/arch/x86/lib/acpi_table.c +++ b/arch/x86/lib/acpi_table.c @@ -212,13 +212,14 @@ static void acpi_create_mcfg(struct acpi_mcfg *mcfg) __weak u32 acpi_fill_csrt(u32 current) { - return current; + return 0; } -static void acpi_create_csrt(struct acpi_csrt *csrt) +static int acpi_create_csrt(struct acpi_csrt *csrt) { struct acpi_table_header *header = &(csrt->header); u32 current = (u32)csrt + sizeof(struct acpi_csrt); + uint ptr; memset((void *)csrt, 0, sizeof(struct acpi_csrt)); @@ -227,11 +228,16 @@ static void acpi_create_csrt(struct acpi_csrt *csrt) header->length = sizeof(struct acpi_csrt); header->revision = 0; - current = acpi_fill_csrt(current); + ptr = acpi_fill_csrt(current); + if (!ptr) + return -ENOENT; + current = ptr; /* (Re)calculate length and checksum */ header->length = current - (u32)csrt; header->checksum = table_compute_checksum((void *)csrt, header->length); + + return 0; } static void acpi_create_spcr(struct acpi_spcr *spcr) @@ -482,9 +488,10 @@ ulong write_acpi_tables(ulong start_addr) debug("ACPI: * CSRT\n"); csrt = ctx->current; - acpi_create_csrt(csrt); - acpi_inc_align(ctx, csrt->header.length); - acpi_add_table(ctx, csrt); + if (!acpi_create_csrt(csrt)) { + acpi_inc_align(ctx, csrt->header.length); + acpi_add_table(ctx, csrt); + } debug("ACPI: * SPCR\n"); spcr = ctx->current;