Skip to content

Commit

Permalink
drivers: ethernet: fix thread function signatures
Browse files Browse the repository at this point in the history
Fix thread function signatures to avoid 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 9247f0e commit fbef0ed
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
8 changes: 6 additions & 2 deletions drivers/ethernet/eth_adin2111.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,12 @@ static inline void adin2111_port_on_phyint(const struct device *dev)
}
}

static void adin2111_offload_thread(const struct device *dev)
static void adin2111_offload_thread(void *p1, void *p2, void *p3)
{
ARG_UNUSED(p2);
ARG_UNUSED(p3);

const struct device *dev = p1;
struct adin2111_data *ctx = dev->data;
const struct adin2111_config *adin_cfg = dev->config;
bool is_adin2111 = (adin_cfg->id == ADIN2111_MAC);
Expand Down Expand Up @@ -669,7 +673,7 @@ static void adin2111_port_iface_init(struct net_if *iface)
/* all ifaces are done, start INT processing */
k_thread_create(&ctx->rx_thread, ctx->rx_thread_stack,
CONFIG_ETH_ADIN2111_IRQ_THREAD_STACK_SIZE,
(k_thread_entry_t)adin2111_offload_thread,
adin2111_offload_thread,
(void *)adin, NULL, NULL,
CONFIG_ETH_ADIN2111_IRQ_THREAD_PRIO,
K_ESSENTIAL, K_NO_WAIT);
Expand Down
8 changes: 6 additions & 2 deletions drivers/ethernet/eth_enc28j60.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,12 @@ static int eth_enc28j60_rx(const struct device *dev, uint16_t *vlan_tag)
return 0;
}

static void eth_enc28j60_rx_thread(const struct device *dev)
static void eth_enc28j60_rx_thread(void *p1, void *p2, void *p3)
{
ARG_UNUSED(p2);
ARG_UNUSED(p3);

const struct device *dev = p1;
struct eth_enc28j60_runtime *context = dev->data;
uint16_t vlan_tag = NET_VLAN_TAG_UNSPEC;
uint8_t int_stat;
Expand Down Expand Up @@ -850,7 +854,7 @@ static int eth_enc28j60_init(const struct device *dev)
/* Start interruption-poll thread */
k_thread_create(&context->thread, context->thread_stack,
CONFIG_ETH_ENC28J60_RX_THREAD_STACK_SIZE,
(k_thread_entry_t)eth_enc28j60_rx_thread,
eth_enc28j60_rx_thread,
(void *)dev, NULL, NULL,
K_PRIO_COOP(CONFIG_ETH_ENC28J60_RX_THREAD_PRIO),
0, K_NO_WAIT);
Expand Down
8 changes: 6 additions & 2 deletions drivers/ethernet/eth_enc424j600.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,12 @@ static int enc424j600_rx(const struct device *dev)
return 0;
}

static void enc424j600_rx_thread(struct enc424j600_runtime *context)
static void enc424j600_rx_thread(void *p1, void *p2, void *p3)
{
ARG_UNUSED(p2);
ARG_UNUSED(p3);

struct enc424j600_runtime *context = p1;
uint16_t eir;
uint16_t estat;
uint8_t counter;
Expand Down Expand Up @@ -767,7 +771,7 @@ static int enc424j600_init(const struct device *dev)
/* Start interruption-poll thread */
k_thread_create(&context->thread, context->thread_stack,
CONFIG_ETH_ENC424J600_RX_THREAD_STACK_SIZE,
(k_thread_entry_t)enc424j600_rx_thread,
enc424j600_rx_thread,
context, NULL, NULL,
K_PRIO_COOP(CONFIG_ETH_ENC424J600_RX_THREAD_PRIO),
0, K_NO_WAIT);
Expand Down
8 changes: 6 additions & 2 deletions drivers/ethernet/eth_native_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,12 @@ static int read_data(struct eth_context *ctx, int fd)
return 0;
}

static void eth_rx(struct eth_context *ctx)
static void eth_rx(void *p1, void *p2, void *p3)
{
ARG_UNUSED(p2);
ARG_UNUSED(p3);

struct eth_context *ctx = p1;
LOG_DBG("Starting ZETH RX thread");

while (1) {
Expand All @@ -391,7 +395,7 @@ static void create_rx_handler(struct eth_context *ctx)
k_thread_create(ctx->rx_thread,
ctx->rx_stack,
ctx->rx_stack_size,
(k_thread_entry_t)eth_rx,
eth_rx,
ctx, NULL, NULL, K_PRIO_COOP(14),
0, K_NO_WAIT);

Expand Down
8 changes: 6 additions & 2 deletions drivers/ethernet/eth_w5500.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,12 @@ static void w5500_rx(const struct device *dev)
w5500_command(dev, S0_CR_RECV);
}

static void w5500_thread(const struct device *dev)
static void w5500_thread(void *p1, void *p2, void *p3)
{
ARG_UNUSED(p2);
ARG_UNUSED(p3);

const struct device *dev = p1;
uint8_t ir;
struct w5500_runtime *ctx = dev->data;
const struct w5500_config *config = dev->config;
Expand Down Expand Up @@ -557,7 +561,7 @@ static int w5500_init(const struct device *dev)

k_thread_create(&ctx->thread, ctx->thread_stack,
CONFIG_ETH_W5500_RX_THREAD_STACK_SIZE,
(k_thread_entry_t)w5500_thread,
w5500_thread,
(void *)dev, NULL, NULL,
K_PRIO_COOP(CONFIG_ETH_W5500_RX_THREAD_PRIO),
0, K_NO_WAIT);
Expand Down

0 comments on commit fbef0ed

Please sign in to comment.