Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

BUG found in FreeRTOS Kernel

Posted by kristofmulier on December 21, 2015

I have found a bug in the following function (from the "list.c" file in the Kernel):

~~~~ void vListInsertEnd(Listt * const pxList, ListItemt * const pxNewListItem) { ListItem_t * const pxIndex = pxList->pxIndex;

/*-----------------------------------------------*/
/* Integrity checks not used, code removed.      */
/*-----------------------------------------------*/

/* Insert a new list item into pxList, but rather than sort the list,
make the new list item the last item to be removed by a call to
listGET_OWNER_OF_NEXT_ENTRY(). */

pxNewListItem->pxNext = pxIndex;
pxNewListItem->pxPrevious = pxIndex->pxPrevious;

/* Only used during decision coverage testing. */
mtCOVERAGE_TEST_DELAY();

pxIndex->pxPrevious->pxNext = pxNewListItem;
pxIndex->pxPrevious = pxNewListItem;

/* Remember which list the item is in. */
pxNewListItem->pvContainer = (void *) pxList;

(pxList->uxNumberOfItems)++;

/* BUG FOUND                                                     */
/* The documentation for this function mentions: "Placing        */
/* an item in a list using vListInsertEnd(..) effectively        */
/* places the item in the list position pointed to by pvIndex."  */
/* I believe there are two bugs here:                            */
/* (1) The correct field name is not "pvIndex" but "pxIndex"     */
/*     (that's a documentation bug, so not really a big deal)    */
/* (2) The pxList->pxIndex does not point to the NewListItem!    */
/*     The following code line was forgotten:                    */

pxList->pxIndex = pxNewListItem;

} ~~~~

Did anyone experience this bug? Kind greetings,

Kristof Mulier Project Engineer Mechatronics, Sirris - Heverlee (Belgium)


BUG found in FreeRTOS Kernel

Posted by rtel on December 21, 2015

I understand your point that the comments in the code are no longer correct, but it is otherwise not clear to me - have you found something in the code that could either potentially mis-behave or potentially crash? If so, please state clearly what it is so it can be assessed.

By mis-behave I mean result in an incorrect task being selected, or other such incorrect behaviour?

Regards.


BUG found in FreeRTOS Kernel

Posted by kristofmulier on December 21, 2015

Thank you very much for your quick reply :-) No, I did not see a misbehaviour. But I just figured out that the documentation mentions:

~~~~ /* The "pxIndex" from the Listt will point to the newly inserted ListItemt , such that every other item within the list will be returned by listGETOWNEROFNEXTENTRY(..) before the pxIndex parameter again points to the item being inserted. */ ~~~~

Indeed, when you call the macro "listGETOWNEROFNEXTENTRY(..)", the pxIndex parameter from the list gets incremented first, such that it points to the "next entry" from which the owner is returned. So the documentation above makes perfectly sense.

Unfortunately, the documentation doesn't correspond with the actual behaviour of the "vListInsertEnd(..)" function. This is because the following code line is forgotten (or at least, it looks to me like the developer forgot this line of code to update the pxIndex):

~~~~ pxList->pxIndex = pxNewListItem; ~~~~

That's all :-) One more question: I noticed that some parts of the documentation mention the List_t to be in descending order, whereas other parts of the documentation state that it's ascending order. So I'm a bit confused. From the function:

~~~~ vListInsert( Listt * const pxList, ListItemt * const pxNewListItem ) ~~~~ I conclude that it is ascending order (from small to large). Is my conclusion correct?

Kind greetings :-)


BUG found in FreeRTOS Kernel

Posted by edwards3 on December 21, 2015

I think the following quick test shows the expected behavior?

~~~~ ListItemt item1 = { 1, NULL, NULL, 1, NULL }; ListItemt item2 = { 2, NULL, NULL, 2, NULL }; ListItemt item3 = { 3, NULL, NULL, 3, NULL }; ListItemt item4 = { 0, NULL, NULL, 0, NULL }; List_t list; void *result;

int main( void ) { vListInitialise(&list);

vListInsert(&list, &item1);
vListInsert(&list, &item2);
vListInsert(&list, &item3);
vListInsert(&list, &item4);

// vListInsert() used, so expect to receive in item value order.
listGET_OWNER_OF_NEXT_ENTRY(result, &list);
configASSERT((int)result == 0); // << 0 first
listGET_OWNER_OF_NEXT_ENTRY(result, &list);
configASSERT((int)result == 1);
listGET_OWNER_OF_NEXT_ENTRY(result, &list);
configASSERT((int)result == 2);
listGET_OWNER_OF_NEXT_ENTRY(result, &list);
configASSERT((int)result == 3);


vListInitialise(&list);

vListInsert(&list, &item1);
vListInsert(&list, &item2);
vListInsert(&list, &item3);
vListInsertEnd(&list, &item4);

// vListInsertEnd() used, so expect to receive 0 last.
listGET_OWNER_OF_NEXT_ENTRY(result, &list);
configASSERT((int)result == 1);
listGET_OWNER_OF_NEXT_ENTRY(result, &list);
configASSERT((int)result == 2);
listGET_OWNER_OF_NEXT_ENTRY(result, &list);
configASSERT((int)result == 3);
listGET_OWNER_OF_NEXT_ENTRY(result, &list);
configASSERT((int)result == 0); // << 0 last

~~~~


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists