Page MenuHomeFreeBSD

bwi: Fix clang 14 warning about possible unaligned access
ClosedPublic

Authored by dim on Feb 7 2022, 9:01 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Nov 3, 12:15 AM
Unknown Object (File)
Thu, Oct 10, 3:41 AM
Unknown Object (File)
Oct 1 2024, 12:43 PM
Unknown Object (File)
Sep 15 2024, 4:02 PM
Unknown Object (File)
Sep 12 2024, 2:49 AM
Unknown Object (File)
Sep 4 2024, 2:48 PM
Unknown Object (File)
Aug 31 2024, 5:51 PM
Unknown Object (File)
Aug 11 2024, 8:40 PM
Subscribers
None

Details

Summary

On architectures with strict alignment requirements (e.g. arm), clang 14
warns about a packed struct which encloses a non-packed union:

In file included from sys/dev/bwi/bwimac.c:79:
sys/dev/bwi/if_bwivar.h:308:7: error: field iv_val within 'struct bwi_fw_iv' is less aligned than 'union (unnamed union at sys/dev/bwi/if_bwivar.h:305:2)' and is usually due to 'struct bwi_fw_iv' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access]
        }                       iv_val;
                                ^

It appears to help if you also add __packed to the inner union (i.e.
iv_val). No change to the layout is intended.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable