diff --git a/samples/matter/common/src/binding/binding_handler.cpp b/samples/matter/common/src/binding/binding_handler.cpp index 319c37aa4666..0804da0a625e 100644 --- a/samples/matter/common/src/binding/binding_handler.cpp +++ b/samples/matter/common/src/binding/binding_handler.cpp @@ -31,6 +31,7 @@ namespace Nrf::Matter void BindingHandler::OnInvokeCommandSucces(BindingData *bindingData) { + VerifyOrReturn(bindingData != nullptr, LOG_ERR("Invalid binding data")); LOG_DBG("Binding command applied successfully!"); /* If session was recovered and communication works, reset flag to the initial state. */ diff --git a/samples/matter/light_switch/src/shell_commands.cpp b/samples/matter/light_switch/src/shell_commands.cpp index 43639e596fe9..af31e1991caf 100644 --- a/samples/matter/light_switch/src/shell_commands.cpp +++ b/samples/matter/light_switch/src/shell_commands.cpp @@ -67,42 +67,51 @@ namespace Unicast { Nrf::Matter::BindingHandler::BindingData *data = Platform::New(); - data->EndpointId = LightSwitch::GetInstance().GetLightSwitchEndpointId(); - data->CommandId = Clusters::OnOff::Commands::On::Id; - data->ClusterId = Clusters::OnOff::Id; - data->InvokeCommandFunc = LightSwitch::SwitchChangedHandler; - data->IsGroup.SetValue(false); - - Nrf::Matter::BindingHandler::RunBoundClusterAction(data); - return CHIP_NO_ERROR; + if (data) { + data->EndpointId = LightSwitch::GetInstance().GetLightSwitchEndpointId(); + data->CommandId = Clusters::OnOff::Commands::On::Id; + data->ClusterId = Clusters::OnOff::Id; + data->InvokeCommandFunc = LightSwitch::SwitchChangedHandler; + data->IsGroup.SetValue(false); + + Nrf::Matter::BindingHandler::RunBoundClusterAction(data); + return CHIP_NO_ERROR; + } + return CHIP_ERROR_NO_MEMORY; } static CHIP_ERROR OffCommandHandler(int argc, char **argv) { Nrf::Matter::BindingHandler::BindingData *data = Platform::New(); - data->EndpointId = LightSwitch::GetInstance().GetLightSwitchEndpointId(); - data->CommandId = Clusters::OnOff::Commands::Off::Id; - data->ClusterId = Clusters::OnOff::Id; - data->InvokeCommandFunc = LightSwitch::SwitchChangedHandler; - data->IsGroup.SetValue(false); - - Nrf::Matter::BindingHandler::RunBoundClusterAction(data); - return CHIP_NO_ERROR; + if (data) { + data->EndpointId = LightSwitch::GetInstance().GetLightSwitchEndpointId(); + data->CommandId = Clusters::OnOff::Commands::Off::Id; + data->ClusterId = Clusters::OnOff::Id; + data->InvokeCommandFunc = LightSwitch::SwitchChangedHandler; + data->IsGroup.SetValue(false); + + Nrf::Matter::BindingHandler::RunBoundClusterAction(data); + return CHIP_NO_ERROR; + } + return CHIP_ERROR_NO_MEMORY; } static CHIP_ERROR ToggleCommandHandler(int argc, char **argv) { Nrf::Matter::BindingHandler::BindingData *data = Platform::New(); - data->EndpointId = LightSwitch::GetInstance().GetLightSwitchEndpointId(); - data->CommandId = Clusters::OnOff::Commands::Toggle::Id; - data->ClusterId = Clusters::OnOff::Id; - data->InvokeCommandFunc = LightSwitch::SwitchChangedHandler; - data->IsGroup.SetValue(false); - - Nrf::Matter::BindingHandler::RunBoundClusterAction(data); - return CHIP_NO_ERROR; + if (data) { + data->EndpointId = LightSwitch::GetInstance().GetLightSwitchEndpointId(); + data->CommandId = Clusters::OnOff::Commands::Toggle::Id; + data->ClusterId = Clusters::OnOff::Id; + data->InvokeCommandFunc = LightSwitch::SwitchChangedHandler; + data->IsGroup.SetValue(false); + + Nrf::Matter::BindingHandler::RunBoundClusterAction(data); + return CHIP_NO_ERROR; + } + return CHIP_ERROR_NO_MEMORY; } } /* namespace Unicast */ @@ -142,42 +151,51 @@ namespace Group { Nrf::Matter::BindingHandler::BindingData *data = Platform::New(); - data->EndpointId = LightSwitch::GetInstance().GetLightSwitchEndpointId(); - data->CommandId = Clusters::OnOff::Commands::On::Id; - data->ClusterId = Clusters::OnOff::Id; - data->InvokeCommandFunc = LightSwitch::SwitchChangedHandler; - data->IsGroup.SetValue(true); - - Nrf::Matter::BindingHandler::RunBoundClusterAction(data); - return CHIP_NO_ERROR; + if (data) { + data->EndpointId = LightSwitch::GetInstance().GetLightSwitchEndpointId(); + data->CommandId = Clusters::OnOff::Commands::On::Id; + data->ClusterId = Clusters::OnOff::Id; + data->InvokeCommandFunc = LightSwitch::SwitchChangedHandler; + data->IsGroup.SetValue(true); + + Nrf::Matter::BindingHandler::RunBoundClusterAction(data); + return CHIP_NO_ERROR; + } + return CHIP_ERROR_NO_MEMORY; } CHIP_ERROR OffCommandHandler(int argc, char **argv) { Nrf::Matter::BindingHandler::BindingData *data = Platform::New(); - data->EndpointId = LightSwitch::GetInstance().GetLightSwitchEndpointId(); - data->CommandId = Clusters::OnOff::Commands::Off::Id; - data->ClusterId = Clusters::OnOff::Id; - data->InvokeCommandFunc = LightSwitch::SwitchChangedHandler; - data->IsGroup.SetValue(true); - - Nrf::Matter::BindingHandler::RunBoundClusterAction(data); - return CHIP_NO_ERROR; + if (data) { + data->EndpointId = LightSwitch::GetInstance().GetLightSwitchEndpointId(); + data->CommandId = Clusters::OnOff::Commands::Off::Id; + data->ClusterId = Clusters::OnOff::Id; + data->InvokeCommandFunc = LightSwitch::SwitchChangedHandler; + data->IsGroup.SetValue(true); + + Nrf::Matter::BindingHandler::RunBoundClusterAction(data); + return CHIP_NO_ERROR; + } + return CHIP_ERROR_NO_MEMORY; } CHIP_ERROR ToggleCommandHandler(int argc, char **argv) { Nrf::Matter::BindingHandler::BindingData *data = Platform::New(); - data->EndpointId = LightSwitch::GetInstance().GetLightSwitchEndpointId(); - data->CommandId = Clusters::OnOff::Commands::Toggle::Id; - data->ClusterId = Clusters::OnOff::Id; - data->InvokeCommandFunc = LightSwitch::SwitchChangedHandler; - data->IsGroup.SetValue(true); - - Nrf::Matter::BindingHandler::RunBoundClusterAction(data); - return CHIP_NO_ERROR; + if (data) { + data->EndpointId = LightSwitch::GetInstance().GetLightSwitchEndpointId(); + data->CommandId = Clusters::OnOff::Commands::Toggle::Id; + data->ClusterId = Clusters::OnOff::Id; + data->InvokeCommandFunc = LightSwitch::SwitchChangedHandler; + data->IsGroup.SetValue(true); + + Nrf::Matter::BindingHandler::RunBoundClusterAction(data); + return CHIP_NO_ERROR; + } + return CHIP_ERROR_NO_MEMORY; } } /* namespace Group */ diff --git a/samples/matter/thermostat/src/temperature_measurement/sensor.cpp b/samples/matter/thermostat/src/temperature_measurement/sensor.cpp index 49b7214409e4..e365a122c9a9 100644 --- a/samples/matter/thermostat/src/temperature_measurement/sensor.cpp +++ b/samples/matter/thermostat/src/temperature_measurement/sensor.cpp @@ -85,10 +85,12 @@ void TemperatureSensor::InternalMeasurement() void TemperatureSensor::ExternalMeasurement() { Nrf::Matter::BindingHandler::BindingData *data = Platform::New(); - data->ClusterId = Clusters::TemperatureMeasurement::Id; - data->EndpointId = mTemperatureMeasurementEndpointId; - data->InvokeCommandFunc = ExternalTemperatureMeasurementReadHandler; - BindingHandler::RunBoundClusterAction(data); + if (data) { + data->ClusterId = Clusters::TemperatureMeasurement::Id; + data->EndpointId = mTemperatureMeasurementEndpointId; + data->InvokeCommandFunc = ExternalTemperatureMeasurementReadHandler; + BindingHandler::RunBoundClusterAction(data); + } } void TemperatureSensor::ExternalTemperatureMeasurementReadHandler(const EmberBindingTableEntry &binding,