From d7f0da1c78f68a56a19d4e5540f7e63a99fca86f Mon Sep 17 00:00:00 2001 From: Benedikt Schmidt Date: Wed, 4 Oct 2023 10:01:46 +0200 Subject: [PATCH] net: fix thread function signatures Fix thread function signatures to avoid stack corruption on thread exit. Signed-off-by: Benedikt Schmidt --- subsys/net/conn_mgr/conn_mgr_monitor.c | 8 ++++++-- subsys/net/ip/net_if.c | 8 ++++++-- subsys/net/ip/net_mgmt.c | 8 ++++++-- subsys/net/ip/net_tc.c | 16 ++++++++++++---- subsys/net/l2/ethernet/gptp/gptp.c | 8 ++++++-- subsys/net/l2/ppp/ppp_l2.c | 10 +++++++--- subsys/net/lib/lwm2m/lwm2m_engine.c | 8 ++++++-- 7 files changed, 49 insertions(+), 17 deletions(-) diff --git a/subsys/net/conn_mgr/conn_mgr_monitor.c b/subsys/net/conn_mgr/conn_mgr_monitor.c index 7396b06dc54..69c21f75b2c 100644 --- a/subsys/net/conn_mgr/conn_mgr_monitor.c +++ b/subsys/net/conn_mgr/conn_mgr_monitor.c @@ -193,8 +193,12 @@ static void conn_mgr_mon_init_cb(struct net_if *iface, void *user_data) conn_mgr_mon_initial_state(iface); } -static void conn_mgr_mon_thread_fn(void) +static void conn_mgr_mon_thread_fn(void *p1, void *p2, void *p3) { + ARG_UNUSED(p1); + ARG_UNUSED(p2); + ARG_UNUSED(p3); + k_mutex_lock(&conn_mgr_mon_lock, K_FOREVER); conn_mgr_conn_init(); @@ -332,7 +336,7 @@ static int conn_mgr_mon_init(void) k_thread_create(&conn_mgr_mon_thread, conn_mgr_mon_stack, CONFIG_NET_CONNECTION_MANAGER_MONITOR_STACK_SIZE, - (k_thread_entry_t)conn_mgr_mon_thread_fn, + conn_mgr_mon_thread_fn, NULL, NULL, NULL, THREAD_PRIORITY, 0, K_NO_WAIT); return 0; diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index 66ee02252dc..b77c3ad3269 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -4618,8 +4618,12 @@ bool net_if_is_suspended(struct net_if *iface) #endif /* CONFIG_NET_POWER_MANAGEMENT */ #if defined(CONFIG_NET_PKT_TIMESTAMP_THREAD) -static void net_tx_ts_thread(void) +static void net_tx_ts_thread(void *p1, void *p2, void *p3) { + ARG_UNUSED(p1); + ARG_UNUSED(p2); + ARG_UNUSED(p3); + struct net_pkt *pkt; NET_DBG("Starting TX timestamp callback thread"); @@ -4880,7 +4884,7 @@ void net_if_init(void) #if defined(CONFIG_NET_PKT_TIMESTAMP_THREAD) k_thread_create(&tx_thread_ts, tx_ts_stack, K_KERNEL_STACK_SIZEOF(tx_ts_stack), - (k_thread_entry_t)net_tx_ts_thread, + net_tx_ts_thread, NULL, NULL, NULL, K_PRIO_COOP(1), 0, K_NO_WAIT); k_thread_name_set(&tx_thread_ts, "tx_tstamp"); #endif /* CONFIG_NET_PKT_TIMESTAMP_THREAD */ diff --git a/subsys/net/ip/net_mgmt.c b/subsys/net/ip/net_mgmt.c index 4ae67a8aeda..d26503b2858 100644 --- a/subsys/net/ip/net_mgmt.c +++ b/subsys/net/ip/net_mgmt.c @@ -189,8 +189,12 @@ static inline void mgmt_run_callbacks(const struct mgmt_event_entry * const mgmt #endif } -static void mgmt_thread(void) +static void mgmt_thread(void *p1, void *p2, void *p3) { + ARG_UNUSED(p1); + ARG_UNUSED(p2); + ARG_UNUSED(p3); + struct mgmt_event_entry mgmt_event; while (1) { @@ -343,7 +347,7 @@ void net_mgmt_event_init(void) k_thread_create(&mgmt_thread_data, mgmt_stack, K_KERNEL_STACK_SIZEOF(mgmt_stack), - (k_thread_entry_t)mgmt_thread, NULL, NULL, NULL, + mgmt_thread, NULL, NULL, NULL, THREAD_PRIORITY, 0, K_NO_WAIT); k_thread_name_set(&mgmt_thread_data, "net_mgmt"); diff --git a/subsys/net/ip/net_tc.c b/subsys/net/ip/net_tc.c index b9e21ba79e4..d789232b582 100644 --- a/subsys/net/ip/net_tc.c +++ b/subsys/net/ip/net_tc.c @@ -237,8 +237,12 @@ static void net_tc_rx_stats_priority_setup(struct net_if *iface, #endif #if NET_TC_RX_COUNT > 0 -static void tc_rx_handler(struct k_fifo *fifo) +static void tc_rx_handler(void *p1, void *p2, void *p3) { + ARG_UNUSED(p2); + ARG_UNUSED(p3); + + struct k_fifo *fifo = p1; struct net_pkt *pkt; while (1) { @@ -253,8 +257,12 @@ static void tc_rx_handler(struct k_fifo *fifo) #endif #if NET_TC_TX_COUNT > 0 -static void tc_tx_handler(struct k_fifo *fifo) +static void tc_tx_handler(void *p1, void *p2, void *p3) { + ARG_UNUSED(p2); + ARG_UNUSED(p3); + + struct k_fifo *fifo = p1; struct net_pkt *pkt; while (1) { @@ -309,7 +317,7 @@ void net_tc_tx_init(void) tid = k_thread_create(&tx_classes[i].handler, tx_stack[i], K_KERNEL_STACK_SIZEOF(tx_stack[i]), - (k_thread_entry_t)tc_tx_handler, + tc_tx_handler, &tx_classes[i].fifo, NULL, NULL, priority, 0, K_FOREVER); if (!tid) { @@ -367,7 +375,7 @@ void net_tc_rx_init(void) tid = k_thread_create(&rx_classes[i].handler, rx_stack[i], K_KERNEL_STACK_SIZEOF(rx_stack[i]), - (k_thread_entry_t)tc_rx_handler, + tc_rx_handler, &rx_classes[i].fifo, NULL, NULL, priority, 0, K_FOREVER); if (!tid) { diff --git a/subsys/net/l2/ethernet/gptp/gptp.c b/subsys/net/l2/ethernet/gptp/gptp.c index 3f822ad548c..2cb128d26c2 100644 --- a/subsys/net/l2/ethernet/gptp/gptp.c +++ b/subsys/net/l2/ethernet/gptp/gptp.c @@ -540,8 +540,12 @@ static void gptp_state_machine(void) gptp_mi_state_machines(); } -static void gptp_thread(void) +static void gptp_thread(void *p1, void *p2, void *p3) { + ARG_UNUSED(p1); + ARG_UNUSED(p2); + ARG_UNUSED(p3); + int port; NET_DBG("Starting PTP thread"); @@ -917,7 +921,7 @@ static void init_ports(void) tid = k_thread_create(&gptp_thread_data, gptp_stack, K_KERNEL_STACK_SIZEOF(gptp_stack), - (k_thread_entry_t)gptp_thread, + gptp_thread, NULL, NULL, NULL, K_PRIO_COOP(5), 0, K_NO_WAIT); k_thread_name_set(&gptp_thread_data, "gptp"); } diff --git a/subsys/net/l2/ppp/ppp_l2.c b/subsys/net/l2/ppp/ppp_l2.c index b949c491406..e2bf29274cc 100644 --- a/subsys/net/l2/ppp/ppp_l2.c +++ b/subsys/net/l2/ppp/ppp_l2.c @@ -30,10 +30,10 @@ static K_FIFO_DEFINE(tx_queue); #define THREAD_PRIORITY K_PRIO_PREEMPT(CONFIG_NET_L2_PPP_THREAD_PRIO) #endif -static void tx_handler(void); +static void tx_handler(void *p1, void *p2, void *p3); static K_THREAD_DEFINE(tx_handler_thread, CONFIG_NET_L2_PPP_TX_STACK_SIZE, - (k_thread_entry_t)tx_handler, NULL, NULL, NULL, + tx_handler, NULL, NULL, NULL, THREAD_PRIORITY, 0, 0); static const struct ppp_protocol_handler *ppp_lcp; @@ -344,8 +344,12 @@ void ppp_queue_pkt(struct net_pkt *pkt) k_fifo_put(&tx_queue, pkt); } -static void tx_handler(void) +static void tx_handler(void *p1, void *p2, void *p3) { + ARG_UNUSED(p1); + ARG_UNUSED(p2); + ARG_UNUSED(p3); + struct net_pkt *pkt; int ret; diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index d4ebf2d62a2..befc8826e0c 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -696,8 +696,12 @@ static void socket_reset_pollfd_events(void) } /* LwM2M main work loop */ -static void socket_loop(void) +static void socket_loop(void *p1, void *p2, void *p3) { + ARG_UNUSED(p1); + ARG_UNUSED(p2); + ARG_UNUSED(p3); + int i, rc; int64_t now, next; int64_t timeout, next_retransmit; @@ -1245,7 +1249,7 @@ static int lwm2m_engine_init(void) /* start sock receive thread */ engine_thread_id = k_thread_create(&engine_thread_data, &engine_thread_stack[0], - K_KERNEL_STACK_SIZEOF(engine_thread_stack), (k_thread_entry_t)socket_loop, + K_KERNEL_STACK_SIZEOF(engine_thread_stack), socket_loop, NULL, NULL, NULL, THREAD_PRIORITY, 0, K_NO_WAIT); k_thread_name_set(&engine_thread_data, "lwm2m-sock-recv"); LOG_DBG("LWM2M engine socket receive thread started");