Decawave / uwb-core

Ultrawideband Core
http://decawave.com
Apache License 2.0
58 stars 36 forks source link

uwb_rng_request is possibly not thread safe. #19

Open fjmolinas opened 3 years ago

fjmolinas commented 3 years ago

In the uwb_rng_request function at the end it waits for a semaphore to be posted, signaling the end of transactions:

https://github.com/Decawave/uwb-core/blob/66f468659ec3353cf7fd6f2bd14f3a6cef397f4e/lib/uwb_rng/src/uwb_rng.c#L535-L538

But this semaphore is release in tx_comeplete():

https://github.com/Decawave/uwb-core/blob/66f468659ec3353cf7fd6f2bd14f3a6cef397f4e/lib/uwb_rng/src/uwb_rng.c#L913-L926

This function is then calling all the rng_complete functions, these could be scheduling an another request, or setting the radio to listen is this is done in ISR context or in another thread with a higher priority than the thread that triggered the uwb_rng_request then the first thread will be locked waiting for the semaphore to be released. This could fix itself in the long run, but if the device was set to listen forever then that thread would be definitively blocked.