Skip to content

Commit d7086f0

Browse files
committed
[nrf fomlist] secure_storage: its: improve return codes
As the modified functions can return anything other than PSA_SUCCESS to signal an error, make them return the exact error codes encountered so that the ITS implementation layer logs them as errors. Upstream PR #: 90395 Signed-off-by: Tomi Fontanilles <[email protected]>
1 parent d982c42 commit d7086f0

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

subsys/secure_storage/src/its/store/settings.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ psa_status_t secure_storage_its_store_remove(secure_storage_its_uid_t uid)
120120
secure_storage_its_store_settings_get_name(uid, name);
121121

122122
ret = settings_delete(name);
123-
124123
LOG_DBG("%s %s. (%d)", ret ? "Failed to delete" : "Deleted", name, ret);
125-
return ret ? PSA_ERROR_STORAGE_FAILURE : PSA_SUCCESS;
124+
125+
BUILD_ASSERT(PSA_SUCCESS == 0);
126+
return ret;
126127
}

subsys/secure_storage/src/its/store/zms.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ psa_status_t secure_storage_its_store_remove(secure_storage_its_uid_t uid)
117117

118118
zms_ret = zms_delete(&s_zms, zms_id);
119119
LOG_DBG("%s 0x%x. (%d)", zms_ret ? "Failed to delete" : "Deleted", zms_id, zms_ret);
120+
120121
BUILD_ASSERT(PSA_SUCCESS == 0);
121122
return zms_ret;
122123
}

subsys/secure_storage/src/its/transform/aead.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static psa_status_t psa_aead_crypt(psa_key_usage_t operation, secure_storage_its
3131
psa_set_key_lifetime(&key_attributes, PSA_KEY_LIFETIME_VOLATILE);
3232
psa_set_key_type(&key_attributes, key_type);
3333
psa_set_key_algorithm(&key_attributes, alg);
34-
psa_set_key_bits(&key_attributes, sizeof(key) * 8);
34+
psa_set_key_bits(&key_attributes, PSA_BYTES_TO_BITS(sizeof(key)));
3535

3636
/* Avoid calling psa_aead_*crypt() because that would require importing keys into
3737
* PSA Crypto. This gets called from PSA Crypto for storing persistent keys so,
@@ -113,7 +113,7 @@ psa_status_t secure_storage_its_transform_from_store(
113113
psa_storage_create_flags_t *create_flags)
114114
{
115115
if (stored_data_len < STORED_ENTRY_LEN(0)) {
116-
return PSA_ERROR_STORAGE_FAILURE;
116+
return PSA_ERROR_DATA_CORRUPT;
117117
}
118118

119119
psa_status_t ret;

subsys/secure_storage/src/its/transform/aead_get.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ psa_status_t secure_storage_its_transform_aead_get_key(
7575
if (hwinfo_ret != 0) {
7676
hwinfo_ret = hwinfo_get_device_id(data.device_id, sizeof(data.device_id));
7777
if (hwinfo_ret <= 0) {
78-
return PSA_ERROR_HARDWARE_FAILURE;
78+
if (hwinfo_ret == PSA_SUCCESS) {
79+
hwinfo_ret ^= 1;
80+
}
81+
return hwinfo_ret;
7982
}
8083
if (hwinfo_ret < sizeof(data.device_id)) {
8184
memset(data.device_id + hwinfo_ret, 0, sizeof(data.device_id) - hwinfo_ret);

0 commit comments

Comments
 (0)