Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/heap/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct z_heap {
size_t allocated_bytes;
size_t max_allocated_bytes;
#endif
struct z_heap_bucket buckets[0];
struct z_heap_bucket buckets[];
};

static inline bool big_heap_chunks(chunksz_t chunks)
Expand Down
10 changes: 5 additions & 5 deletions subsys/bluetooth/audio/has_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct bt_has {

struct bt_has_cp_hdr {
uint8_t opcode;
uint8_t data[0];
uint8_t data[];
} __packed;

struct bt_has_cp_read_presets_req {
Expand All @@ -80,25 +80,25 @@ struct bt_has_cp_read_preset_rsp {
uint8_t is_last;
uint8_t index;
uint8_t properties;
uint8_t name[0];
uint8_t name[];
} __packed;

struct bt_has_cp_preset_changed {
uint8_t change_id;
uint8_t is_last;
uint8_t additional_params[0];
uint8_t additional_params[];
} __packed;

struct bt_has_cp_generic_update {
uint8_t prev_index;
uint8_t index;
uint8_t properties;
uint8_t name[0];
uint8_t name[];
} __packed;

struct bt_has_cp_write_preset_name {
uint8_t index;
uint8_t name[0];
uint8_t name[];
} __packed;

struct bt_has_cp_set_active_preset {
Expand Down
4 changes: 2 additions & 2 deletions subsys/bluetooth/audio/pacs_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ struct bt_pac_codec {
struct bt_pac_ltv {
uint8_t len;
uint8_t type;
uint8_t value[0];
uint8_t value[];
} __packed;

struct bt_pac_ltv_data {
uint8_t len;
struct bt_pac_ltv data[0];
struct bt_pac_ltv data[];
} __packed;

struct bt_pacs_read_rsp {
Expand Down
4 changes: 2 additions & 2 deletions subsys/bluetooth/audio/tbs_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ struct bt_tbs_call_cp_retrieve {

struct bt_tbs_call_cp_originate {
uint8_t opcode;
uint8_t uri[0];
uint8_t uri[];
} __packed;

struct bt_tbs_call_cp_join {
uint8_t opcode;
uint8_t call_indexes[0];
uint8_t call_indexes[];
} __packed;

union bt_tbs_call_cp_t {
Expand Down
18 changes: 6 additions & 12 deletions subsys/bluetooth/controller/ll_sw/openisa/lll/pdu_vendor.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,27 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/sys/util.h>

/* Minimum vendor specific Rx payload buffer allocation */
#define LL_VND_OCTETS_RX_MIN 0

/* No vendor Data PDU struct octet3 */
struct pdu_data_vnd_octet3 {
union {
uint8_t resv[0];
} __packed;
FLEXIBLE_ARRAY_DECLARE(uint8_t, resv);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have concern (not verified) that __packed has been removed by the introduction of FLEXIBLE_ARRAY_DECLARE. Is this truly equivalent?

I see prior PRs have already change some in subsys/bluetooth/controller/ll_sw/pdu.h file.

Can we have a __packed variant of this "workaround" define, like FLEXIBLE_ARRAY_DECLARE_PACKED?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, did __packed for an array of size 0 really do anything?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And even if it wasn't of size 0, since the elements are byte aligned, I don't think __packed would do anything at all.

Copy link
Contributor

@cvinayak cvinayak Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__packed struct or union when nested need __packed individually every time; besides themselves being packed, the parent struct or union which has __packed still need to include them without which the members are machine word aligned/sized (please run a sample on Cortex-M0 nRF51 and you will hit hardfaults based on how linking has been unlucky... i.e. increasing/decreasing buffer counts will misalign these structs).

This file is not the best example, as the union has only one zero length byte array.

But here :

struct pdu_data_vnd_octet3 {
union {
uint8_t resv[OCTET3_LEN]; /* nRF specific octet3 required for NRF_CCM use */
#if !defined(CONFIG_BT_CTLR_DATA_LENGTH_CLEAR)
struct pdu_cte_info cte_info; /* BT 5.1 Core spec. CTEInfo storage */
#endif /* !CONFIG_BT_CTLR_DATA_LENGTH_CLEAR */
} __packed;
} __packed;

The union needs __packed so that it take 1 byte and not 4 bytes in size.

It is best to have a FLEXIBLE_ARRAY_DECLARE_PACKED for code that had __packed for the union inside other __packed union/structs... and also where FLEXIBLE_ARRAY_DECLARE added new union/struct into __packed structs/unions. Hence to also correct the other PR that made changes to as here: 1a56b90

There is also zero length array alignment requirements for nRF51: 701d524

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this example is wrong. With/without packed you will get 4 bytes if CONFIG_BT_CTLR_DATA_LENGTH_CLEAR is not defined. And since this union is the only element of the structure pdu_data_vnd_octet3 that is packed you will get 1 byte size when CONFIG_BT_CTLR_DATA_LENGTH_CLEAR is defined.

If you noticed, I have just changed for this specific use case where the union.

I am wondering if I am missing something here though. Did you get any memory alignment issue ? Printing the struct sizes I get exactly the same thing and the alignment should be correct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok... I did a quick diff of .lst file of a sample for BBC microbit board (adding CONFIG_OUTPUT_DISASSEMBLY=y), with and without 56e2b01, and I see no difference. I am ok for now.

} __packed;

/* No vendor BIS PDU struct octet3 */
struct pdu_bis_vnd_octet3 {
union {
uint8_t resv[0];
} __packed;
FLEXIBLE_ARRAY_DECLARE(uint8_t, resv);
} __packed;

/* No vendor CIS PDU struct octet3 */
struct pdu_cis_vnd_octet3 {
union {
uint8_t resv[0];
} __packed;
FLEXIBLE_ARRAY_DECLARE(uint8_t, resv);
} __packed;

/* No ISOAL helper vendor ISO PDU struct octet3 */
struct pdu_iso_vnd_octet3 {
union {
uint8_t resv[0];
} __packed;
FLEXIBLE_ARRAY_DECLARE(uint8_t, resv);
} __packed;
2 changes: 1 addition & 1 deletion subsys/bluetooth/controller/util/dbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct dbuf_hdr {
/* Size in a bytes of a single element stored in double buffer. */
uint8_t elem_size;
/* Pointer for actual buffer memory. Its size should be 2 times @p elem_size. */
uint8_t data[0];
uint8_t data[];
};

/**
Expand Down
4 changes: 2 additions & 2 deletions subsys/bluetooth/host/classic/avdtp_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ struct bt_avdtp_recovery_capabilities {
struct bt_avdtp_media_codec_capabilities {
uint8_t media_type;
uint8_t media_code_type;
uint8_t media_codec_spec_info[0];
uint8_t media_codec_spec_info[];
} __packed;

struct bt_avdtp_content_protection_capabilities {
uint8_t cp_type_lsb;
uint8_t cp_type_msb;
uint8_t cp_type_spec_value[0];
uint8_t cp_type_spec_value[];
} __packed;

struct bt_avdtp_header_compression_capabilities {
Expand Down
5 changes: 3 additions & 2 deletions subsys/bluetooth/host/classic/l2cap_br_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <zephyr/bluetooth/l2cap.h>
#include <zephyr/sys/iterable_sections.h>
#include <zephyr/sys/util.h>
#include "l2cap_br_interface.h"

#define BT_L2CAP_CID_BR_SIG 0x0001
Expand Down Expand Up @@ -177,12 +178,12 @@ struct bt_l2cap_disconn_rsp {

#define BT_L2CAP_ECHO_REQ 0x08
struct bt_l2cap_echo_req {
uint8_t data[0];
FLEXIBLE_ARRAY_DECLARE(uint8_t, data);
} __packed;

#define BT_L2CAP_ECHO_RSP 0x09
struct bt_l2cap_echo_rsp {
uint8_t data[0];
FLEXIBLE_ARRAY_DECLARE(uint8_t, data);
} __packed;

#define BT_L2CAP_INFO_CONNLESS_MTU 0x0001
Expand Down
11 changes: 6 additions & 5 deletions tests/bluetooth/tester/src/audio/btp/btp_bap.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
#include <zephyr/bluetooth/addr.h>
#include <zephyr/bluetooth/audio/audio.h>
#include <zephyr/bluetooth/iso.h>
#include <zephyr/sys/util.h>

/* BAP commands */
#define BTP_BAP_READ_SUPPORTED_COMMANDS 0x01
struct btp_bap_read_supported_commands_rp {
uint8_t data[0];
FLEXIBLE_ARRAY_DECLARE(uint8_t, data);
} __packed;

#define BTP_BAP_DISCOVER 0x02
Expand All @@ -31,7 +32,7 @@ struct btp_bap_send_cmd {
bt_addr_le_t address;
uint8_t ase_id;
uint8_t data_len;
uint8_t data[0];
uint8_t data[];
} __packed;

struct btp_bap_send_rp {
Expand Down Expand Up @@ -148,7 +149,7 @@ struct btp_bap_add_broadcast_src_cmd {
uint8_t padv_sync;
uint16_t padv_interval;
uint8_t num_subgroups;
uint8_t subgroups[0];
uint8_t subgroups[];
} __packed;

#define BTP_BAP_REMOVE_BROADCAST_SRC 0x15
Expand All @@ -164,7 +165,7 @@ struct btp_bap_modify_broadcast_src_cmd {
uint8_t padv_sync;
uint16_t padv_interval;
uint8_t num_subgroups;
uint8_t subgroups[0];
uint8_t subgroups[];
} __packed;

#define BTP_BAP_SET_BROADCAST_CODE 0x17
Expand Down Expand Up @@ -287,7 +288,7 @@ struct btp_bap_broadcast_receive_state_ev {
uint8_t pa_sync_state;
uint8_t big_encryption;
uint8_t num_subgroups;
uint8_t subgroups[0];
uint8_t subgroups[];
} __packed;

#define BTP_BAP_EV_PA_SYNC_REQ 0x8a
Expand Down
15 changes: 8 additions & 7 deletions tests/bluetooth/tester/src/audio/btp/btp_cap.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
#include <zephyr/bluetooth/addr.h>
#include <zephyr/bluetooth/audio/audio.h>
#include <zephyr/bluetooth/iso.h>
#include <zephyr/sys/util.h>
#include <zephyr/sys/util_macro.h>

/* CAP commands */
#define BTP_CAP_READ_SUPPORTED_COMMANDS 0x01
struct btp_cap_read_supported_commands_rp {
uint8_t data[0];
FLEXIBLE_ARRAY_DECLARE(uint8_t, data);
} __packed;

#define BTP_CAP_DISCOVER 0x02
Expand All @@ -41,7 +42,7 @@ struct btp_cap_unicast_setup_ase_cmd {
uint8_t presentation_delay[3];
uint8_t cc_ltvs_len;
uint8_t metadata_ltvs_len;
uint8_t ltvs[0];
uint8_t ltvs[];
} __packed;

#define BTP_CAP_UNICAST_AUDIO_START 0x04
Expand All @@ -55,13 +56,13 @@ struct btp_cap_unicast_audio_start_cmd {
#define BTP_CAP_UNICAST_AUDIO_UPDATE 0x05
struct btp_cap_unicast_audio_update_cmd {
uint8_t stream_count;
uint8_t update_data[0];
uint8_t update_data[];
} __packed;
struct btp_cap_unicast_audio_update_data {
bt_addr_le_t address;
uint8_t ase_id;
uint8_t metadata_ltvs_len;
uint8_t metadata_ltvs[0];
uint8_t metadata_ltvs[];
} __packed;

#define BTP_CAP_UNICAST_AUDIO_STOP 0x06
Expand All @@ -80,7 +81,7 @@ struct btp_cap_broadcast_source_setup_stream_cmd {
uint16_t cid;
uint8_t cc_ltvs_len;
uint8_t metadata_ltvs_len;
uint8_t ltvs[0];
uint8_t ltvs[];
} __packed;

#define BTP_CAP_BROADCAST_SOURCE_SETUP_SUBGROUP 0x08
Expand All @@ -92,7 +93,7 @@ struct btp_cap_broadcast_source_setup_subgroup_cmd {
uint16_t cid;
uint8_t cc_ltvs_len;
uint8_t metadata_ltvs_len;
uint8_t ltvs[0];
uint8_t ltvs[];
} __packed;

#define BTP_CAP_BROADCAST_SOURCE_SETUP 0x09
Expand Down Expand Up @@ -145,7 +146,7 @@ struct btp_cap_broadcast_source_stop_cmd {
struct btp_cap_broadcast_source_update_cmd {
uint8_t source_id;
uint8_t metadata_ltvs_len;
uint8_t metadata_ltvs[0];
uint8_t metadata_ltvs[];
} __packed;

/* CAP events */
Expand Down
3 changes: 2 additions & 1 deletion tests/bluetooth/tester/src/audio/btp/btp_mcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

#include <zephyr/bluetooth/addr.h>
#include <zephyr/bluetooth/services/ots.h>
#include <zephyr/sys/util.h>

/* MCP commands */
#define BTP_MCP_READ_SUPPORTED_COMMANDS 0x01
struct btp_mcp_read_supported_commands_rp {
uint8_t data[0];
FLEXIBLE_ARRAY_DECLARE(uint8_t, data);
} __packed;

#define BTP_MCP_DISCOVER 0x02
Expand Down
2 changes: 1 addition & 1 deletion tests/bluetooth/tester/src/audio/btp/btp_micp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/* MICP commands */
#define BTP_MICP_READ_SUPPORTED_COMMANDS 0x01
struct btp_micp_read_supported_commands_rp {
uint8_t data[0];
FLEXIBLE_ARRAY_DECLARE(uint8_t, data);
} __packed;

#define BTP_MICP_CTLR_DISCOVER 0x02
Expand Down
2 changes: 1 addition & 1 deletion tests/bluetooth/tester/src/audio/btp/btp_pacs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/* PACS commands */
#define BTP_PACS_READ_SUPPORTED_COMMANDS 0x01
struct btp_pacs_read_supported_commands_rp {
uint8_t data[0];
FLEXIBLE_ARRAY_DECLARE(uint8_t, data);
} __packed;

#define BTP_PACS_CHARACTERISTIC_SINK_PAC 0x01
Expand Down
5 changes: 3 additions & 2 deletions tests/bluetooth/tester/src/btp/btp_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
*/

#include <stdint.h>
#include <zephyr/sys/util.h>

/* Core Service */
#define BTP_CORE_READ_SUPPORTED_COMMANDS 0x01
struct btp_core_read_supported_commands_rp {
uint8_t data[0];
FLEXIBLE_ARRAY_DECLARE(uint8_t, data);
} __packed;

#define BTP_CORE_READ_SUPPORTED_SERVICES 0x02
struct btp_core_read_supported_services_rp {
uint8_t data[0];
FLEXIBLE_ARRAY_DECLARE(uint8_t, data);
} __packed;

#define BTP_CORE_REGISTER_SERVICE 0x03
Expand Down
7 changes: 4 additions & 3 deletions tests/bluetooth/tester/src/btp/btp_gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

#include <zephyr/bluetooth/addr.h>
#include <zephyr/bluetooth/iso.h>
#include <zephyr/sys/util.h>

/* GAP Service */
/* commands */
#define BTP_GAP_READ_SUPPORTED_COMMANDS 0x01
struct btp_gap_read_supported_commands_rp {
uint8_t data[0];
FLEXIBLE_ARRAY_DECLARE(uint8_t, data);
} __packed;

#define BTP_GAP_READ_CONTROLLER_INDEX_LIST 0x02
Expand Down Expand Up @@ -360,7 +361,7 @@ struct btp_gap_big_create_sync_cmd {
uint32_t mse;
uint16_t sync_timeout;
uint8_t encryption;
uint8_t broadcast_code[0];
uint8_t broadcast_code[];
} __packed;

#define BTP_GAP_CREATE_BIG_ENC_DISABLE 0x00
Expand All @@ -377,7 +378,7 @@ struct btp_gap_create_big_cmd {
uint8_t packing;
uint8_t framing;
uint8_t encryption;
uint8_t broadcast_code[0];
uint8_t broadcast_code[];
} __packed;

#define BTP_GAP_BIS_BROADCAST 0x2e
Expand Down
Loading