If the initialization is repeated, exist error code is returned and the original init check is deleted.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- include/wd_alg_common.h | 1 - wd_aead.c | 4 ++-- wd_cipher.c | 4 ++-- wd_comp.c | 4 ++-- wd_dh.c | 4 ++-- wd_digest.c | 4 ++-- wd_ecc.c | 4 ++-- wd_rsa.c | 4 ++-- wd_util.c | 12 +++--------- 9 files changed, 17 insertions(+), 24 deletions(-)
diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h index 31208ad..5d8e863 100644 --- a/include/wd_alg_common.h +++ b/include/wd_alg_common.h @@ -107,7 +107,6 @@ struct wd_ctx_config_internal { __u32 ctx_num; struct wd_ctx_internal *ctxs; void *priv; - int pid; bool epoll_en; unsigned long *msg_cnt; }; diff --git a/wd_aead.c b/wd_aead.c index cd1a82b..a14234a 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -469,7 +469,7 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
flag = wd_alg_try_init(&wd_aead_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
ret = wd_init_param_check(config, sched); if (ret) @@ -540,7 +540,7 @@ int wd_aead_init2_(char *alg, __u32 sched_type, int task_type,
flag = wd_alg_try_init(&wd_aead_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
if (!alg || sched_type >= SCHED_POLICY_BUTT || task_type < 0 || task_type >= TASK_MAX_TYPE) { diff --git a/wd_cipher.c b/wd_cipher.c index 6a1662a..a8ebeea 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -347,7 +347,7 @@ int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched)
flag = wd_alg_try_init(&wd_cipher_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
ret = wd_init_param_check(config, sched); if (ret) @@ -391,7 +391,7 @@ int wd_cipher_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_p
flag = wd_alg_try_init(&wd_cipher_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { diff --git a/wd_comp.c b/wd_comp.c index 4a22a80..2239e33 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -169,7 +169,7 @@ int wd_comp_init(struct wd_ctx_config *config, struct wd_sched *sched)
flag = wd_alg_try_init(&wd_comp_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
ret = wd_init_param_check(config, sched); if (ret) @@ -213,7 +213,7 @@ int wd_comp_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_par
flag = wd_alg_try_init(&wd_comp_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { diff --git a/wd_dh.c b/wd_dh.c index 4b6a75d..7feb7ee 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -161,7 +161,7 @@ int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
flag = wd_alg_try_init(&wd_dh_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
ret = wd_init_param_check(config, sched); if (ret) @@ -204,7 +204,7 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param
flag = wd_alg_try_init(&wd_dh_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { WD_ERR("invalid: input param is wrong!\n"); diff --git a/wd_digest.c b/wd_digest.c index c3aface..df9f656 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -282,7 +282,7 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched)
flag = wd_alg_try_init(&wd_digest_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
ret = wd_init_param_check(config, sched); if (ret) @@ -349,7 +349,7 @@ int wd_digest_init2_(char *alg, __u32 sched_type, int task_type,
flag = wd_alg_try_init(&wd_digest_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
if (!alg || sched_type >= SCHED_POLICY_BUTT || task_type < 0 || task_type >= TASK_MAX_TYPE) { diff --git a/wd_ecc.c b/wd_ecc.c index 2dc8557..da717a8 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -217,7 +217,7 @@ int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched)
flag = wd_alg_try_init(&wd_ecc_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
ret = wd_init_param_check(config, sched); if (ret) @@ -260,7 +260,7 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para
flag = wd_alg_try_init(&wd_ecc_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { WD_ERR("invalid: input param is wrong!\n"); diff --git a/wd_rsa.c b/wd_rsa.c index 7e71a17..60c2836 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -202,7 +202,7 @@ int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched)
flag = wd_alg_try_init(&wd_rsa_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
ret = wd_init_param_check(config, sched); if (ret) @@ -245,7 +245,7 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para
flag = wd_alg_try_init(&wd_rsa_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { WD_ERR("invalid: input param is wrong!\n"); diff --git a/wd_util.c b/wd_util.c index db42fa3..465d958 100644 --- a/wd_util.c +++ b/wd_util.c @@ -229,12 +229,6 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in, return -WD_EINVAL; }
- /* ctx could only be invoked once for one process. */ - if (in->ctx_num && in->pid == getpid()) { - WD_ERR("ctx have initialized.\n"); - return -WD_EEXIST; - } - in->msg_cnt = wd_shared_create(WD_CTX_CNT_NUM); if (!in->msg_cnt && need_info) return -WD_EINVAL; @@ -262,7 +256,6 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in, }
in->ctxs = ctxs; - in->pid = getpid(); in->priv = cfg->priv; in->ctx_num = cfg->ctx_num;
@@ -316,7 +309,6 @@ void wd_clear_ctx_config(struct wd_ctx_config_internal *in)
in->priv = NULL; in->ctx_num = 0; - in->pid = 0; if (in->ctxs) { free(in->ctxs); in->ctxs = NULL; @@ -2326,8 +2318,10 @@ bool wd_alg_try_init(enum wd_status *status) expected = WD_UNINIT; ret = __atomic_compare_exchange_n(status, &expected, WD_INITING, true, __ATOMIC_RELAXED, __ATOMIC_RELAXED); - if (expected == WD_INIT) + if (expected == WD_INIT) { + WD_ERR("The algorithm has been initialized!\n"); return false; + } usleep(WD_INIT_SLEEP_UTIME); if (!(++count % WD_INIT_RETRY_TIMES)) WD_ERR("The algorithm initizalite has been waiting for %ds!\n",