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

fix(BLE): Fix PalFlashEraseSector, Decrement Erase by Sector Size #726

Merged
merged 1 commit into from
Sep 21, 2023

Conversation

EdwinFairchild
Copy link
Contributor

@EdwinFairchild EdwinFairchild commented Sep 12, 2023

Description

The PalFlashEraseSector function comments and behavior are that of a byte erase function which is incorrect. The function is called assuming size is in terms of sectors which it should be. In the function below PalFlashEraseSector is passed a value of 1 to erase one sector at a time, PalFlashEraseSector then decrements 1 -MXC_FLASH_PAGE_SIZE and causes size to underflow and the number becomes really big since it is unsigned and the function erases lots of sectors causing application to crash and be unrecoverable.

void WsfNvmEraseDataAll(WsfNvmCompEvent_t compCback)
{
  for (uint32_t eraseAddr = WSF_NVM_START_ADDR; eraseAddr < wsfNvmCb.availAddr; eraseAddr += wsfNvmCb.sectorSize) {
    PalFlashEraseSector(1, eraseAddr);
  }
  wsfNvmCb.availAddr = WSF_NVM_START_ADDR;

  if (compCback) {
    compCback(TRUE);
  }
}

Checklist Before Requesting Review

  • PR Title follows correct guidelines.
  • Description of changes and all other relevant information.
  • (Optional) Link any related GitHub issues using a keyword
  • (Optional) Provide info on any relevant functional testing/validation. For API changes or significant features, this is not optional.

@github-actions github-actions bot added the BLE Related to Bluetooth label Sep 12, 2023
@EdwinFairchild EdwinFairchild changed the title fix(BLE): Change comment in PalFlashEraseSector, decrement size by 1 fix(BLE): Fix comment in PalFlashEraseSector, decrement size by 1 Sep 12, 2023
@sihyung-maxim sihyung-maxim changed the title fix(BLE): Fix comment in PalFlashEraseSector, decrement size by 1 fix(BLE): Fix comment in PalFlashEraseSector, decrement size by 1 Sep 12, 2023
@EdwinFairchild
Copy link
Contributor Author

@yc-adi

@Jake-Carter Jake-Carter changed the title fix(BLE): Fix comment in PalFlashEraseSector, decrement size by 1 fix(BLE): Fix PalFlashEraseSector, Decrement Erase by Sector Size Sep 21, 2023
@Jake-Carter Jake-Carter merged commit 37cb121 into main Sep 21, 2023
16 of 20 checks passed
@Jake-Carter Jake-Carter deleted the pal-erase-sector-fix branch September 21, 2023 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BLE Related to Bluetooth
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants