haukepetersen opened a new pull request #970: URL: https://github.com/apache/mynewt-nimble/pull/970
This one took me some time to track down :-) Under certain situations, NimBLE on RIOT hard-faulted on nRF boards. This happend maybe every 5th or so time a board was rebootet, mainly showing for RIOTs `nimble_scanner` example application. It turned out, that the late initialization of the pseudo random number generator as introduced in #883 has caused this: - the first ever call to `jrand48()` causes a memory allocation (`malloc`) inside the libc code - as `ble_ll_rand()` is partly called from interrupt context, this could trigger the late initialization in the interrupt context, leading to a `malloc` to be executed in interrupt context - end of last year, a thread-safe malloc wrapper was introduced to RIOT, which does not allow for `malloc` calls from interrupt context, triggering a failed assertion (see https://github.com/RIOT-OS/RIOT/pull/15606) - this leads to kind of a race condition for the `nimble_scanner` example: if the first call to `ble_ll_rand()` is coming from thread context, everything is fine, if its by chance coming from interrupt context, the node hard-faults due to a failed assertion. In this PR I propose a pretty simple fix: why don't we simplify the `ble_ll_rand()` initialization per se and merge all three initialization steps into the `ble_ll_rand_init()` function?! This saves a little RAM (no static `init` var), makes the code more concise and prevents the error described above. I don't really see a drawback, as the split between `ble_ll_rand_init()` and `ble_ll_rand_start()` seems rather arbitrary to me, both are called exactly once and right after each other from the controllers init code anyway... -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org