From b95bc64b06a1ec1786d9c82d3041c63ca1b4e147 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Fri, 1 Sep 2023 11:27:10 -0600 Subject: [PATCH] x86: Prevent from missing the FADT chaining Recent approach with FADT writer shows that there is a room for subtle errors. Prevent this from happening again by introducing acpi_add_fadt() helper. Signed-off-by: Andy Shevchenko Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- arch/x86/cpu/apollolake/acpi.c | 6 +----- arch/x86/cpu/baytrail/acpi.c | 6 +----- arch/x86/cpu/quark/acpi.c | 6 +----- arch/x86/cpu/tangier/acpi.c | 6 +----- include/acpi/acpi_table.h | 7 +++++++ 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/arch/x86/cpu/apollolake/acpi.c b/arch/x86/cpu/apollolake/acpi.c index 16aaed7238..c610a7f447 100644 --- a/arch/x86/cpu/apollolake/acpi.c +++ b/arch/x86/cpu/apollolake/acpi.c @@ -158,11 +158,7 @@ static int apl_write_fadt(struct acpi_ctx *ctx, const struct acpi_writer *entry) header = &fadt->header; header->checksum = table_compute_checksum(fadt, header->length); - acpi_add_table(ctx, fadt); - - acpi_inc(ctx, sizeof(struct acpi_fadt)); - - return 0; + return acpi_add_fadt(ctx, fadt); } ACPI_WRITER(5fadt, "FADT", apl_write_fadt, 0); diff --git a/arch/x86/cpu/baytrail/acpi.c b/arch/x86/cpu/baytrail/acpi.c index 4c526ff273..4378846f8b 100644 --- a/arch/x86/cpu/baytrail/acpi.c +++ b/arch/x86/cpu/baytrail/acpi.c @@ -142,11 +142,7 @@ static int baytrail_write_fadt(struct acpi_ctx *ctx, header->checksum = table_compute_checksum(fadt, header->length); - acpi_add_table(ctx, fadt); - - acpi_inc(ctx, sizeof(struct acpi_fadt)); - - return 0; + return acpi_add_fadt(ctx, fadt); } ACPI_WRITER(5fadt, "FADT", baytrail_write_fadt, 0); diff --git a/arch/x86/cpu/quark/acpi.c b/arch/x86/cpu/quark/acpi.c index 92fa5bc30c..9a2d682451 100644 --- a/arch/x86/cpu/quark/acpi.c +++ b/arch/x86/cpu/quark/acpi.c @@ -137,11 +137,7 @@ static int quark_write_fadt(struct acpi_ctx *ctx, header->checksum = table_compute_checksum(fadt, header->length); - acpi_add_table(ctx, fadt); - - acpi_inc(ctx, sizeof(struct acpi_fadt)); - - return 0; + return acpi_add_fadt(ctx, fadt); } ACPI_WRITER(5fadt, "FADT", quark_write_fadt, 0); diff --git a/arch/x86/cpu/tangier/acpi.c b/arch/x86/cpu/tangier/acpi.c index ffaa56ab6f..1c667c7d56 100644 --- a/arch/x86/cpu/tangier/acpi.c +++ b/arch/x86/cpu/tangier/acpi.c @@ -52,11 +52,7 @@ static int tangier_write_fadt(struct acpi_ctx *ctx, header->checksum = table_compute_checksum(fadt, header->length); - acpi_add_table(ctx, fadt); - - acpi_inc(ctx, sizeof(struct acpi_fadt)); - - return 0; + return acpi_add_fadt(ctx, fadt); } ACPI_WRITER(5fadt, "FADT", tangier_write_fadt, 0); diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h index 7ed0443c82..1f85de091d 100644 --- a/include/acpi/acpi_table.h +++ b/include/acpi/acpi_table.h @@ -883,6 +883,13 @@ void acpi_inc_align(struct acpi_ctx *ctx, uint amount); */ int acpi_add_table(struct acpi_ctx *ctx, void *table); +static inline int acpi_add_fadt(struct acpi_ctx *ctx, struct acpi_fadt *fadt) +{ + acpi_add_table(ctx, fadt); + acpi_inc(ctx, sizeof(struct acpi_fadt)); + return 0; +} + /** * acpi_write_rsdp() - Write out an RSDP indicating where the ACPI tables are *