Skip to content

Commit 3ae4dfe

Browse files
jakub-uCjhedberg
authored andcommitted
shell: fix deadlock in the bypass function
Previously, the bypass() function was called while the shell mutex was still held, preventing the use of shell APIs (e.g. shell_print()) inside the bypass context. This change unlocks the shell mutex before invoking bypass() and locks it again afterwards, restoring proper shell context handling and preventing potential deadlocks. Issue fixed by: roni1234321 Fixes #97722 Signed-off-by: Jakub Rzeszutko <[email protected]>
1 parent a4588c0 commit 3ae4dfe

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

subsys/shell/shell.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,18 @@ static void state_collect(const struct shell *sh)
999999
sizeof(buf), &count);
10001000
if (count) {
10011001
z_flag_cmd_ctx_set(sh, true);
1002+
/** Unlock the shell mutex before calling the bypass function,
1003+
* allowing shell APIs (e.g. shell_print()) to be used inside it.
1004+
* Since these APIs require the mutex to be unlocked,
1005+
* we temporarily leave the shell context and transfer control
1006+
* to the bypass function.
1007+
*/
1008+
z_shell_unlock(sh);
10021009
bypass(sh, buf, count);
1010+
/* After returning, we're back in the shell context — re-acquire
1011+
* the shell mutex on the shell thread.
1012+
*/
1013+
z_shell_lock(sh);
10031014
z_flag_cmd_ctx_set(sh, false);
10041015
/* Check if bypass mode ended. */
10051016
if (!(volatile shell_bypass_cb_t *)sh->ctx->bypass) {

0 commit comments

Comments
 (0)