diff options
author | Rob Austein <sra@hactrn.net> | 2017-04-30 10:21:09 -0400 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2017-04-30 10:21:09 -0400 |
commit | a76a684fbd33c2b90a33e9c12e7536149630d6b5 (patch) | |
tree | edb512556900a5a6680dd946050e60c0ea8e1128 /rpc_pkey.c | |
parent | 18c297c5f88681236aec2537f7e7f2d9b50fcd7e (diff) | |
parent | 018b238e7aac5b4a990a28f49323b821246c9f66 (diff) |
Merge branch 'ksng' into no-rtos
Diffstat (limited to 'rpc_pkey.c')
-rw-r--r-- | rpc_pkey.c | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -93,6 +93,21 @@ static inline hal_pkey_slot_t *alloc_slot(const hal_key_flags_t flags) } /* + * Clear a slot. Probably not necessary to do this in a critical + * section, but be safe. + */ + +static inline void clear_slot(hal_pkey_slot_t *slot) +{ + hal_critical_section_start(); + + if (slot != NULL) + memset(slot, 0, sizeof(*slot)); + + hal_critical_section_end(); +} + +/* * Check a caller-supplied handle. Must be in range, in use, and have * the right glop. Returns slot pointer on success, NULL otherwise. */ @@ -395,7 +410,7 @@ static hal_error_t pkey_local_open(const hal_client_handle_t client, return HAL_OK; fail: - memset(slot, 0, sizeof(*slot)); + clear_slot(slot); return err; } @@ -537,7 +552,7 @@ static hal_error_t pkey_local_close(const hal_pkey_handle_t pkey) if ((slot = find_handle(pkey)) == NULL) return HAL_ERROR_KEY_NOT_FOUND; - memset(slot, 0, sizeof(*slot)); + clear_slot(slot); return HAL_OK; } @@ -566,7 +581,7 @@ static hal_error_t pkey_local_delete(const hal_pkey_handle_t pkey) (void) hal_ks_close(ks); if (err == HAL_OK || err == HAL_ERROR_KEY_NOT_FOUND) - memset(slot, 0, sizeof(*slot)); + clear_slot(slot); return err; } |