From fbbda73faa72ed811225a5bbf9a74b28da33fa93 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 25 May 2016 16:16:23 -0500 Subject: [PATCH] Update Callback to fix fault in serial interrupts per @c1728p9 Update the Callback class to handle a NULL thunk by returning 0 rather than trying to call the thunk. This fixes a crash that occurs on some targets when the TX uart handler is not attached. Background: The K64F HAL uart implementation calls the TX interrupt handler every time a uart interrupt occurs while the TX register is empty. It does not check to see if the TX interrupt has been enabled. This means that the TX interrupt can and typically does get run on RX events. This causes a crash with the newer callback code which did not (prior to this patch) support a NULL thunk. --- hal/api/Callback.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/hal/api/Callback.h b/hal/api/Callback.h index fa1f5ecc3f..b90baf91af 100644 --- a/hal/api/Callback.h +++ b/hal/api/Callback.h @@ -106,6 +106,9 @@ public: /** Call the attached function */ R call(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { + if (!_thunk) { + return (R)0; + } return _thunk(_obj, &_func, a0, a1, a2, a3, a4); } @@ -244,6 +247,9 @@ public: /** Call the attached function */ R call(A0 a0, A1 a1, A2 a2, A3 a3) { + if (!_thunk) { + return (R)0; + } return _thunk(_obj, &_func, a0, a1, a2, a3); } @@ -382,6 +388,9 @@ public: /** Call the attached function */ R call(A0 a0, A1 a1, A2 a2) { + if (!_thunk) { + return (R)0; + } return _thunk(_obj, &_func, a0, a1, a2); } @@ -520,6 +529,9 @@ public: /** Call the attached function */ R call(A0 a0, A1 a1) { + if (!_thunk) { + return (R)0; + } return _thunk(_obj, &_func, a0, a1); } @@ -658,6 +670,9 @@ public: /** Call the attached function */ R call(A0 a0) { + if (!_thunk) { + return (R)0; + } return _thunk(_obj, &_func, a0); } @@ -796,6 +811,9 @@ public: /** Call the attached function */ R call() { + if (!_thunk) { + return (R)0; + } return _thunk(_obj, &_func); }