From 75d3f45d5a57eb0da5b25173d96a5af3753fcf15 Mon Sep 17 00:00:00 2001 From: Jerzy Kasenberg Date: Tue, 15 Oct 2024 12:38:11 +0200 Subject: [PATCH] tests: drivers: spi: spi_slave: Fix memory corruption This fixes memory corruption of delayable work when tests executes unsupported function. When test (e.g. only_rx_in_chunks) is executed it starts delayed work for master functionality (with 10 ms delay). Later when slave function is tried and reports that function is unsupported, test is terminated (task ends) but work is still scheduled. When next test starts it clears work that is already scheduled: static void before(void *not_used) { ARG_UNUSED(not_used); memset(&tdata, 0, sizeof(tdata)); this leads to memory corruption and system work queue tries to remove work but it never does since head/next pointers are zeroed at that time. This just adds after function that cancels work regardless if it was scheduled or not. Signed-off-by: Jerzy Kasenberg --- tests/drivers/spi/spi_controller_peripheral/src/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/drivers/spi/spi_controller_peripheral/src/main.c b/tests/drivers/spi/spi_controller_peripheral/src/main.c index 75e5a4d2ea3..997e6f5f91f 100644 --- a/tests/drivers/spi/spi_controller_peripheral/src/main.c +++ b/tests/drivers/spi/spi_controller_peripheral/src/main.c @@ -530,9 +530,16 @@ static void before(void *not_used) k_sem_init(&tdata.sem, 0, 1); } +static void after(void *not_used) +{ + ARG_UNUSED(not_used); + + k_work_cancel_delayable(&tdata.test_work); +} + static void *suite_setup(void) { return NULL; } -ZTEST_SUITE(spi_controller_peripheral, NULL, suite_setup, before, NULL, NULL); +ZTEST_SUITE(spi_controller_peripheral, NULL, suite_setup, before, after, NULL);