Skip to content

Commit d3052f1

Browse files
authoredSep 11, 2024··
Event Groups: snapshot xEventGroupSetBits returning value while in vTaskSuspendAll (FreeRTOS#1143)
Event Groups: snapshot xEventGroupSetBits returning value while in vTaskSuspendAll. Fixes uxEventBits dereference after event group deleted by higher priority thread.
1 parent d806240 commit d3052f1

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed
 

‎event_groups.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@
551551
ListItem_t * pxNext;
552552
ListItem_t const * pxListEnd;
553553
List_t const * pxList;
554-
EventBits_t uxBitsToClear = 0, uxBitsWaitedFor, uxControlBits;
554+
EventBits_t uxBitsToClear = 0, uxBitsWaitedFor, uxControlBits, uxReturnBits;
555555
EventGroup_t * pxEventBits = xEventGroup;
556556
BaseType_t xMatchFound = pdFALSE;
557557

@@ -635,12 +635,15 @@
635635
/* Clear any bits that matched when the eventCLEAR_EVENTS_ON_EXIT_BIT
636636
* bit was set in the control word. */
637637
pxEventBits->uxEventBits &= ~uxBitsToClear;
638+
639+
/* Snapshot resulting bits. */
640+
uxReturnBits = pxEventBits->uxEventBits;
638641
}
639642
( void ) xTaskResumeAll();
640643

641-
traceRETURN_xEventGroupSetBits( pxEventBits->uxEventBits );
644+
traceRETURN_xEventGroupSetBits( uxReturnBits );
642645

643-
return pxEventBits->uxEventBits;
646+
return uxReturnBits;
644647
}
645648
/*-----------------------------------------------------------*/
646649

‎include/event_groups.h

+5-8
Original file line numberDiff line numberDiff line change
@@ -483,14 +483,11 @@ EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup,
483483
* and bit 0 set uxBitsToSet to 0x09.
484484
*
485485
* @return The value of the event group at the time the call to
486-
* xEventGroupSetBits() returns. There are two reasons why the returned value
487-
* might have the bits specified by the uxBitsToSet parameter cleared. First,
488-
* if setting a bit results in a task that was waiting for the bit leaving the
489-
* blocked state then it is possible the bit will be cleared automatically
490-
* (see the xClearBitOnExit parameter of xEventGroupWaitBits()). Second, any
491-
* unblocked (or otherwise Ready state) task that has a priority above that of
492-
* the task that called xEventGroupSetBits() will execute and may change the
493-
* event group value before the call to xEventGroupSetBits() returns.
486+
* xEventGroupSetBits() returns. Returned value might have the bits specified
487+
* by the uxBitsToSet parameter cleared if setting a bit results in a task
488+
* that was waiting for the bit leaving the blocked state then it is possible
489+
* the bit will be cleared automatically (see the xClearBitOnExit parameter
490+
* of xEventGroupWaitBits()).
494491
*
495492
* Example usage:
496493
* @code{c}

0 commit comments

Comments
 (0)
Please sign in to comment.