Skip to content

Commit

Permalink
[ESP32] Unregistering wifi and IP event handlers before factory reset…
Browse files Browse the repository at this point in the history
… to avoid random crashes due to PostEventQueue failure. (#33684) (#33702)

* Unregistering wifi and IP event handlers before factory reset to avoid random crashes due to post event queue failure

* Restyled by clang-format

* Fix the CI failure in lit-icd app

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
shripad621git and restyled-commits committed Jun 3, 2024
1 parent c9cfd3f commit 6aea023
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/platform/ESP32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <lib/support/CodeUtils.h>
#include <platform/ConfigurationManager.h>
#include <platform/ESP32/ESP32Config.h>
#include <platform/ESP32/ESP32Utils.h>
#include <platform/internal/GenericConfigurationManagerImpl.ipp>

#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
Expand Down Expand Up @@ -404,6 +405,22 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
{
CHIP_ERROR err;

// Unregistering the wifi and IP event handlers from the esp_default_event_loop()
err = ESP32Utils::MapError(esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent));
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Failed to unregister IP event handler");
}

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
err =
ESP32Utils::MapError(esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent));
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Failed to unregister wifi event handler");
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI

ChipLogProgress(DeviceLayer, "Performing factory reset");

// Erase all values in the chip-config NVS namespace.
Expand Down

0 comments on commit 6aea023

Please sign in to comment.