Skip to content

Commit

Permalink
[K32W0] Fix OTA memory allocation (#13530)
Browse files Browse the repository at this point in the history
* [K32W0] Fix OTA memory allocation

Use the non-buggy version from ESP32.
See also: #1339

Signed-off-by: Doru Gucea <[email protected]>

* Restyled by clang-format

* [K32W0] Remove unneeded memory free

Signed-off-by: Doru Gucea <[email protected]>

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Aug 22, 2023
1 parent aa4d7a4 commit 1033886
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/platform/nxp/k32w/k32w0/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,29 +142,29 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context)

CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block)
{
if ((block.data() == nullptr) || block.empty())
if (!IsSpanUsable(block))
{
return CHIP_NO_ERROR;
}

// Allocate memory for block data if it has not been done yet
if (mBlock.empty())
if (mBlock.size() < block.size())
{
mBlock = MutableByteSpan(static_cast<uint8_t *>(chip::Platform::MemoryAlloc(block.size())), block.size());
if (mBlock.data() == nullptr)
if (!mBlock.empty())
{
ReleaseBlock();
}
uint8_t * mBlock_ptr = static_cast<uint8_t *>(chip::Platform::MemoryAlloc(block.size()));
if (mBlock_ptr == nullptr)
{
return CHIP_ERROR_NO_MEMORY;
}
mBlock = MutableByteSpan(mBlock_ptr, block.size());
}

// Store the actual block data
CHIP_ERROR err = CopySpanToMutableSpan(block, mBlock);
if (err != CHIP_NO_ERROR)
{
ChipLogError(SoftwareUpdate, "Cannot copy block data: %" CHIP_ERROR_FORMAT, err.Format());
return err;
}

return CHIP_NO_ERROR;
}

Expand Down

0 comments on commit 1033886

Please sign in to comment.