Skip to content

Commit 622fddb

Browse files
ccli8dkalowsk
authored andcommitted
drivers: wifi: esp_at: fix premature socket release
This fixes premature socket release. Without this fix, system will crash because esp_rx thread can still hold reference to the socket in the following cases: 1. esp_rx thread has got the socket reference but hasn't unref'ed via esp_socket_unref. 2. esp_rx thread can still get the socket reference for refcount not being zero in esp_socket_ref. Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
1 parent a865cf4 commit 622fddb

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/wifi/esp_at/esp_socket.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ void esp_socket_unref(struct esp_socket *sock)
7676
}
7777
} while (!atomic_cas(&sock->refcount, ref, ref - 1));
7878

79+
/* notifies free only on 1-to-0 transition */
80+
if (ref > 1) {
81+
return;
82+
}
83+
7984
k_sem_give(&sock->sem_free);
8085
}
8186

0 commit comments

Comments
 (0)