Skip to content

Commit e91db54

Browse files
check kvstore works when opening the db
1 parent c2c09c7 commit e91db54

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

features/FEATURE_BLE/source/generic/KVStoreSecurityDb.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ KVStoreSecurityDb::~KVStoreSecurityDb() {
6363

6464
bool KVStoreSecurityDb::open_db() {
6565
uint8_t version = 0;
66-
db_read(&version, DB_VERSION);
66+
char db_key[DB_FULL_KEY_SIZE];
67+
create_key(db_key, DB_VERSION);
68+
size_t size;
69+
int ret = kv_get(db_key, &version, sizeof(uint8_t), &size);
70+
71+
/* kvstore problem (check if it's been successfully initialised before this call) */
72+
if (ret != MBED_ERROR_ITEM_NOT_FOUND && (ret != MBED_SUCCESS || size != sizeof(uint8_t))) {
73+
return false;
74+
}
6775

6876
/* wipe the db if it's the wrong version or it doesn't exist */
6977
if (version != KVSTORESECURITYDB_VERSION) {

0 commit comments

Comments
 (0)