Skip to main content
FStut
Associate
December 11, 2018
Question

Possible bug in the memory pools CMSIS implementation during allocation. Needs verifying

  • December 11, 2018
  • 1 reply
  • 668 views

I use the CMSIS wrapper for FreeRTOS generated by CubeMX. This Project was generated about 4 month ago with the current version at that time. I didn't find this bug in forums so I'll ask here.

In *osPoolAlloc() the array of pool entries will be search for a free spot. If it's found in the markers-array, the corresponding memory pointer is returned. I think to speed up sucessive allocations, a currentIndex is saved. If I interpreted the code right, the search should start at currentIndex and wrap around the markers-array.

E.g. is the length is 5 (0, ..., 4) and currentIndex is 2, the order should be 2, 3, 4, 0 and finally 1.

The generated code looks like this:

for (i = 0; i < pool_id->pool_sz; i++) {
 index = pool_id->currentIndex + i;
 if (index >= pool_id->pool_sz) {
 index = 0;
 }
 // actual logic
}

What happens is instead of wrapping the index, it will be set to 0. In the example the sequence 2, 3, 4, 0, 0 will be generated. This fixes the behaviour:

for (i = 0; i < pool_id->pool_sz; i++) {
 index = (pool_id->currentIndex + i) % pool_id->pool_sz;
 // actual logic
}

Can someone verify this and check, if this wasn't fixed in the meantime?

Thanks!

This topic has been closed for replies.

1 reply

Technical Moderator
December 13, 2018

Hello @FStut​,

Thank you for reported this issue. This is already raised internally for fix as a better implementation would be:

index = (pool_id->currentIndex + i) % pool_id->pool_sz;

without resetting the index to '0'.

Kind Regards,

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks