Skip to content

Commit 6f5dc33

Browse files
committed
nvs: Fix deletion of the last entry added
Make sure that the last entry added is deleted correctly by storing the fact that one was found in a local variable. Fix by Laczen JMS <[email protected]> Fixes #18813. Signed-off-by: Carles Cufi <[email protected]>
1 parent e5974f7 commit 6f5dc33

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

subsys/fs/nvs/nvs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ ssize_t nvs_write(struct nvs_fs *fs, u16_t id, const void *data, size_t len)
753753
struct nvs_ate wlk_ate;
754754
u32_t wlk_addr, rd_addr;
755755
u16_t required_space = 0U; /* no space, appropriate for delete ate */
756+
bool prev_found = false;
756757

757758
if (!fs->ready) {
758759
LOG_ERR("NVS not initialized");
@@ -782,14 +783,15 @@ ssize_t nvs_write(struct nvs_fs *fs, u16_t id, const void *data, size_t len)
782783
return rc;
783784
}
784785
if ((wlk_ate.id == id) && (!nvs_ate_crc8_check(&wlk_ate))) {
786+
prev_found = true;
785787
break;
786788
}
787789
if (wlk_addr == fs->ate_wra) {
788790
break;
789791
}
790792
}
791793

792-
if (wlk_addr != fs->ate_wra) {
794+
if (prev_found) {
793795
/* previous entry found */
794796
rd_addr &= ADDR_SECT_MASK;
795797
rd_addr += wlk_ate.offset;

tests/subsys/fs/nvs/src/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,6 @@ void test_nvs_full_sector(void)
503503
len = nvs_write(&fs, filling_id, &filling_id,
504504
sizeof(filling_id));
505505
if (len == -ENOSPC) {
506-
filling_id--;
507506
break;
508507
}
509508
zassert_true(len == sizeof(filling_id), "nvs_write failed: %d",

0 commit comments

Comments
 (0)