drivers: modem: fix race condition when waiting on cmd reply

Command was sent first, then a semaphore was reset. This semaphore could
be released by received reply even before semaphore was reset. This is
quite unlikely, but possible result of race condition.

Move k_sem_reset() call before attempt to send command over modem
interface. This makes sure that receiving reply momentarily after
sending request will always be handled properly.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This commit is contained in:
Marcin Niestroj 2020-11-19 19:42:42 +01:00 committed by Anas Nashif
parent 67976f8686
commit eae32b7e7a

View file

@ -514,11 +514,14 @@ static int _modem_cmd_send(struct modem_iface *iface,
LOG_DBG("EOL not set!!!");
}
#endif
if (sem) {
k_sem_reset(sem);
}
iface->write(iface, buf, strlen(buf));
iface->write(iface, data->eol, data->eol_len);
if (sem) {
k_sem_reset(sem);
ret = k_sem_take(sem, timeout);
if (ret == 0) {