Skip to content

Commit 399f177

Browse files
bjarki-andreasenkartben
authored andcommitted
drivers: flash: sam: fix flash erase last page
The implementation for erasing pages in the flash_sam.c driver indicated a successful erase after exceeding the last page to be erased successfully. Since the last page has no proceeding page, the succeeded status was not set. This fix switches around the status to be set as succeeded before erase begins, to have the succeeded status cleared if page unlock or erase fails. Signed-off-by: Bjarki Arge Andreasen <[email protected]> (cherry picked from commit 9c6195a)
1 parent 0ac2d65 commit 399f177

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

drivers/flash/flash_sam.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -396,17 +396,12 @@ static bool sam_flash_erase_foreach_page(const struct flash_pages_info *info, vo
396396
/* Check if we've reached the end of pages to erase */
397397
if (info->start_offset >= erase_data->section_end) {
398398
/* Succeeded, stop iterating */
399-
erase_data->succeeded = true;
400399
return false;
401400
}
402401

403-
if (sam_flash_unlock_page(dev, info) < 0) {
404-
/* Failed to unlock page, stop iterating */
405-
return false;
406-
}
407-
408-
if (sam_flash_erase_page(dev, info) < 0) {
409-
/* Failed to erase page, stop iterating */
402+
if (sam_flash_unlock_page(dev, info) || sam_flash_erase_page(dev, info)) {
403+
/* Failed to unlock page and erase page, stop iterating */
404+
erase_data->succeeded = false;
410405
return false;
411406
}
412407

@@ -436,7 +431,7 @@ static int sam_flash_erase(const struct device *dev, off_t offset, size_t size)
436431
key = k_spin_lock(&sam_data->lock);
437432
sam_data->erase_data.section_start = offset;
438433
sam_data->erase_data.section_end = offset + size;
439-
sam_data->erase_data.succeeded = false;
434+
sam_data->erase_data.succeeded = true;
440435
flash_page_foreach(dev, sam_flash_erase_foreach_page, sam_data);
441436
if (!sam_data->erase_data.succeeded) {
442437
k_spin_unlock(&sam_data->lock, key);

0 commit comments

Comments
 (0)