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:
parent
67976f8686
commit
eae32b7e7a
|
@ -514,11 +514,14 @@ static int _modem_cmd_send(struct modem_iface *iface,
|
||||||
LOG_DBG("EOL not set!!!");
|
LOG_DBG("EOL not set!!!");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (sem) {
|
||||||
|
k_sem_reset(sem);
|
||||||
|
}
|
||||||
|
|
||||||
iface->write(iface, buf, strlen(buf));
|
iface->write(iface, buf, strlen(buf));
|
||||||
iface->write(iface, data->eol, data->eol_len);
|
iface->write(iface, data->eol, data->eol_len);
|
||||||
|
|
||||||
if (sem) {
|
if (sem) {
|
||||||
k_sem_reset(sem);
|
|
||||||
ret = k_sem_take(sem, timeout);
|
ret = k_sem_take(sem, timeout);
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
|
|
Loading…
Reference in a new issue