x86: acpi: Fix address-of-packed-mem warning

The warning below appears once -Waddress-of-packed-mem is enabled:

/home/carles/src/zephyr/zephyr/arch/x86/core/acpi.c: In function
'z_acpi_find_table':
/home/carles/src/zephyr/zephyr/arch/x86/core/acpi.c:190:24: warning:
taking address of packed member of 'struct acpi_xsdt' may result in an
unaligned pointer value [-Waddress-of-packed-member]
  190 |    for (uint64_t *tp = &xsdt->table_ptrs[0]; tp < end; tp++) {

To avoid the warning, use an intermediate void * variable.

More info in #16587.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
This commit is contained in:
Carles Cufi 2021-12-07 12:40:36 +01:00 committed by Carles Cufí
commit 4f64ae383d

View file

@ -149,7 +149,12 @@ void *z_acpi_find_table(uint32_t signature)
uint32_t *end = (uint32_t *)((char *)rsdt + rsdt->sdt.length);
for (uint32_t *tp = &rsdt->table_ptrs[0]; tp < end; tp++) {
/* Extra indirection required to avoid
* -Waddress-of-packed-member
*/
void *table_ptrs = &rsdt->table_ptrs[0];
for (uint32_t *tp = table_ptrs; tp < end; tp++) {
t_phys = (long)*tp;
z_phys_map(&mapped_tbl, t_phys, sizeof(*t), 0);
t = (void *)mapped_tbl;
@ -186,7 +191,12 @@ void *z_acpi_find_table(uint32_t signature)
uint64_t *end = (uint64_t *)((char *)xsdt + xsdt->sdt.length);
for (uint64_t *tp = &xsdt->table_ptrs[0]; tp < end; tp++) {
/* Extra indirection required to avoid
* -Waddress-of-packed-member
*/
void *table_ptrs = &xsdt->table_ptrs[0];
for (uint64_t *tp = table_ptrs; tp < end; tp++) {
t_phys = (long)*tp;
z_phys_map(&mapped_tbl, t_phys, sizeof(*t), 0);
t = (void *)mapped_tbl;