Skip to content

Commit 440de0d

Browse files
yolavalkartben
authored andcommitted
fs: nvs: fix invalid block compare when data CRC is enabled
When nvs_write is called, the nvs_flash_block_cmp is used to check if the new data to be written matches the data already on flash. This check always fail when CONFIG_NVS_DATA_CRC is enabled, caused by the NVS_DATA_CRC_SIZE being added to the len parameter. The pointer to the new data does not already have the CRC part added, while the data on flash does, and the size to be compared includes CRC section. By removing the addition of NVS_DATA_CRC_SIZE to the compare size, only the data without CRC is compared, which will make the compare work in both cases. Signed-off-by: Yonas Alizadeh <[email protected]>
1 parent 691816d commit 440de0d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

subsys/fs/nvs/nvs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,10 @@ ssize_t nvs_write(struct nvs_fs *fs, uint16_t id, const void *data, size_t len)
11361136
} else if (len + NVS_DATA_CRC_SIZE == wlk_ate.len) {
11371137
/* do not try to compare if lengths are not equal */
11381138
/* compare the data and if equal return 0 */
1139-
rc = nvs_flash_block_cmp(fs, rd_addr, data, len + NVS_DATA_CRC_SIZE);
1139+
/* note: data CRC is not taken into account here, as it has not yet been
1140+
* appended to the data buffer
1141+
*/
1142+
rc = nvs_flash_block_cmp(fs, rd_addr, data, len);
11401143
if (rc <= 0) {
11411144
return rc;
11421145
}

0 commit comments

Comments
 (0)