diff --git a/examples/platforms/qpg6095/settings.cpp b/examples/platforms/qpg6095/settings.cpp index 1cc6ba559..500e9929e 100644 --- a/examples/platforms/qpg6095/settings.cpp +++ b/examples/platforms/qpg6095/settings.cpp @@ -55,6 +55,11 @@ void otPlatSettingsInit(otInstance *aInstance) qorvoSettingsInit(); } +void otPlatSettingsDeinit(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); +} + otError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength) { otError error = OT_ERROR_NOT_FOUND; diff --git a/examples/platforms/utils/settings_flash.c b/examples/platforms/utils/settings_flash.c index 4ea5f3b73..a8c0a2f65 100644 --- a/examples/platforms/utils/settings_flash.c +++ b/examples/platforms/utils/settings_flash.c @@ -303,6 +303,11 @@ void otPlatSettingsInit(otInstance *aInstance) } } +void otPlatSettingsDeinit(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); +} + otError otPlatSettingsBeginChange(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance); diff --git a/include/openthread/platform/settings.h b/include/openthread/platform/settings.h index 115cc67a9..d80c2aff2 100644 --- a/include/openthread/platform/settings.h +++ b/include/openthread/platform/settings.h @@ -60,6 +60,14 @@ extern "C" { */ void otPlatSettingsInit(otInstance *aInstance); +/** + * Performs any de-initialization for the settings subsystem, if necessary. + * + * @param[in] aInstance The OpenThread instance structure. + * + */ +void otPlatSettingsDeinit(otInstance *aInstance); + /// Fetches the value of a setting /** This function fetches the value of the setting identified * by aKey and write it to the memory pointed to by aValue. diff --git a/src/core/common/instance.cpp b/src/core/common/instance.cpp index 8543da6f0..13c5282e4 100644 --- a/src/core/common/instance.cpp +++ b/src/core/common/instance.cpp @@ -178,6 +178,8 @@ void Instance::Finalize(void) IgnoreReturnValue(otThreadSetEnabled(this, false)); IgnoreReturnValue(otIp6SetEnabled(this, false)); IgnoreReturnValue(otLinkSetEnabled(this, false)); + + Get().Deinit(); #endif #if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES diff --git a/src/core/common/settings.cpp b/src/core/common/settings.cpp index 679b26937..473cdc4d7 100644 --- a/src/core/common/settings.cpp +++ b/src/core/common/settings.cpp @@ -97,6 +97,11 @@ void Settings::Init(void) otPlatSettingsInit(&GetInstance()); } +void Settings::Deinit(void) +{ + otPlatSettingsDeinit(&GetInstance()); +} + void Settings::Wipe(void) { otPlatSettingsWipe(&GetInstance()); diff --git a/src/core/common/settings.hpp b/src/core/common/settings.hpp index 9a481f2d9..974083b06 100644 --- a/src/core/common/settings.hpp +++ b/src/core/common/settings.hpp @@ -182,6 +182,14 @@ public: */ void Init(void); + /** + * This method de-initializes the platform settings (non-volatile) module. + * + * This method should be called when OpenThread instance is no longer in use. + * + */ + void Deinit(void); + /** * This method removes all settings from the non-volatile store. * diff --git a/src/posix/main.c b/src/posix/main.c index 9e3232a2e..b18c14ecb 100644 --- a/src/posix/main.c +++ b/src/posix/main.c @@ -144,6 +144,7 @@ int main(int argc, char *argv[]) otxConsoleDeinit(); #endif otInstanceFinalize(instance); + otSysDeinit(); return 0; } diff --git a/src/posix/platform/misc.c b/src/posix/platform/misc.c index 4ac6ded0e..1b3245294 100644 --- a/src/posix/platform/misc.c +++ b/src/posix/platform/misc.c @@ -45,8 +45,7 @@ static otPlatMcuPowerState gPlatMcuPowerState = OT_PLAT_MCU_POWER_STATE_ON; void otPlatReset(otInstance *aInstance) { - OT_UNUSED_VARIABLE(aInstance); - + otInstanceFinalize(aInstance); otSysDeinit(); longjmp(gResetJump, 1); diff --git a/src/posix/platform/settings.cpp b/src/posix/platform/settings.cpp index 283f655e0..0abba6a4b 100644 --- a/src/posix/platform/settings.cpp +++ b/src/posix/platform/settings.cpp @@ -180,6 +180,14 @@ exit: } } +void otPlatSettingsDeinit(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + assert(sSettingsFd != -1); + VerifyOrDie(close(sSettingsFd) == 0); +} + otError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength) { OT_UNUSED_VARIABLE(aInstance); @@ -484,6 +492,7 @@ int main() assert(otPlatSettingsGet(instance, 0, 0, NULL, NULL) == OT_ERROR_NOT_FOUND); } otPlatSettingsWipe(instance); + otPlatSettingsDeinit(instance); return 0; } diff --git a/tests/fuzz/fuzzer_platform.c b/tests/fuzz/fuzzer_platform.c index b8d3abd99..69de2c039 100644 --- a/tests/fuzz/fuzzer_platform.c +++ b/tests/fuzz/fuzzer_platform.c @@ -353,6 +353,11 @@ void otPlatSettingsInit(otInstance *aInstance) OT_UNUSED_VARIABLE(aInstance); } +void otPlatSettingsDeinit(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); +} + otError otPlatSettingsBeginChange(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance); diff --git a/tests/unit/test_platform.cpp b/tests/unit/test_platform.cpp index ac3286212..3e7b1c933 100644 --- a/tests/unit/test_platform.cpp +++ b/tests/unit/test_platform.cpp @@ -487,6 +487,11 @@ void otPlatSettingsInit(otInstance *aInstance) OT_UNUSED_VARIABLE(aInstance); } +void otPlatSettingsDeinit(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); +} + otError otPlatSettingsBeginChange(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance);