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 <andriy.shevche...@linux.intel.com> --- 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 16aaed7238ab..c610a7f44770 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 4c526ff27310..4378846f8b0c 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 92fa5bc30c36..9a2d682451be 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 ffaa56ab6f87..1c667c7d5693 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 7ed0443c821a..1f85de091d39 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 * -- 2.40.0.1.gaa8946217a0b