summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--host/lib/crossystem.c6
-rw-r--r--tests/vb2_host_nvdata_flashrom_tests.c6
2 files changed, 6 insertions, 6 deletions
diff --git a/host/lib/crossystem.c b/host/lib/crossystem.c
index 63f20c42..59acc0d2 100644
--- a/host/lib/crossystem.c
+++ b/host/lib/crossystem.c
@@ -685,8 +685,8 @@ static int vb2_nv_index(const uint8_t *buf, uint32_t buf_sz, int vbnv_size)
break;
}
- if (!index || index == buf_sz / vbnv_size) {
- fprintf(stderr, "VBNV is either uninitialized or corrupted.\n");
+ if (!index) {
+ fprintf(stderr, "VBNV is uninitialized.\n");
return -1;
}
@@ -737,7 +737,7 @@ int vb2_write_nv_storage_flashrom(struct vb2_context *ctx)
}
next_index = current_index + 1;
- if ((next_index + 1) * vbnv_size == flash_size) {
+ if (next_index * vbnv_size == flash_size) {
/* VBNV is full. Erase and write at beginning. */
memset(flash_buf, 0xff, flash_size);
next_index = 0;
diff --git a/tests/vb2_host_nvdata_flashrom_tests.c b/tests/vb2_host_nvdata_flashrom_tests.c
index 7a147856..33b435d9 100644
--- a/tests/vb2_host_nvdata_flashrom_tests.c
+++ b/tests/vb2_host_nvdata_flashrom_tests.c
@@ -147,12 +147,12 @@ static void test_read_ok_full(void)
reset_test_data(&ctx, sizeof(test_nvdata_16b));
- for (int entry = 0; entry < fake_flash_entry_count - 2; entry++)
+ for (int entry = 0; entry < fake_flash_entry_count - 1; entry++)
memcpy(fake_flash_region + (entry * VB2_NVDATA_SIZE),
test_nvdata_16b, sizeof(test_nvdata_16b));
memcpy(fake_flash_region +
- ((fake_flash_entry_count - 2) * VB2_NVDATA_SIZE),
+ ((fake_flash_entry_count - 1) * VB2_NVDATA_SIZE),
test_nvdata2_16b, sizeof(test_nvdata2_16b));
TEST_EQ(vb2_read_nv_storage_flashrom(&ctx), 0,
@@ -222,7 +222,7 @@ static void test_write_ok_full(void)
reset_test_data(&ctx, sizeof(test_nvdata_16b));
- for (int entry = 0; entry < fake_flash_entry_count - 1; entry++)
+ for (int entry = 0; entry < fake_flash_entry_count; entry++)
memcpy(fake_flash_region + (entry * VB2_NVDATA_SIZE),
test_nvdata_16b, sizeof(test_nvdata_16b));