From 28a962075818f20c38c9bd0d6b2d79573055edd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Ku=C5=BAnia?= Date: Tue, 6 Aug 2019 18:16:08 +0200 Subject: [PATCH] [ncp] set NCP instance pointer to NULL during pseudo reset (#4065) This commit fixes the problem with initializing the NCP with wpantund. The bug was apparent when the NCP image was built with the FULL_LOGS switch set. The reason for the bug was that after the pseudo reset the OpenThread stack wrote logs to NCP's otPlatLog implementation that used the not yet initialized NCP object. This put the mUartSendTask and mUpdateChangedPropsTask to the TaskletScheduler linked list. Later when the NCP itself was initialized, the mNext pointer in the tasklets mUartSendTask and mUpdateChangedPropsTask was set to null, causing all tasklets scheduled after the mUartSendTask to be lost. The NCP reset status could not be in such case sent to the wpantund. The wpantund then retried resetting the NCP, which repeated the process until the wpantund gave up. --- src/ncp/ncp_base.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index 9803ba95a..f4baf6265 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -604,7 +604,7 @@ void NcpBase::Log(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aLog otError error = OT_ERROR_NONE; uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0; - VerifyOrExit(!mDisableStreamWrite); + VerifyOrExit(!mDisableStreamWrite, error = OT_ERROR_INVALID_STATE); VerifyOrExit(!mChangedPropsSet.IsPropertyFiltered(SPINEL_PROP_STREAM_LOG)); // If there is a pending queued response we do not allow any new log @@ -1172,6 +1172,8 @@ otError NcpBase::CommandHandler_RESET(uint8_t aHeader) mUpdateChangedPropsTask.Post(); } + sNcpInstance = NULL; + return error; }