Skip to content

Commit d55c592

Browse files
authored
Fix linux BLE deadload (#26418)
Make is so ChipDeviceScanner::StartScan is only called while in the Matter Context
1 parent 80b6fd9 commit d55c592

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/controller/python/chip/ble/LinuxImpl.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ extern "C" void * pychip_ble_start_scanning(PyObject * context, void * adapter,
130130
return nullptr;
131131
}
132132

133-
if (scanner->StartScan(chip::System::Clock::Milliseconds32(timeoutMs)) != CHIP_NO_ERROR)
133+
CHIP_ERROR err = CHIP_NO_ERROR;
134+
chip::DeviceLayer::PlatformMgr().LockChipStack();
135+
err = scanner->StartScan(chip::System::Clock::Milliseconds32(timeoutMs));
136+
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
137+
if (err != CHIP_NO_ERROR)
134138
{
135139
return nullptr;
136140
}

src/platform/Linux/bluez/ChipDeviceScanner.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ std::unique_ptr<ChipDeviceScanner> ChipDeviceScanner::Create(BluezAdapter1 * ada
141141

142142
CHIP_ERROR ChipDeviceScanner::StartScan(System::Clock::Timeout timeout)
143143
{
144+
assertChipStackLockedByCurrentThread();
144145
ReturnErrorCodeIf(mIsScanning, CHIP_ERROR_INCORRECT_STATE);
145146

146147
mIsScanning = true; // optimistic, to allow all callbacks to check this
@@ -157,9 +158,7 @@ CHIP_ERROR ChipDeviceScanner::StartScan(System::Clock::Timeout timeout)
157158
return CHIP_ERROR_INTERNAL;
158159
}
159160

160-
DeviceLayer::PlatformMgr().LockChipStack();
161161
CHIP_ERROR err = chip::DeviceLayer::SystemLayer().StartTimer(timeout, TimerExpiredCallback, static_cast<void *>(this));
162-
DeviceLayer::PlatformMgr().UnlockChipStack();
163162

164163
if (err != CHIP_NO_ERROR)
165164
{

src/platform/Linux/bluez/ChipDeviceScanner.h

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class ChipDeviceScanner
6666
~ChipDeviceScanner();
6767

6868
/// Initiate a scan for devices, with the given timeout
69+
///
70+
/// This method must be called while in the Matter context (from the Matter event
71+
/// loop, or while holding the Matter stack lock).
6972
CHIP_ERROR StartScan(System::Clock::Timeout timeout);
7073

7174
/// Stop any currently running scan

0 commit comments

Comments
 (0)