Skip to content

Commit d38fb88

Browse files
tomi-fonthenrikbrixandersen
authored andcommitted
secure_storage: its: improve return codes
Instead of returning storage-related error codes, return ones which make it clear that it's not about the storage itself. Signed-off-by: Tomi Fontanilles <[email protected]>
1 parent 2cad6fa commit d38fb88

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

subsys/secure_storage/include/psa/internal_trusted_storage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* @param create_flags Flags indicating the properties of the entry.
3535
*
3636
* @retval PSA_SUCCESS The operation completed successfully.
37+
* @retval PSA_ERROR_GENERIC_ERROR An unspecified internal failure happened.
3738
* @retval PSA_ERROR_NOT_PERMITTED An entry associated with the provided `uid` already
3839
* exists and was created with `PSA_STORAGE_FLAG_WRITE_ONCE`.
3940
* @retval PSA_ERROR_NOT_SUPPORTED One or more of the flags provided in `create_flags`
@@ -63,6 +64,7 @@ psa_status_t psa_its_set(psa_storage_uid_t uid, size_t data_length,
6364
* @param[out] p_data_length On success, the number of bytes placed in `p_data`.
6465
*
6566
* @retval PSA_SUCCESS The operation completed successfully.
67+
* @retval PSA_ERROR_GENERIC_ERROR An unspecified internal failure happened.
6668
* @retval PSA_ERROR_INVALID_ARGUMENT One or more of the arguments are invalid. This can also
6769
* happen if `data_offset` is larger than the size of the data
6870
* associated with `uid`.
@@ -87,6 +89,7 @@ psa_status_t psa_its_get(psa_storage_uid_t uid, size_t data_offset,
8789
* be populated with the metadata on success.
8890
*
8991
* @retval PSA_SUCCESS The operation completed successfully.
92+
* @retval PSA_ERROR_GENERIC_ERROR An unspecified internal failure happened.
9093
* @retval PSA_ERROR_INVALID_ARGUMENT One or more of the arguments are invalid.
9194
* @retval PSA_ERROR_DOES_NOT_EXIST The provided `uid` was not found in the storage.
9295
* @retval PSA_ERROR_STORAGE_FAILURE The physical storage has failed (fatal error).

subsys/secure_storage/src/its/implementation.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ static psa_status_t get_stored_data(
5656
if (ret != PSA_ERROR_DOES_NOT_EXIST) {
5757
log_failed_operation("retrieve", "from", ret);
5858
}
59-
return ret;
6059
}
61-
return PSA_SUCCESS;
60+
return ret;
6261
}
6362

6463
static psa_status_t transform_stored_data(
@@ -73,7 +72,7 @@ static psa_status_t transform_stored_data(
7372
data_size, data, data_len, create_flags);
7473
if (ret != PSA_SUCCESS) {
7574
log_failed_operation("transform", "from", ret);
76-
return PSA_ERROR_STORAGE_FAILURE;
75+
return PSA_ERROR_GENERIC_ERROR;
7776
}
7877
return PSA_SUCCESS;
7978
}
@@ -141,7 +140,7 @@ static psa_status_t store_entry(secure_storage_its_uid_t uid, size_t data_length
141140
stored_data, &stored_data_len);
142141
if (ret != PSA_SUCCESS) {
143142
log_failed_operation("transform", "for", ret);
144-
return PSA_ERROR_STORAGE_FAILURE;
143+
return PSA_ERROR_GENERIC_ERROR;
145144
}
146145

147146
ret = secure_storage_its_store_set(uid, stored_data_len, stored_data);
@@ -167,7 +166,7 @@ psa_status_t secure_storage_its_set(secure_storage_its_caller_id_t caller_id, ps
167166
if (data_length > CONFIG_SECURE_STORAGE_ITS_MAX_DATA_SIZE) {
168167
LOG_DBG("Passed data length (%zu) exceeds maximum allowed (%u).",
169168
data_length, CONFIG_SECURE_STORAGE_ITS_MAX_DATA_SIZE);
170-
return PSA_ERROR_INSUFFICIENT_STORAGE;
169+
return PSA_ERROR_INVALID_ARGUMENT;
171170
}
172171

173172
if (keep_stored_entry(its_uid, data_length, p_data, create_flags, &ret)) {
@@ -258,7 +257,9 @@ psa_status_t secure_storage_its_remove(secure_storage_its_caller_id_t caller_id,
258257
return PSA_ERROR_NOT_PERMITTED;
259258
}
260259
/* Allow overwriting corrupted entries as well to not be stuck with them forever. */
261-
if (ret == PSA_SUCCESS || ret == PSA_ERROR_STORAGE_FAILURE) {
260+
if (ret == PSA_SUCCESS ||
261+
ret == PSA_ERROR_STORAGE_FAILURE ||
262+
ret == PSA_ERROR_GENERIC_ERROR) {
262263
ret = secure_storage_its_store_remove(its_uid);
263264
if (ret != PSA_SUCCESS) {
264265
log_failed_operation("remove", "from", ret);

0 commit comments

Comments
 (0)