modem: chat: patch unintended behavior in modem_chat_run_script()

Trying to start a chat script using either modem_chat_run_script()
or modem_chat_run_script_async() should result in returning -EBUSY
without affecting the currently running script and thread waiting
on the current script to stop.

The current behavior causes the thread waiting for the current
script to stop to return with error -EAGAIN, and the thread trying
to start the new script to return with error -EBUSY.

This commit moves the reset of the sem the current thread is
waiting on, to after the check of whether a script is currently
running, leaving the current thread unaffected as is intended.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
This commit is contained in:
Bjarki Arge Andreasen 2024-06-12 16:01:21 +02:00 committed by Alberto Escolar
parent 22061bd7a8
commit 494fab8ea4

View file

@ -877,6 +877,8 @@ int modem_chat_run_script_async(struct modem_chat *chat, const struct modem_chat
return -EBUSY; return -EBUSY;
} }
k_sem_reset(&chat->script_stopped_sem);
chat->pending_script = script; chat->pending_script = script;
k_work_submit(&chat->script_run_work); k_work_submit(&chat->script_run_work);
return 0; return 0;
@ -886,8 +888,6 @@ int modem_chat_run_script(struct modem_chat *chat, const struct modem_chat_scrip
{ {
int ret; int ret;
k_sem_reset(&chat->script_stopped_sem);
ret = modem_chat_run_script_async(chat, script); ret = modem_chat_run_script_async(chat, script);
if (ret < 0) { if (ret < 0) {
return ret; return ret;