Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nrf noup] Lock thread stack before factory reset #380

Merged

Conversation

LipinskiPNordicSemi
Copy link
Contributor

@LipinskiPNordicSemi LipinskiPNordicSemi commented Jan 19, 2024

This commit fix a problem with thread activity interrupting factory reset. This activity used to led to “Factory reset fail: -6”. Writing to cleared nvm flash pages caused the problem.

@LipinskiPNordicSemi LipinskiPNordicSemi force-pushed the factory_reset_fail branch 2 times, most recently from 1bd8078 to 4406491 Compare January 22, 2024 11:02
@@ -176,6 +176,7 @@ void ConfigurationManagerImpl::RunConfigUnitTest(void)
void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
{
ChipLogProgress(DeviceLayer, "Performing factory reset");
ThreadStackManager().LockThreadStack();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably won't compile (?)

Suggested change
ThreadStackManager().LockThreadStack();
ThreadStackMgr().LockThreadStack();

Also, do not assume it's Matter over Thread.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Damian-Nordic Is there any Matter api which allow to disable thread?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand, I meant that you should compile this line only if CONFIG_NET_L2_OPENTHREAD is defined as it may not compile for Wi-Fi.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw. you could add a comment explaining why this is needed as Lock without Unlock can look weird to newcomers :).

@@ -176,6 +176,7 @@ void ConfigurationManagerImpl::RunConfigUnitTest(void)
void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
{
ChipLogProgress(DeviceLayer, "Performing factory reset");
ThreadStackMgr().LockThreadStack();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be guarded with #ifdef CONFIG_NET_L2_OPENTHREAD

Suggested change
ThreadStackMgr().LockThreadStack();
#ifdef CONFIG_NET_L2_OPENTHREAD
ThreadStackMgr().LockThreadStack();
#endif

Also, as Damian suggested, please describe what is the purpose of this call here and why it can be used here without unlocking the stack.

This commit fix a problem with thread activity interrupting factory reset.
This activity used to led to “Factory reset fail: -6”.
Writing to cleared nvm flash pages caused the problem.

Signed-off-by: Patryk Lipinski <[email protected]>
Signed-off-by: Michał Szablowski <[email protected]>
@kkasperczyk-no kkasperczyk-no merged commit 4936f9f into nrfconnect:master Feb 1, 2024
4 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants