From 16af010e71020e802a30efc1038226a02a1ff3ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Quentin?= Date: Wed, 22 Jan 2025 15:21:54 +0100 Subject: [PATCH] esp-wifi: fix possible deadlock (#3015) * Fix possible deadlock * CHANGELOG * avoid `mem::forget` --- esp-wifi/CHANGELOG.md | 2 ++ esp-wifi/src/wifi/mod.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/esp-wifi/CHANGELOG.md b/esp-wifi/CHANGELOG.md index 7af1bf14057..d757f42955d 100644 --- a/esp-wifi/CHANGELOG.md +++ b/esp-wifi/CHANGELOG.md @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed a problem using BLE on ESP32-C6 when connected via Serial-JTAG (#2981) +- Fix a possible dead-lock when the rx-queue is overrun (#3015) + ### Removed ## 0.12.0 - 2025-01-15 diff --git a/esp-wifi/src/wifi/mod.rs b/esp-wifi/src/wifi/mod.rs index aede5895434..8f4e93e6f19 100644 --- a/esp-wifi/src/wifi/mod.rs +++ b/esp-wifi/src/wifi/mod.rs @@ -1536,12 +1536,12 @@ unsafe extern "C" fn recv_cb_sta( // which will try to lock an internal mutex. If the mutex is already taken, // the function will try to trigger a context switch, which will fail if we // are in an interrupt-free context. - if DATA_QUEUE_RX_STA.with(|queue| { + if let Ok(()) = DATA_QUEUE_RX_STA.with(|queue| { if queue.len() < RX_QUEUE_SIZE { queue.push_back(packet); - true + Ok(()) } else { - false + Err(packet) } }) { embassy::STA_RECEIVE_WAKER.wake(); @@ -1564,12 +1564,12 @@ unsafe extern "C" fn recv_cb_ap( // which will try to lock an internal mutex. If the mutex is already taken, // the function will try to trigger a context switch, which will fail if we // are in an interrupt-free context. - if DATA_QUEUE_RX_AP.with(|queue| { + if let Ok(()) = DATA_QUEUE_RX_AP.with(|queue| { if queue.len() < RX_QUEUE_SIZE { queue.push_back(packet); - true + Ok(()) } else { - false + Err(packet) } }) { embassy::AP_RECEIVE_WAKER.wake();