wifi: esp_at: claim net_context in rx

Claim the net_context mutext associated with a socket before claiming
the socket mutex. The receive callback claims the net_context mutex
internally, which will now always succeed immediately.

The TX path claims the net_context mutex before the socket mutex, and if
we don't use the same order, we can end up in a deadlock.

Fixes #43470.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
Jordan Yates 2022-03-08 15:41:32 +10:00 committed by Christopher Friedt
parent 50a24d6782
commit a3e7047ad5
1 changed files with 14 additions and 0 deletions

View File

@ -169,6 +169,15 @@ void esp_socket_rx(struct esp_socket *sock, struct net_buf *buf,
return;
}
#ifdef CONFIG_NET_SOCKETS
/* We need to claim the net_context mutex here so that the ordering of
* net_context and socket mutex claims matches the TX code path. Failure
* to do so can lead to deadlocks.
*/
if (sock->context->cond.lock) {
k_mutex_lock(sock->context->cond.lock, K_FOREVER);
}
#endif /* CONFIG_NET_SOCKETS */
k_mutex_lock(&sock->lock, K_FOREVER);
if (sock->recv_cb) {
sock->recv_cb(sock->context, pkt, NULL, NULL,
@ -179,6 +188,11 @@ void esp_socket_rx(struct esp_socket *sock, struct net_buf *buf,
net_pkt_unref(pkt);
}
k_mutex_unlock(&sock->lock);
#ifdef CONFIG_NET_SOCKETS
if (sock->context->cond.lock) {
k_mutex_unlock(sock->context->cond.lock);
}
#endif /* CONFIG_NET_SOCKETS */
}
void esp_socket_close(struct esp_socket *sock)