diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 71856925135fee..9307215472114b 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -1526,32 +1526,26 @@ void BasicFailure(void * context, uint8_t status) #if CHIP_DEVICE_CONFIG_ENABLE_MDNS void DeviceCommissioner::OnNodeIdResolved(const chip::Mdns::ResolvedNodeData & nodeData) { - Device * device = nullptr; - if (mDeviceBeingPaired >= kNumMaxActiveDevices) - { - return; - } - - device = &mActiveDevices[mDeviceBeingPaired]; - if (device->GetDeviceId() == nodeData.mPeerId.GetNodeId() && mCommissioningStage == CommissioningStage::kFindOperational) + if (mDeviceBeingPaired < kNumMaxActiveDevices) { - AdvanceCommissioningStage(CHIP_NO_ERROR); + Device * device = &mActiveDevices[mDeviceBeingPaired]; + if (device->GetDeviceId() == nodeData.mPeerId.GetNodeId() && mCommissioningStage == CommissioningStage::kFindOperational) + { + AdvanceCommissioningStage(CHIP_NO_ERROR); + } } DeviceController::OnNodeIdResolved(nodeData); } void DeviceCommissioner::OnNodeIdResolutionFailed(const chip::PeerId & peer, CHIP_ERROR error) { - Device * device = nullptr; - if (mDeviceBeingPaired >= kNumMaxActiveDevices) - { - return; - } - - device = &mActiveDevices[mDeviceBeingPaired]; - if (device->GetDeviceId() == peer.GetNodeId() && mCommissioningStage == CommissioningStage::kFindOperational) + if (mDeviceBeingPaired < kNumMaxActiveDevices) { - OnSessionEstablishmentError(error); + Device * device = &mActiveDevices[mDeviceBeingPaired]; + if (device->GetDeviceId() == peer.GetNodeId() && mCommissioningStage == CommissioningStage::kFindOperational) + { + OnSessionEstablishmentError(error); + } } DeviceController::OnNodeIdResolutionFailed(peer, error); }