Skip to content

cyw43_driver_deinit fix #3208

Open

Description

@peterharperuk

cyw43_poll_worker can re-arm sleep_timeout_worker so the order of these is wrong. Not sure the lock is necessary but can't do any hard.

 void cyw43_driver_deinit(async_context_t *context) {
     if (cyw43_async_context != NULL) {
         assert(context == cyw43_async_context);
-        async_context_remove_at_time_worker(context, &sleep_timeout_worker);
+        async_context_acquire_lock_blocking(context);
         async_context_remove_when_pending_worker(context, &cyw43_poll_worker);
+        async_context_remove_at_time_worker(context, &sleep_timeout_worker);
+        async_context_release_lock(context);
         // the IRQ IS on the same core as the context, so must be de-initialized there
         async_context_execute_sync(context, cyw43_irq_deinit, NULL);
         cyw43_deinit(&cyw43_state);

Activity

  1. added this to the 2.3.2 milestone on Sep 24, 2026
  2. kvnloo commented on Sep 29, 2026

    @kvnloo

    I traced the worker lifecycle here. cyw43_do_poll() can re-add sleep_timeout_worker, so the current removal order is racy.

    The FreeRTOS and threadsafe-background remove_* implementations already serialize through the context lock, so I think the minimal fix is to remove cyw43_poll_worker first and sleep_timeout_worker second, without adding an outer lock.

    Once async_context_remove_when_pending_worker() returns, an active poll has completed under the context lock and that worker can no longer re-arm the timeout. Removing sleep_timeout_worker second then closes the remaining edge.

    This also avoids broadening the lock around teardown / execute_sync(), which the cyw43_arch_* deinit comments explicitly warn about.

    I'd add a regression that repeatedly init/deinits with the poll path pending and verifies neither worker can fire after deinit.


  3. kvnloo commented on Sep 29, 2026

    @kvnloo

    I sent a focused fix in #3215.

    The change removes cyw43_poll_worker before sleep_timeout_worker. Since cyw43_do_poll() is what can re-arm the timeout, stopping that worker first closes the teardown race without adding a broader lock around execute_sync().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions