Skip to content

Commit 41adc4e

Browse files
Alexander Zilberkantadbridge
authored andcommitted
Fix PSA internal storage misconfiguration
Use internal TDBStore instance instead of default one
1 parent 16a73d1 commit 41adc4e

File tree

1 file changed

+16
-14
lines changed
  • components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IMPL

1 file changed

+16
-14
lines changed

components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IMPL/pits_impl.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,22 @@ const uint8_t base64_coding_table[] = {
4848
'4', '5', '6', '7', '8', '9', '+', '-'
4949
};
5050

51-
51+
/*
52+
* \brief Get default KVStore instance for internal flesh storage
53+
*
54+
* \return valid pointer to KVStore
55+
*/
5256
static KVStore *get_kvstore_instance(void)
5357
{
5458
KVMap &kv_map = KVMap::get_instance();
5559

56-
return kv_map.get_main_kv_instance(STR_EXPAND(MBED_CONF_STORAGE_DEFAULT_KV));
60+
KVStore *kvstore = kv_map.get_internal_kv_instance(STR_EXPAND(MBED_CONF_STORAGE_DEFAULT_KV));
61+
if (!kvstore) {
62+
// Can only happen due to system misconfiguration.
63+
// Thus considered as unrecoverable error for runtime.
64+
error("Failed getting kvstore instance\n");
65+
}
66+
return kvstore;
5767
}
5868

5969
static void generate_fn(char *tdb_filename, uint32_t tdb_file_len, uint32_t uid, uint32_t pid)
@@ -91,9 +101,7 @@ static void generate_fn(char *tdb_filename, uint32_t tdb_file_len, uint32_t uid,
91101
psa_its_status_t psa_its_set_impl(uint32_t pid, uint32_t uid, uint32_t data_length, const void *p_data, psa_its_create_flags_t create_flags)
92102
{
93103
KVStore *kvstore = get_kvstore_instance();
94-
if (!kvstore) {
95-
error("psa_its_set_impl() - Failed getting kvstore instance\n");
96-
}
104+
MBED_ASSERT(kvstore);
97105

98106
if ((create_flags != 0) && (create_flags != PSA_ITS_WRITE_ONCE_FLAG)) {
99107
return PSA_ITS_ERROR_FLAGS_NOT_SUPPORTED;
@@ -130,9 +138,7 @@ psa_its_status_t psa_its_set_impl(uint32_t pid, uint32_t uid, uint32_t data_leng
130138
psa_its_status_t psa_its_get_impl(uint32_t pid, uint32_t uid, uint32_t data_offset, uint32_t data_length, void *p_data)
131139
{
132140
KVStore *kvstore = get_kvstore_instance();
133-
if (!kvstore) {
134-
error("psa_its_get_impl() - Failed getting kvstore instance\n");
135-
}
141+
MBED_ASSERT(kvstore);
136142

137143
// Generate KVStore key
138144
char kv_key[PSA_ITS_FILENAME_MAX_LEN] = {'\0'};
@@ -190,9 +196,7 @@ psa_its_status_t psa_its_get_impl(uint32_t pid, uint32_t uid, uint32_t data_offs
190196
psa_its_status_t psa_its_get_info_impl(uint32_t pid, uint32_t uid, struct psa_its_info_t *p_info)
191197
{
192198
KVStore *kvstore = get_kvstore_instance();
193-
if (!kvstore) {
194-
error("psa_its_get_info_impl() - Failed getting kvstore instance\n");
195-
}
199+
MBED_ASSERT(kvstore);
196200

197201
// Generate KVStore key
198202
char kv_key[PSA_ITS_FILENAME_MAX_LEN] = {'\0'};
@@ -226,9 +230,7 @@ psa_its_status_t psa_its_get_info_impl(uint32_t pid, uint32_t uid, struct psa_it
226230
psa_its_status_t psa_its_remove_impl(uint32_t pid, uint32_t uid)
227231
{
228232
KVStore *kvstore = get_kvstore_instance();
229-
if (!kvstore) {
230-
error("psa_its_remove_impl() - Failed getting kvstore instance\n");
231-
}
233+
MBED_ASSERT(kvstore);
232234

233235
// Generate KVStore key
234236
char kv_key[PSA_ITS_FILENAME_MAX_LEN] = {'\0'};

0 commit comments

Comments
 (0)