Skip to content

Commit a0078a6

Browse files
sjancm-alperen-sener
authored andcommitted
[nrf fromtree] tests: Bluetooth: Tester: Avoid union with packed structure
This may cause some compiler warnings due to flexible array being used in btp_hdr. Simply avoid it and do explicit pointer type cast where needed. Signed-off-by: Szymon Janc <[email protected]> (cherry picked from commit aff2875)
1 parent d298569 commit a0078a6

File tree

1 file changed

+14
-15
lines changed
  • tests/bluetooth/tester/src

1 file changed

+14
-15
lines changed

tests/bluetooth/tester/src/btp.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ static struct k_thread cmd_thread;
3131
#define CMD_QUEUED 2
3232
struct btp_buf {
3333
intptr_t _reserved;
34-
uint8_t rsp[BTP_MTU];
35-
union {
36-
uint8_t data[BTP_MTU];
37-
struct btp_hdr hdr;
38-
};
34+
uint8_t data[BTP_MTU]; /* includes btp header */
35+
uint8_t rsp[BTP_DATA_MAX_SIZE];
3936
};
4037

4138
static struct btp_buf cmd_buf[CMD_QUEUED];
@@ -90,25 +87,27 @@ static void cmd_handler(void *p1, void *p2, void *p3)
9087
while (1) {
9188
const struct btp_handler *btp;
9289
struct btp_buf *cmd;
90+
struct btp_hdr *hdr;
9391
uint8_t status;
9492
uint16_t rsp_len = 0;
9593
uint16_t len;
9694

9795
cmd = k_fifo_get(&cmds_queue, K_FOREVER);
96+
hdr = (struct btp_hdr *)cmd->data;
9897

99-
LOG_DBG("cmd service 0x%02x opcode 0x%02x index 0x%02x", cmd->hdr.service,
100-
cmd->hdr.opcode, cmd->hdr.index);
98+
LOG_DBG("cmd service 0x%02x opcode 0x%02x index 0x%02x",
99+
hdr->service, hdr->opcode, hdr->index);
101100

102-
len = sys_le16_to_cpu(cmd->hdr.len);
101+
len = sys_le16_to_cpu(hdr->len);
103102

104-
btp = find_btp_handler(cmd->hdr.service, cmd->hdr.opcode);
103+
btp = find_btp_handler(hdr->service, hdr->opcode);
105104
if (btp) {
106-
if (btp->index != cmd->hdr.index) {
105+
if (btp->index != hdr->index) {
107106
status = BTP_STATUS_FAILED;
108107
} else if ((btp->expect_len >= 0) && (btp->expect_len != len)) {
109108
status = BTP_STATUS_FAILED;
110109
} else {
111-
status = btp->func(cmd->hdr.data, len,
110+
status = btp->func(hdr->data, len,
112111
cmd->rsp, &rsp_len);
113112
}
114113

@@ -127,11 +126,11 @@ static void cmd_handler(void *p1, void *p2, void *p3)
127126
}
128127

129128
if ((status == BTP_STATUS_SUCCESS) && rsp_len > 0) {
130-
tester_send_with_index(cmd->hdr.service, cmd->hdr.opcode,
131-
cmd->hdr.index, cmd->rsp, rsp_len);
129+
tester_send_with_index(hdr->service, hdr->opcode,
130+
hdr->index, cmd->rsp, rsp_len);
132131
} else {
133-
tester_rsp_with_index(cmd->hdr.service, cmd->hdr.opcode,
134-
cmd->hdr.index, status);
132+
tester_rsp_with_index(hdr->service, hdr->opcode,
133+
hdr->index, status);
135134
}
136135

137136
(void)memset(cmd, 0, sizeof(*cmd));

0 commit comments

Comments
 (0)