Skip to content

Commit 4f64ae3

Browse files
committed
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 <[email protected]>
1 parent 55350a9 commit 4f64ae3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

arch/x86/core/acpi.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ void *z_acpi_find_table(uint32_t signature)
149149

150150
uint32_t *end = (uint32_t *)((char *)rsdt + rsdt->sdt.length);
151151

152-
for (uint32_t *tp = &rsdt->table_ptrs[0]; tp < end; tp++) {
152+
/* Extra indirection required to avoid
153+
* -Waddress-of-packed-member
154+
*/
155+
void *table_ptrs = &rsdt->table_ptrs[0];
156+
157+
for (uint32_t *tp = table_ptrs; tp < end; tp++) {
153158
t_phys = (long)*tp;
154159
z_phys_map(&mapped_tbl, t_phys, sizeof(*t), 0);
155160
t = (void *)mapped_tbl;
@@ -186,7 +191,12 @@ void *z_acpi_find_table(uint32_t signature)
186191

187192
uint64_t *end = (uint64_t *)((char *)xsdt + xsdt->sdt.length);
188193

189-
for (uint64_t *tp = &xsdt->table_ptrs[0]; tp < end; tp++) {
194+
/* Extra indirection required to avoid
195+
* -Waddress-of-packed-member
196+
*/
197+
void *table_ptrs = &xsdt->table_ptrs[0];
198+
199+
for (uint64_t *tp = table_ptrs; tp < end; tp++) {
190200
t_phys = (long)*tp;
191201
z_phys_map(&mapped_tbl, t_phys, sizeof(*t), 0);
192202
t = (void *)mapped_tbl;

0 commit comments

Comments
 (0)