Skip to content

Commit fbbda73

Browse files
gekytheotherjimmy
authored andcommitted
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.
1 parent a7f4262 commit fbbda73

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

hal/api/Callback.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ class Callback<R(A0, A1, A2, A3, A4)> {
106106
/** Call the attached function
107107
*/
108108
R call(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
109+
if (!_thunk) {
110+
return (R)0;
111+
}
109112
return _thunk(_obj, &_func, a0, a1, a2, a3, a4);
110113
}
111114

@@ -244,6 +247,9 @@ class Callback<R(A0, A1, A2, A3)> {
244247
/** Call the attached function
245248
*/
246249
R call(A0 a0, A1 a1, A2 a2, A3 a3) {
250+
if (!_thunk) {
251+
return (R)0;
252+
}
247253
return _thunk(_obj, &_func, a0, a1, a2, a3);
248254
}
249255

@@ -382,6 +388,9 @@ class Callback<R(A0, A1, A2)> {
382388
/** Call the attached function
383389
*/
384390
R call(A0 a0, A1 a1, A2 a2) {
391+
if (!_thunk) {
392+
return (R)0;
393+
}
385394
return _thunk(_obj, &_func, a0, a1, a2);
386395
}
387396

@@ -520,6 +529,9 @@ class Callback<R(A0, A1)> {
520529
/** Call the attached function
521530
*/
522531
R call(A0 a0, A1 a1) {
532+
if (!_thunk) {
533+
return (R)0;
534+
}
523535
return _thunk(_obj, &_func, a0, a1);
524536
}
525537

@@ -658,6 +670,9 @@ class Callback<R(A0)> {
658670
/** Call the attached function
659671
*/
660672
R call(A0 a0) {
673+
if (!_thunk) {
674+
return (R)0;
675+
}
661676
return _thunk(_obj, &_func, a0);
662677
}
663678

@@ -796,6 +811,9 @@ class Callback<R()> {
796811
/** Call the attached function
797812
*/
798813
R call() {
814+
if (!_thunk) {
815+
return (R)0;
816+
}
799817
return _thunk(_obj, &_func);
800818
}
801819

0 commit comments

Comments
 (0)