Skip to content

uwb_rng_request is possibly not thread safe. #19

Description

@fjmolinas

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

err = dpl_sem_pend(&rng->sem, DPL_TIMEOUT_NEVER); // Wait for completion of transactions
if (err != DPL_OK) {
goto early_exit;
}

But this semaphore is release in tx_comeplete():

switch(rng->code) {
case UWB_DATA_CODE_SS_TWR ... UWB_DATA_CODE_DS_TWR_EXT_END:
RNG_STATS_INC(tx_complete);
if (rng->control.complete_after_tx) {
dpl_sem_release(&rng->sem);
rng_issue_complete(inst);
}
rng->control.complete_after_tx = 0;
return true;
break;
default:
return false;
}
}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions