Skip to content

Commit 55104dd

Browse files
committed
Prevent memory_reset_hww from masking flash write failures
memory_reset_hww combined the CHUNK_1 write result and the shared BLE chunk write using |=, so a later successful write could hide an earlier failure. Change both writes to be checked individually and return false on the first failure, making the function only report success when all flash writes succeed. Using explicit checks with early returns instead of changing |= to &= keeps each flash write logically independent and minimalizes the risk of future confusion.
1 parent d8ee94c commit 55104dd

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/memory/memory.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ bool memory_reset_hww(void)
371371
}
372372

373373
// Initialize hww memory
374-
375374
chunk_1_t chunk = {0};
376375
CLEANUP_CHUNK(chunk);
377376
_read_chunk(CHUNK_1, chunk_bytes);
@@ -382,7 +381,9 @@ bool memory_reset_hww(void)
382381
// Set a new noise static private key.
383382
rust_noise_generate_static_private_key(rust_util_bytes_mut(
384383
chunk.fields.noise_static_private_key, sizeof(chunk.fields.noise_static_private_key)));
385-
bool res = _write_chunk(CHUNK_1, chunk.bytes);
384+
if (!_write_chunk(CHUNK_1, chunk.bytes)) {
385+
return false;
386+
}
386387

387388
// Reset bond-db and reinitialize IRK and identity address
388389
if (memory_get_platform() == MEMORY_PLATFORM_BITBOX02_PLUS) {
@@ -405,10 +406,12 @@ bool memory_reset_hww(void)
405406
chunk_shared.fields.ble_identity_address[0] |= 0xc;
406407

407408
memset(&chunk_shared.fields.ble_bond_db, 0xff, sizeof(chunk_shared.fields.ble_bond_db));
408-
res |= _write_to_address(FLASH_SHARED_DATA_START, 0, chunk_shared.bytes);
409+
if (!_write_to_address(FLASH_SHARED_DATA_START, 0, chunk_shared.bytes)) {
410+
return false;
411+
}
409412
}
410413

411-
return res;
414+
return true;
412415
}
413416

414417
static bool _is_bitmask_flag_set(uint8_t flag)

0 commit comments

Comments
 (0)