From 8c46799083a9d59eb5a80724d3108a66fb89c716 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 30 Jun 2022 10:17:08 -0700 Subject: [PATCH] Assert that controllers are inited and shut down with the Matter lock held. We were not asserting this, and some consumers were not doing this, leading to data races. --- src/controller/CHIPDeviceController.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index af7754600d4cf4..53ef449d95573b 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #include @@ -105,6 +106,8 @@ DeviceController::DeviceController() CHIP_ERROR DeviceController::Init(ControllerInitParams params) { + assertChipStackLockedByCurrentThread(); + VerifyOrReturnError(mState == State::NotInitialized, CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnError(params.systemState != nullptr, CHIP_ERROR_INVALID_ARGUMENT); @@ -282,6 +285,8 @@ CHIP_ERROR DeviceController::InitControllerNOCChain(const ControllerInitParams & void DeviceController::Shutdown() { + assertChipStackLockedByCurrentThread(); + VerifyOrReturn(mState != State::NotInitialized); ChipLogDetail(Controller, "Shutting down the controller");