Commit 2ec7a46d authored by Aleksander Wasaznik's avatar Aleksander Wasaznik Committed by Carles Cufi
Browse files

Bluetooth: Assert alignof bt_addr types

I got some feedback about confusion as to why the bt_addr types are not
packed. This commit adds a note about it.

This commit also adds a check for the alignof of the structs to verify
the statement 'their members are bytes or byte arrays' to thoroughly
prove that the struct is effectively as-if packed.

Signed-off-by: default avatarAleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
parent 796fc9d5
Loading
Loading
Loading
Loading
+8 −0
Changes for subsys/bluetooth/common/dummy.c: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -9,6 +9,8 @@
 * SPDX-License-Identifier: Apache-2.0
 */

#include <stdalign.h>

#include <zephyr/kernel.h>
#include <zephyr/bluetooth/bluetooth.h>

@@ -18,9 +20,15 @@
 * their members are bytes or byte arrays, the size is. They must not be padded
 * by the compiler, otherwise the on-wire packet will not map the packed
 * structure correctly.
 *
 * The bt_addr structs are not marked __packed because it's considered ugly by
 * some. But here is a proof that the structs have all the properties of, and
 * can be safely used as packed structs.
 */
BUILD_ASSERT(sizeof(bt_addr_t) == BT_ADDR_SIZE);
BUILD_ASSERT(alignof(bt_addr_t) == 1);
BUILD_ASSERT(sizeof(bt_addr_le_t) == BT_ADDR_LE_SIZE);
BUILD_ASSERT(alignof(bt_addr_le_t) == 1);

#if defined(CONFIG_BT_HCI_HOST)
/* The Bluetooth subsystem requires that higher priority events shall be given