cancel
Showing results for 
Search instead for 
Did you mean: 

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

FStut
Associate

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!

1 REPLY 1
Imen.D
ST Employee

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

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen