2661ee282a7edfdff299d2ccfc298dac75cf65e4

Author
Nick Brassel <nick@tzarc.org>
Committer
GitHub <noreply@github.com>
Date

Message

[Bugfix] Manipulate deferred executor slot only if tokens match (#22722)

Diff

 1diff --git a/quantum/deferred_exec.c b/quantum/deferred_exec.c
 2index a0046a9648d677a475df0e52eaa71c28b37baa86..b3be3747d47d07aa5ef13371aadcc8629881c1aa 100644
 3--- a/quantum/deferred_exec.c
 4+++ b/quantum/deferred_exec.c
 5@@ -124,13 +124,19 @@ void deferred_exec_advanced_task(deferred_executor_t *table, size_t table_count,
 6 
 7         // Run through each of the executors
 8         for (int i = 0; i < table_count; ++i) {
 9-            deferred_executor_t *entry = &table[i];
10+            deferred_executor_t *entry      = &table[i];
11+            deferred_token       curr_token = entry->token;
12 
13             // Check if we're supposed to execute this entry
14-            if (entry->token != INVALID_DEFERRED_TOKEN && ((int32_t)TIMER_DIFF_32(entry->trigger_time, now)) <= 0) {
15+            if (curr_token != INVALID_DEFERRED_TOKEN && ((int32_t)TIMER_DIFF_32(entry->trigger_time, now)) <= 0) {
16                 // Invoke the callback and work work out if we should be requeued
17                 uint32_t delay_ms = entry->callback(entry->trigger_time, entry->cb_arg);
18 
19+                // If the token has changed, then the callback has canceled and re-queued. Skip further processing.
20+                if (entry->token != curr_token) {
21+                    continue;
22+                }
23+
24                 // Update the trigger time if we have to repeat, otherwise clear it out
25                 if (delay_ms > 0) {
26                     // Intentionally add just the delay to the existing trigger time -- this ensures the next