From b3c60533dd75f608a3c4db86efa60920a6754b4e Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Thu, 19 Oct 2023 16:06:28 -0700 Subject: [PATCH 1/2] treewide: Add CODE_UNREACHABLE after k_thread_abort(current) Compiler can't tell that k_thread_abort() won't return and issues a warning unless we tell it that control never gets this far. Signed-off-by: Flavio Ceolin (cherry picked from commit 564adad952fcd7171fbeb8d5292094e87c4b09f8) --- lib/posix/pthread.c | 2 ++ samples/modules/tflite-micro/tflm_ethosu/src/main.cpp | 2 ++ subsys/shell/shell.c | 2 ++ subsys/testsuite/ztest/src/ztest.c | 2 ++ subsys/testsuite/ztest/src/ztest_error_hook.c | 2 ++ subsys/testsuite/ztest/src/ztest_new.c | 2 ++ tests/kernel/sched/deadline/src/main.c | 2 ++ .../kernel/threads/thread_apis/src/test_threads_cancel_abort.c | 1 + 8 files changed, 15 insertions(+) diff --git a/lib/posix/pthread.c b/lib/posix/pthread.c index 7377f2b133dfc7..f2bbc07ae9a463 100644 --- a/lib/posix/pthread.c +++ b/lib/posix/pthread.c @@ -628,6 +628,8 @@ void pthread_exit(void *retval) /* not a valid posix_thread */ LOG_DBG("Aborting non-pthread %p", k_current_get()); k_thread_abort(k_current_get()); + + CODE_UNREACHABLE; } /* Make a thread as cancelable before exiting */ diff --git a/samples/modules/tflite-micro/tflm_ethosu/src/main.cpp b/samples/modules/tflite-micro/tflm_ethosu/src/main.cpp index 19a4afad9c2050..5671b0a0718541 100644 --- a/samples/modules/tflite-micro/tflm_ethosu/src/main.cpp +++ b/samples/modules/tflite-micro/tflm_ethosu/src/main.cpp @@ -149,6 +149,8 @@ void inferenceProcessTask(void *_name, void *heap, void *_params) } k_thread_abort(k_current_get()); + + CODE_UNREACHABLE; } /* inferenceSenderTask - Creates NUM_INFERENCE_JOBS jobs, queues them, and then diff --git a/subsys/shell/shell.c b/subsys/shell/shell.c index 34ed7daa755bfa..1a803d73339f68 100644 --- a/subsys/shell/shell.c +++ b/subsys/shell/shell.c @@ -1307,6 +1307,8 @@ static void kill_handler(const struct shell *sh) sh->ctx->tid = NULL; k_thread_abort(k_current_get()); + + CODE_UNREACHABLE; } void shell_thread(void *shell_handle, void *arg_log_backend, diff --git a/subsys/testsuite/ztest/src/ztest.c b/subsys/testsuite/ztest/src/ztest.c index 04e16b97f927d3..69a975c645fd03 100644 --- a/subsys/testsuite/ztest/src/ztest.c +++ b/subsys/testsuite/ztest/src/ztest.c @@ -324,6 +324,8 @@ static void test_finalize(void) if (IS_ENABLED(CONFIG_MULTITHREADING)) { k_thread_abort(&ztest_thread); k_thread_abort(k_current_get()); + + CODE_UNREACHABLE; } } diff --git a/subsys/testsuite/ztest/src/ztest_error_hook.c b/subsys/testsuite/ztest/src/ztest_error_hook.c index e0a92077b0e139..64dede71533eff 100644 --- a/subsys/testsuite/ztest/src/ztest_error_hook.c +++ b/subsys/testsuite/ztest/src/ztest_error_hook.c @@ -106,6 +106,8 @@ static inline void z_vrfy_ztest_set_assert_valid(bool valid) __weak void ztest_post_assert_fail_hook(void) { k_thread_abort(k_current_get()); + + CODE_UNREACHABLE; } #ifdef CONFIG_ASSERT_NO_FILE_INFO diff --git a/subsys/testsuite/ztest/src/ztest_new.c b/subsys/testsuite/ztest/src/ztest_new.c index b100921ab21ac2..4215ec77c89e6f 100644 --- a/subsys/testsuite/ztest/src/ztest_new.c +++ b/subsys/testsuite/ztest/src/ztest_new.c @@ -440,6 +440,8 @@ static void test_finalize(void) if (IS_ENABLED(CONFIG_MULTITHREADING)) { k_thread_abort(&ztest_thread); k_thread_abort(k_current_get()); + + CODE_UNREACHABLE; } } diff --git a/tests/kernel/sched/deadline/src/main.c b/tests/kernel/sched/deadline/src/main.c index a3fd777a779140..7e1cf7a63c8a98 100644 --- a/tests/kernel/sched/deadline/src/main.c +++ b/tests/kernel/sched/deadline/src/main.c @@ -125,6 +125,8 @@ void yield_worker(void *p1, void *p2, void *p3) zassert_true(n_exec == NUM_THREADS, ""); k_thread_abort(k_current_get()); + + CODE_UNREACHABLE; } ZTEST(suite_deadline, test_yield) diff --git a/tests/kernel/threads/thread_apis/src/test_threads_cancel_abort.c b/tests/kernel/threads/thread_apis/src/test_threads_cancel_abort.c index 481aeac676df19..cfe4fab24b70c8 100644 --- a/tests/kernel/threads/thread_apis/src/test_threads_cancel_abort.c +++ b/tests/kernel/threads/thread_apis/src/test_threads_cancel_abort.c @@ -25,6 +25,7 @@ static void thread_entry_abort(void *p1, void *p2, void *p3) /**TESTPOINT: abort current thread*/ execute_flag = 1; k_thread_abort(k_current_get()); + CODE_UNREACHABLE; /*unreachable*/ execute_flag = 2; zassert_true(1 == 0); From e1550e0c7186e7f9bd5018ea581b5b7509cfd240 Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Thu, 19 Oct 2023 22:27:15 -0700 Subject: [PATCH 2/2] ztest: Do not abort k_current_get from ISR Do not abort k_current_get() from ISR. Signed-off-by: Flavio Ceolin (cherry picked from commit c166685fcfeb9a11157c8d5aba8b2806df2aaf7c) --- subsys/testsuite/ztest/src/ztest.c | 5 ++++- subsys/testsuite/ztest/src/ztest_new.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/subsys/testsuite/ztest/src/ztest.c b/subsys/testsuite/ztest/src/ztest.c index 69a975c645fd03..dcce9acfe3baf1 100644 --- a/subsys/testsuite/ztest/src/ztest.c +++ b/subsys/testsuite/ztest/src/ztest.c @@ -323,8 +323,11 @@ static void test_finalize(void) { if (IS_ENABLED(CONFIG_MULTITHREADING)) { k_thread_abort(&ztest_thread); - k_thread_abort(k_current_get()); + if (k_is_in_isr()) { + return; + } + k_thread_abort(k_current_get()); CODE_UNREACHABLE; } } diff --git a/subsys/testsuite/ztest/src/ztest_new.c b/subsys/testsuite/ztest/src/ztest_new.c index 4215ec77c89e6f..12271e61eb9caa 100644 --- a/subsys/testsuite/ztest/src/ztest_new.c +++ b/subsys/testsuite/ztest/src/ztest_new.c @@ -439,8 +439,11 @@ static void test_finalize(void) { if (IS_ENABLED(CONFIG_MULTITHREADING)) { k_thread_abort(&ztest_thread); - k_thread_abort(k_current_get()); + if (k_is_in_isr()) { + return; + } + k_thread_abort(k_current_get()); CODE_UNREACHABLE; } }