From b71ae9b1a704a9631698d7d4a92b1dfdfc9a0f69 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Wed, 11 Feb 2015 10:51:17 +0300 Subject: target: fix timer callbacks processing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Warning, behaviour change: before this patch if a timer callback returned an error, the other handlers in the list were not called. This patch fixes two different issues with the way timer callbacks are called: 1. The function is not designed to be reentrant but a nested call is possible via: target_handle timer event -> poll -> target events before/after reexaminantion -> script_command_run -> target_call_timer_callbacks_now . This patch makes function a no-op when called recursively; 2. The current code can deal with the case when calling a handler leads to its removal but not when it leads to removal of the next callback in the list. This patch defers actual removal to consolidate it with the calling loop. These bugs were exposed by Valgrind. Change-Id: Ia628a744634f5d2911eb329747e826cb9772e789 Signed-off-by: Paul Fertser Reviewed-on: http://openocd.zylin.com/2541 Tested-by: jenkins Reviewed-by: Stian Skjelstad Reviewed-by: Andreas Färber Reviewed-by: Spencer Oliver --- src/target/target.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/target/target.h') diff --git a/src/target/target.h b/src/target/target.h index d46571e7..f709d6a5 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -294,6 +294,7 @@ struct target_timer_callback { int (*callback)(void *priv); int time_ms; int periodic; + bool removed; struct timeval when; void *priv; struct target_timer_callback *next; -- cgit v1.2.3-18-g5258