Skip to content

Commit 8cea4ce

Browse files
joerchankartben
authored andcommitted
drivers: modem: Fix possible race condition, reset sem before data send
Fix possible race condition, reset the response semaphore before we send any data. In case we don't get scheduled back before the response is processed. Signed-off-by: Joakim Andersson <joerchan@gmail.com>
1 parent 878de47 commit 8cea4ce

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/modem/ublox-sara-r4.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,16 @@ static ssize_t send_cert(struct modem_socket *sock,
486486
goto exit;
487487
}
488488

489+
/* Reset response semaphore before sending data
490+
* So that we are sure that we won't use a previously pending one
491+
* And we won't miss the one that is going to be freed
492+
*/
493+
k_sem_reset(&mdata.sem_response);
494+
489495
/* slight pause per spec so that @ prompt is received */
490496
k_sleep(MDM_PROMPT_CMD_DELAY);
491497
mctx.iface.write(&mctx.iface, cert_data, cert_len);
492498

493-
k_sem_reset(&mdata.sem_response);
494499
ret = k_sem_take(&mdata.sem_response, K_MSEC(1000));
495500

496501
if (ret == 0) {

0 commit comments

Comments
 (0)