Skip to content

Commit

Permalink
drivers: bluetooth: fix thread function signatures
Browse files Browse the repository at this point in the history
Fix thread function signatures to avoid a stack corruption on thread exit.

Signed-off-by: Benedikt Schmidt <[email protected]>
  • Loading branch information
benediktibk authored and carlescufi committed Oct 30, 2023
1 parent c533924 commit 9247f0e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
16 changes: 12 additions & 4 deletions drivers/bluetooth/hci/h5.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,12 @@ static int h5_queue(struct net_buf *buf)
return 0;
}

static void tx_thread(void)
static void tx_thread(void *p1, void *p2, void *p3)
{
ARG_UNUSED(p1);
ARG_UNUSED(p2);
ARG_UNUSED(p3);

LOG_DBG("");

/* FIXME: make periodic sending */
Expand Down Expand Up @@ -653,8 +657,12 @@ static void h5_set_txwin(uint8_t *conf)
conf[2] = h5.tx_win & 0x07;
}

static void rx_thread(void)
static void rx_thread(void *p1, void *p2, void *p3)
{
ARG_UNUSED(p1);
ARG_UNUSED(p2);
ARG_UNUSED(p3);

LOG_DBG("");

while (true) {
Expand Down Expand Up @@ -721,15 +729,15 @@ static void h5_init(void)
k_fifo_init(&h5.tx_queue);
k_thread_create(&tx_thread_data, tx_stack,
K_KERNEL_STACK_SIZEOF(tx_stack),
(k_thread_entry_t)tx_thread, NULL, NULL, NULL,
tx_thread, NULL, NULL, NULL,
K_PRIO_COOP(CONFIG_BT_HCI_TX_PRIO),
0, K_NO_WAIT);
k_thread_name_set(&tx_thread_data, "tx_thread");

k_fifo_init(&h5.rx_queue);
k_thread_create(&rx_thread_data, rx_stack,
K_KERNEL_STACK_SIZEOF(rx_stack),
(k_thread_entry_t)rx_thread, NULL, NULL, NULL,
rx_thread, NULL, NULL, NULL,
K_PRIO_COOP(CONFIG_BT_RX_PRIO),
0, K_NO_WAIT);
k_thread_name_set(&rx_thread_data, "rx_thread");
Expand Down
8 changes: 6 additions & 2 deletions drivers/bluetooth/hci/ipm_stm32wb.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,12 @@ void TM_EvtReceivedCb(TL_EvtPacket_t *hcievt)
k_fifo_put(&ipm_rx_events_fifo, hcievt);
}

static void bt_ipm_rx_thread(void)
static void bt_ipm_rx_thread(void *p1, void *p2, void *p3)
{
ARG_UNUSED(p1);
ARG_UNUSED(p2);
ARG_UNUSED(p3);

while (true) {
bool discardable = false;
k_timeout_t timeout = K_FOREVER;
Expand Down Expand Up @@ -554,7 +558,7 @@ static int bt_ipm_open(void)
/* Start RX thread */
k_thread_create(&ipm_rx_thread_data, ipm_rx_stack,
K_KERNEL_STACK_SIZEOF(ipm_rx_stack),
(k_thread_entry_t)bt_ipm_rx_thread, NULL, NULL, NULL,
bt_ipm_rx_thread, NULL, NULL, NULL,
K_PRIO_COOP(CONFIG_BT_DRIVER_RX_HIGH_PRIO),
0, K_NO_WAIT);

Expand Down
11 changes: 10 additions & 1 deletion drivers/bluetooth/hci/slz_hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,23 @@ static int slz_bt_send(struct net_buf *buf)
return rv;
}

static void slz_thread_func(void *p1, void *p2, void *p3)
{
ARG_UNUSED(p1);
ARG_UNUSED(p2);
ARG_UNUSED(p3);

slz_ll_thread_func();
}

static int slz_bt_open(void)
{
int ret;

/* Start RX thread */
k_thread_create(&slz_ll_thread, slz_ll_stack,
K_KERNEL_STACK_SIZEOF(slz_ll_stack),
(k_thread_entry_t)slz_ll_thread_func, NULL, NULL, NULL,
slz_thread_func, NULL, NULL, NULL,
K_PRIO_COOP(CONFIG_BT_DRIVER_RX_HIGH_PRIO), 0,
K_NO_WAIT);

Expand Down
8 changes: 6 additions & 2 deletions drivers/bluetooth/hci/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,12 @@ static struct net_buf *bt_spi_rx_buf_construct(uint8_t *msg)
return buf;
}

static void bt_spi_rx_thread(void)
static void bt_spi_rx_thread(void *p1, void *p2, void *p3)
{
ARG_UNUSED(p1);
ARG_UNUSED(p2);
ARG_UNUSED(p3);

uint8_t header_master[5] = { SPI_READ, 0x00, 0x00, 0x00, 0x00 };
uint8_t header_slave[5];
struct net_buf *buf;
Expand Down Expand Up @@ -528,7 +532,7 @@ static int bt_spi_open(void)
/* Start RX thread */
k_thread_create(&spi_rx_thread_data, spi_rx_stack,
K_KERNEL_STACK_SIZEOF(spi_rx_stack),
(k_thread_entry_t)bt_spi_rx_thread, NULL, NULL, NULL,
bt_spi_rx_thread, NULL, NULL, NULL,
K_PRIO_COOP(CONFIG_BT_DRIVER_RX_HIGH_PRIO),
0, K_NO_WAIT);

Expand Down

0 comments on commit 9247f0e

Please sign in to comment.