diff mbox series

[25/53] acpi: acpi_build_hest: use acpi_init_table()/acpi_table_composed() instead of build_header()

Message ID 20210625091818.1047980-27-imammedo@redhat.com (mailing list archive)
State New, archived
Headers show
Series acpi: refactor error prone build_header() and packed structures usage in ACPI tables | expand

Commit Message

Igor Mammedov June 25, 2021, 9:17 a.m. UTC
it replaces error-prone pointer arithmetic for build_header() API,
with 2 calls to start and finish table creation,
which hides offsets magic from API user.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: qemu-arm@nongnu.org
CC: drjones@redhat.com
CC: gengdongjiu1@gmail.com
---
 hw/acpi/ghes.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Dongjiu Geng July 2, 2021, 12:21 p.m. UTC | #1
Igor Mammedov <imammedo@redhat.com> 于2021年6月25日周五 下午5:19写道:
>
> it replaces error-prone pointer arithmetic for build_header() API,
> with 2 calls to start and finish table creation,
> which hides offsets magic from API user.
>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: qemu-arm@nongnu.org
> CC: drjones@redhat.com
> CC: gengdongjiu1@gmail.com
> ---
>  hw/acpi/ghes.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/hw/acpi/ghes.c b/hw/acpi/ghes.c
> index a4dac6bf15..ae577c08e4 100644
> --- a/hw/acpi/ghes.c
> +++ b/hw/acpi/ghes.c
> @@ -362,18 +362,16 @@ static void build_ghes_v2(GArray *table_data, int source_id, BIOSLinker *linker)
>  void acpi_build_hest(GArray *table_data, BIOSLinker *linker,
>                       const char *oem_id, const char *oem_table_id)
>  {
> -    uint64_t hest_start = table_data->len;
> +    AcpiTable table = { .sig = "HEST", .rev = 1,
> +                        .oem_id = oem_id, .oem_table_id = oem_table_id };
>
> -    /* Hardware Error Source Table header*/
> -    acpi_data_push(table_data, sizeof(AcpiTableHeader));
> +    acpi_init_table(&table, table_data);
>
>      /* Error Source Count */
>      build_append_int_noprefix(table_data, ACPI_GHES_ERROR_SOURCE_COUNT, 4);
> -
>      build_ghes_v2(table_data, ACPI_HEST_SRC_ID_SEA, linker);
>
> -    build_header(linker, table_data, (void *)(table_data->data + hest_start),
> -                 "HEST", table_data->len - hest_start, 1, oem_id, oem_table_id);
> +    acpi_table_composed(linker, &table);

     Thanks for the change, I think this change is reasonable to use
common API acpi_init_table() to replace build_header()

     Reviewed-by: Dongjiu Geng <gengdongjiu1@gmail.com>

>  }
>
>  void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s,
> --
> 2.27.0
>
diff mbox series

Patch

diff --git a/hw/acpi/ghes.c b/hw/acpi/ghes.c
index a4dac6bf15..ae577c08e4 100644
--- a/hw/acpi/ghes.c
+++ b/hw/acpi/ghes.c
@@ -362,18 +362,16 @@  static void build_ghes_v2(GArray *table_data, int source_id, BIOSLinker *linker)
 void acpi_build_hest(GArray *table_data, BIOSLinker *linker,
                      const char *oem_id, const char *oem_table_id)
 {
-    uint64_t hest_start = table_data->len;
+    AcpiTable table = { .sig = "HEST", .rev = 1,
+                        .oem_id = oem_id, .oem_table_id = oem_table_id };
 
-    /* Hardware Error Source Table header*/
-    acpi_data_push(table_data, sizeof(AcpiTableHeader));
+    acpi_init_table(&table, table_data);
 
     /* Error Source Count */
     build_append_int_noprefix(table_data, ACPI_GHES_ERROR_SOURCE_COUNT, 4);
-
     build_ghes_v2(table_data, ACPI_HEST_SRC_ID_SEA, linker);
 
-    build_header(linker, table_data, (void *)(table_data->data + hest_start),
-                 "HEST", table_data->len - hest_start, 1, oem_id, oem_table_id);
+    acpi_table_composed(linker, &table);
 }
 
 void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s,