Misc fixes for hpre driver and asymmetric algorithm API.
Qi Tao (1): uadk/rsa: use %u to print u32 variables
Weili Qian (8): drv/hpre: fix ECC operation type drv/hisi_sec: enable address prefetching drv/hpre: rename hpre_alg_driver to hpre_ecc_driver uadk: add algorithm check uadk: modify parameter check conditions uadk: fix repeat uninit error uadk: fix coding style uadk: remove duplicate checks
drv/hisi_hpre.c | 26 +++++----- drv/hisi_sec.c | 6 +++ wd_dh.c | 108 ++++++++++++++++++++++------------------ wd_ecc.c | 130 ++++++++++++++++++++++++++---------------------- wd_rsa.c | 116 ++++++++++++++++++++++-------------------- 5 files changed, 212 insertions(+), 174 deletions(-)
The ECC operation type is 'HPRE_HW_V3_ECC_ALG_TYPE' instead of 'HPRE_HW_V2_ALG_TYPE'. fix it.
Signed-off-by: Weili Qian qianweili@huawei.com --- drv/hisi_hpre.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index 7bf55a1..1f5d4bc 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -529,7 +529,7 @@ static int hpre_ecc_init(void *conf, void *priv) return -WD_EINVAL; }
- qm_priv.op_type = HPRE_HW_V2_ALG_TYPE; + qm_priv.op_type = HPRE_HW_V3_ECC_ALG_TYPE; ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv); if (ret) return ret;
Enable address prefetching for BD3, after BD is sent to the hardware, the accelerator hardware can translate the address in advance.
Signed-off-by: Weili Qian qianweili@huawei.com --- drv/hisi_sec.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index 19d524a..89d113d 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -46,6 +46,8 @@ #define SEC_AKEY_OFFSET_V3 9 #define SEC_MAC_OFFSET_V3 4 #define SEC_AUTH_ALG_OFFSET_V3 15 +#define SEC_SVA_PREFETCH_OFFSET 27 +#define SEC_ENABLE_SVA_PREFETCH 0x1 #define SEC_CIPHER_AUTH_V3 0xbf #define SEC_AUTH_CIPHER_V3 0x40 #define SEC_AI_GEN_OFFSET_V3 2 @@ -1283,6 +1285,8 @@ static int fill_cipher_bd3(struct wd_cipher_msg *msg, struct hisi_sec_sqe3 *sqe) return ret; }
+ sqe->auth_mac_key |= (__u32)SEC_ENABLE_SVA_PREFETCH << SEC_SVA_PREFETCH_OFFSET; + return 0; }
@@ -1934,6 +1938,7 @@ int hisi_sec_digest_send_v3(handle_t ctx, void *digest_msg)
hisi_set_msg_id(h_qp, &msg->tag); sqe.tag = (__u64)(uintptr_t)msg->tag; + sqe.auth_mac_key |= (__u32)SEC_ENABLE_SVA_PREFETCH << SEC_SVA_PREFETCH_OFFSET;
ret = hisi_qm_send(h_qp, &sqe, 1, &count); if (ret < 0) { @@ -2828,6 +2833,7 @@ static int fill_aead_bd3(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe) sqe->c_len_ivin = msg->in_bytes; sqe->cipher_src_offset = msg->assoc_bytes; sqe->a_len_key = msg->in_bytes + msg->assoc_bytes; + sqe->auth_mac_key |= (__u32)SEC_ENABLE_SVA_PREFETCH << SEC_SVA_PREFETCH_OFFSET;
ret = fill_aead_bd3_alg(msg, sqe); if (ret) {
The name of 'hpre_alg_driver' is changed to 'hpre_ecc_driver' because it is used only by the ECC algorithm.
Signed-off-by: Weili Qian qianweili@huawei.com --- drv/hisi_hpre.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index 1f5d4bc..b9be464 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -2438,7 +2438,7 @@ static int ecc_recv(handle_t ctx, void *ecc_msg) return ecc_sqe_parse((struct hisi_qp *)h_qp, msg, &hw_msg); }
-#define GEN_HPRE_ALG_DRIVER(hpre_alg_name) \ +#define GEN_HPRE_ECC_DRIVER(hpre_alg_name) \ {\ .drv_name = "hisi_hpre",\ .alg_name = hpre_alg_name,\ @@ -2453,12 +2453,12 @@ static int ecc_recv(handle_t ctx, void *ecc_msg) .recv = ecc_recv,\ }
-static struct wd_alg_driver hpre_alg_driver[] = { - GEN_HPRE_ALG_DRIVER("sm2"), - GEN_HPRE_ALG_DRIVER("ecdh"), - GEN_HPRE_ALG_DRIVER("ecdsa"), - GEN_HPRE_ALG_DRIVER("x25519"), - GEN_HPRE_ALG_DRIVER("x448"), +static struct wd_alg_driver hpre_ecc_driver[] = { + GEN_HPRE_ECC_DRIVER("sm2"), + GEN_HPRE_ECC_DRIVER("ecdh"), + GEN_HPRE_ECC_DRIVER("ecdsa"), + GEN_HPRE_ECC_DRIVER("x25519"), + GEN_HPRE_ECC_DRIVER("x448"), };
static struct wd_alg_driver hpre_rsa_driver = { @@ -2490,7 +2490,7 @@ static struct wd_alg_driver hpre_dh_driver = { }; static void __attribute__((constructor)) hisi_hpre_probe(void) { - int alg_num = ARRAY_SIZE(hpre_alg_driver); + int alg_num = ARRAY_SIZE(hpre_ecc_driver); int i, ret;
WD_INFO("Info: register HPRE alg drivers!\n"); @@ -2504,19 +2504,19 @@ static void __attribute__((constructor)) hisi_hpre_probe(void) WD_ERR("failed to register HPRE dh driver!\n");
for (i = 0; i < alg_num; i++) { - ret = wd_alg_driver_register(&hpre_alg_driver[i]); + ret = wd_alg_driver_register(&hpre_ecc_driver[i]); if (ret) - WD_ERR("failed to register HPRE %s driver!\n", hpre_alg_driver[i].alg_name); + WD_ERR("failed to register HPRE %s driver!\n", hpre_ecc_driver[i].alg_name); } }
static void __attribute__((destructor)) hisi_hpre_remove(void) { - int alg_num = ARRAY_SIZE(hpre_alg_driver); + int alg_num = ARRAY_SIZE(hpre_ecc_driver); int i;
for (i = 0; i < alg_num; i++) - wd_alg_driver_unregister(&hpre_alg_driver[i]); + wd_alg_driver_unregister(&hpre_ecc_driver[i]);
wd_alg_driver_unregister(&hpre_dh_driver); wd_alg_driver_unregister(&hpre_rsa_driver);
When users initialize algorithm resources, the input alg_name needs to be checked. If algorithm is not supported, return error.
Signed-off-by: Weili Qian qianweili@huawei.com --- wd_dh.c | 9 ++++++--- wd_ecc.c | 30 +++++++++++++++++------------- wd_rsa.c | 9 ++++++--- 3 files changed, 29 insertions(+), 19 deletions(-)
diff --git a/wd_dh.c b/wd_dh.c index 203d3e0..5a79c6d 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -197,8 +197,8 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param { struct wd_ctx_nums dh_ctx_num[WD_DH_PHASE2] = {0}; struct wd_ctx_params dh_ctx_params = {0}; + int ret = -WD_EINVAL; bool flag; - int ret;
pthread_atfork(NULL, NULL, wd_dh_clear_status);
@@ -208,7 +208,11 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param
if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { WD_ERR("invalid: input param is wrong!\n"); - ret = -WD_EINVAL; + goto out_clear_init; + } + + if (strcmp(alg, "dh")) { + WD_ERR("invalid: the alg %s not support!\n", alg); goto out_clear_init; }
@@ -220,7 +224,6 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param wd_dh_setting.dlh_list = wd_dlopen_drv(NULL); if (!wd_dh_setting.dlh_list) { WD_ERR("failed to open driver lib files!\n"); - ret = -WD_EINVAL; goto out_clear_init; }
diff --git a/wd_ecc.c b/wd_ecc.c index 695c61d..c539ce3 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -145,6 +145,16 @@ static int wd_ecc_open_driver(void) return 0; }
+static bool is_alg_support(const char *alg) +{ + if (unlikely(strcmp(alg, "ecdh") && strcmp(alg, "ecdsa") && + strcmp(alg, "x25519") && strcmp(alg, "x448") && + strcmp(alg, "sm2"))) + return false; + + return true; +} + static void wd_ecc_clear_status(void) { wd_alg_clear_init(&wd_ecc_setting.status); @@ -253,8 +263,8 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para { struct wd_ctx_nums ecc_ctx_num[WD_EC_OP_MAX] = {0}; struct wd_ctx_params ecc_ctx_params = {0}; + int ret = -WD_EINVAL; bool flag; - int ret;
pthread_atfork(NULL, NULL, wd_ecc_clear_status);
@@ -264,7 +274,12 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para
if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { WD_ERR("invalid: input param is wrong!\n"); - ret = -WD_EINVAL; + goto out_clear_init; + } + + flag = is_alg_support(alg); + if (!flag) { + WD_ERR("invalid: alg %s not support!\n", alg); goto out_clear_init; }
@@ -276,7 +291,6 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para wd_ecc_setting.dlh_list = wd_dlopen_drv(NULL); if (!wd_ecc_setting.dlh_list) { WD_ERR("failed to open driver lib files!\n"); - ret = -WD_EINVAL; goto out_clear_init; }
@@ -1079,16 +1093,6 @@ static bool is_key_width_support(__u32 key_bits) return true; }
-static bool is_alg_support(const char *alg) -{ - if (unlikely(strcmp(alg, "ecdh") && strcmp(alg, "ecdsa") && - strcmp(alg, "x25519") && strcmp(alg, "x448") && - strcmp(alg, "sm2"))) - return false; - - return true; -} - static int setup_param_check(struct wd_ecc_sess_setup *setup) { if (unlikely(!setup || !setup->alg)) { diff --git a/wd_rsa.c b/wd_rsa.c index 58b1229..0b0be1c 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -238,8 +238,8 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para { struct wd_ctx_nums rsa_ctx_num[WD_RSA_GENKEY] = {0}; struct wd_ctx_params rsa_ctx_params = {0}; + int ret = -WD_EINVAL; bool flag; - int ret;
pthread_atfork(NULL, NULL, wd_rsa_clear_status);
@@ -249,7 +249,11 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para
if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { WD_ERR("invalid: input param is wrong!\n"); - ret = -WD_EINVAL; + goto out_clear_init; + } + + if (strcmp(alg, "rsa")) { + WD_ERR("invalid: the alg %s not support!\n", alg); goto out_clear_init; }
@@ -261,7 +265,6 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para wd_rsa_setting.dlh_list = wd_dlopen_drv(NULL); if (!wd_rsa_setting.dlh_list) { WD_ERR("failed to open driver lib files!\n"); - ret = -WD_EINVAL; goto out_clear_init; }
When user calls wd_<alg>_init2, if the input parameter sched_type is 'SCHED_POLICY_BUTT' or task_type is 'TASK_MAX_TYPE', the parameter is not supported, In this case, an error must be returned.
Signed-off-by: Weili Qian qianweili@huawei.com --- wd_dh.c | 3 ++- wd_ecc.c | 3 ++- wd_rsa.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/wd_dh.c b/wd_dh.c index 5a79c6d..cb90093 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -206,7 +206,8 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param if (!flag) return -WD_EEXIST;
- if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { + if (!alg || sched_type >= SCHED_POLICY_BUTT || + task_type < 0 || task_type >= TASK_MAX_TYPE) { WD_ERR("invalid: input param is wrong!\n"); goto out_clear_init; } diff --git a/wd_ecc.c b/wd_ecc.c index c539ce3..3e90e95 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -272,7 +272,8 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para if (!flag) return -WD_EEXIST;
- if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { + if (!alg || sched_type >= SCHED_POLICY_BUTT || + task_type < 0 || task_type >= TASK_MAX_TYPE) { WD_ERR("invalid: input param is wrong!\n"); goto out_clear_init; } diff --git a/wd_rsa.c b/wd_rsa.c index 0b0be1c..b72ae23 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -247,7 +247,8 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para if (!flag) return -WD_EEXIST;
- if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { + if (!alg || sched_type >= SCHED_POLICY_BUTT || + task_type < 0 || task_type >= TASK_MAX_TYPE) { WD_ERR("invalid: input param is wrong!\n"); goto out_clear_init; }
To avoid repeated free resource, wd_<alg>_common_uninit checks whether the 'priv' pointer exists. However, wd_<alg>_common_uninit does not return a value to the invoking function. As a result, the calling function continues to release resources.
Signed-off-by: Weili Qian qianweili@huawei.com --- wd_dh.c | 20 ++++++++++++++++---- wd_ecc.c | 20 ++++++++++++++++---- wd_rsa.c | 20 ++++++++++++++++---- 3 files changed, 48 insertions(+), 12 deletions(-)
diff --git a/wd_dh.c b/wd_dh.c index cb90093..546fb90 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -135,11 +135,11 @@ out_clear_ctx_config: return ret; }
-static void wd_dh_common_uninit(void) +static int wd_dh_common_uninit(void) { if (!wd_dh_setting.priv) { WD_ERR("invalid: repeat uninit dh!\n"); - return; + return -WD_EINVAL; }
/* uninit async request pool */ @@ -150,6 +150,8 @@ static void wd_dh_common_uninit(void) wd_alg_uninit_driver(&wd_dh_setting.config, wd_dh_setting.driver, &wd_dh_setting.priv); + + return 0; }
int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched) @@ -188,7 +190,12 @@ out_clear_init:
void wd_dh_uninit(void) { - wd_dh_common_uninit(); + int ret; + + ret = wd_dh_common_uninit(); + if (ret) + return; + wd_dh_close_driver(); wd_alg_clear_init(&wd_dh_setting.status); } @@ -287,7 +294,12 @@ out_clear_init:
void wd_dh_uninit2(void) { - wd_dh_common_uninit(); + int ret; + + ret = wd_dh_common_uninit(); + if (ret) + return; + wd_alg_attrs_uninit(&wd_dh_init_attrs); wd_alg_drv_unbind(wd_dh_setting.driver); wd_dlclose_drv(wd_dh_setting.dlh_list); diff --git a/wd_ecc.c b/wd_ecc.c index 3e90e95..0a9ebe0 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -201,11 +201,11 @@ out_clear_ctx_config: return ret; }
-static void wd_ecc_common_uninit(void) +static int wd_ecc_common_uninit(void) { if (!wd_ecc_setting.priv) { WD_ERR("invalid: repeat uninit ecc!\n"); - return; + return -WD_EINVAL; }
/* uninit async request pool */ @@ -216,6 +216,8 @@ static void wd_ecc_common_uninit(void) wd_alg_uninit_driver(&wd_ecc_setting.config, wd_ecc_setting.driver, &wd_ecc_setting.priv); + + return 0; }
int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched) @@ -254,7 +256,12 @@ out_clear_init:
void wd_ecc_uninit(void) { - wd_ecc_common_uninit(); + int ret; + + ret = wd_ecc_common_uninit(); + if (ret) + return; + wd_ecc_close_driver(); wd_alg_clear_init(&wd_ecc_setting.status); } @@ -353,7 +360,12 @@ out_clear_init:
void wd_ecc_uninit2(void) { - wd_ecc_common_uninit(); + int ret; + + ret = wd_ecc_common_uninit(); + if (ret) + return; + wd_alg_attrs_uninit(&wd_ecc_init_attrs); wd_alg_drv_unbind(wd_ecc_setting.driver); wd_dlclose_drv(wd_ecc_setting.dlh_list); diff --git a/wd_rsa.c b/wd_rsa.c index b72ae23..382e831 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -176,11 +176,11 @@ out_clear_ctx_config: return ret; }
-static void wd_rsa_common_uninit(void) +static int wd_rsa_common_uninit(void) { if (!wd_rsa_setting.priv) { WD_ERR("invalid: repeat uninit rsa!\n"); - return; + return -WD_EINVAL; }
/* uninit async request pool */ @@ -191,6 +191,8 @@ static void wd_rsa_common_uninit(void) wd_alg_uninit_driver(&wd_rsa_setting.config, wd_rsa_setting.driver, &wd_rsa_setting.priv); + + return 0; }
int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched) @@ -229,7 +231,12 @@ out_clear_init:
void wd_rsa_uninit(void) { - wd_rsa_common_uninit(); + int ret; + + ret = wd_rsa_common_uninit(); + if (ret) + return; + wd_rsa_close_driver(); wd_alg_clear_init(&wd_rsa_setting.status); } @@ -328,7 +335,12 @@ out_clear_init:
void wd_rsa_uninit2(void) { - wd_rsa_common_uninit(); + int ret; + + ret = wd_rsa_common_uninit(); + if (ret) + return; + wd_alg_attrs_uninit(&wd_rsa_init_attrs); wd_alg_drv_unbind(wd_rsa_setting.driver); wd_dlclose_drv(wd_rsa_setting.dlh_list);
Keep the coding style consistent.
Signed-off-by: Weili Qian qianweili@huawei.com --- wd_dh.c | 71 ++++++++++++++++++++++++++++--------------------------- wd_ecc.c | 72 +++++++++++++++++++++++++++++--------------------------- wd_rsa.c | 71 ++++++++++++++++++++++++++++--------------------------- 3 files changed, 109 insertions(+), 105 deletions(-)
diff --git a/wd_dh.c b/wd_dh.c index 546fb90..df5d90e 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -235,45 +235,46 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param goto out_clear_init; }
-res_retry: - memset(&wd_dh_setting.config, 0, sizeof(struct wd_ctx_config_internal)); - - /* Get alg driver and dev name */ - wd_dh_setting.driver = wd_alg_drv_bind(task_type, alg); - if (!wd_dh_setting.driver) { - WD_ERR("fail to bind a valid driver.\n"); - ret = -WD_EINVAL; - goto out_dlopen; - } + while (ret) { + memset(&wd_dh_setting.config, 0, sizeof(struct wd_ctx_config_internal)); + + /* Get alg driver and dev name */ + wd_dh_setting.driver = wd_alg_drv_bind(task_type, alg); + if (!wd_dh_setting.driver) { + WD_ERR("fail to bind a valid driver.\n"); + ret = -WD_EINVAL; + goto out_dlopen; + }
- dh_ctx_params.ctx_set_num = dh_ctx_num; - ret = wd_ctx_param_init(&dh_ctx_params, ctx_params, - wd_dh_setting.driver, WD_DH_TYPE, WD_DH_PHASE2); - if (ret) { - if (ret == -WD_EAGAIN) { - wd_disable_drv(wd_dh_setting.driver); - wd_alg_drv_unbind(wd_dh_setting.driver); - goto res_retry; + dh_ctx_params.ctx_set_num = dh_ctx_num; + ret = wd_ctx_param_init(&dh_ctx_params, ctx_params, + wd_dh_setting.driver, WD_DH_TYPE, WD_DH_PHASE2); + if (ret) { + if (ret == -WD_EAGAIN) { + wd_disable_drv(wd_dh_setting.driver); + wd_alg_drv_unbind(wd_dh_setting.driver); + continue; + } + goto out_driver; } - goto out_driver; - }
- wd_dh_init_attrs.alg = alg; - wd_dh_init_attrs.sched_type = sched_type; - wd_dh_init_attrs.driver = wd_dh_setting.driver; - wd_dh_init_attrs.ctx_params = &dh_ctx_params; - wd_dh_init_attrs.alg_init = wd_dh_common_init; - wd_dh_init_attrs.alg_poll_ctx = wd_dh_poll_ctx; - ret = wd_alg_attrs_init(&wd_dh_init_attrs); - if (ret) { - if (ret == -WD_ENODEV) { - wd_disable_drv(wd_dh_setting.driver); - wd_alg_drv_unbind(wd_dh_setting.driver); - wd_ctx_param_uninit(&dh_ctx_params); - goto res_retry; + wd_dh_init_attrs.alg = alg; + wd_dh_init_attrs.sched_type = sched_type; + wd_dh_init_attrs.driver = wd_dh_setting.driver; + wd_dh_init_attrs.ctx_params = &dh_ctx_params; + wd_dh_init_attrs.alg_init = wd_dh_common_init; + wd_dh_init_attrs.alg_poll_ctx = wd_dh_poll_ctx; + ret = wd_alg_attrs_init(&wd_dh_init_attrs); + if (ret) { + if (ret == -WD_ENODEV) { + wd_disable_drv(wd_dh_setting.driver); + wd_alg_drv_unbind(wd_dh_setting.driver); + wd_ctx_param_uninit(&dh_ctx_params); + continue; + } + WD_ERR("failed to init alg attrs!\n"); + goto out_params_uninit; } - WD_ERR("failed to init alg attrs!\n"); - goto out_params_uninit; }
wd_alg_set_init(&wd_dh_setting.status); diff --git a/wd_ecc.c b/wd_ecc.c index 0a9ebe0..e401a46 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -302,51 +302,53 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para goto out_clear_init; }
-res_retry: - memset(&wd_ecc_setting.config, 0, sizeof(struct wd_ctx_config_internal)); - - /* Get alg driver and dev name */ - wd_ecc_setting.driver = wd_alg_drv_bind(task_type, alg); - if (!wd_ecc_setting.driver) { - WD_ERR("failed to bind a valid driver!\n"); - ret = -WD_EINVAL; - goto out_dlopen; - } + while (ret) { + memset(&wd_ecc_setting.config, 0, sizeof(struct wd_ctx_config_internal)); + + /* Get alg driver and dev name */ + wd_ecc_setting.driver = wd_alg_drv_bind(task_type, alg); + if (!wd_ecc_setting.driver) { + WD_ERR("failed to bind a valid driver!\n"); + ret = -WD_EINVAL; + goto out_dlopen; + }
- ecc_ctx_params.ctx_set_num = ecc_ctx_num; - ret = wd_ctx_param_init(&ecc_ctx_params, ctx_params, - wd_ecc_setting.driver, WD_ECC_TYPE, WD_EC_OP_MAX); - if (ret) { - if (ret == -WD_EAGAIN) { - wd_disable_drv(wd_ecc_setting.driver); - wd_alg_drv_unbind(wd_ecc_setting.driver); - goto res_retry; + ecc_ctx_params.ctx_set_num = ecc_ctx_num; + ret = wd_ctx_param_init(&ecc_ctx_params, ctx_params, + wd_ecc_setting.driver, WD_ECC_TYPE, WD_EC_OP_MAX); + if (ret) { + if (ret == -WD_EAGAIN) { + wd_disable_drv(wd_ecc_setting.driver); + wd_alg_drv_unbind(wd_ecc_setting.driver); + continue; + } + goto out_driver; } - goto out_driver; - }
- wd_ecc_init_attrs.alg = alg; - wd_ecc_init_attrs.sched_type = sched_type; - wd_ecc_init_attrs.driver = wd_ecc_setting.driver; - wd_ecc_init_attrs.ctx_params = &ecc_ctx_params; - wd_ecc_init_attrs.alg_init = wd_ecc_common_init; - wd_ecc_init_attrs.alg_poll_ctx = wd_ecc_poll_ctx; - ret = wd_alg_attrs_init(&wd_ecc_init_attrs); - if (ret) { - if (ret == -WD_ENODEV) { - wd_disable_drv(wd_ecc_setting.driver); - wd_alg_drv_unbind(wd_ecc_setting.driver); - wd_ctx_param_uninit(&ecc_ctx_params); - goto res_retry; + wd_ecc_init_attrs.alg = alg; + wd_ecc_init_attrs.sched_type = sched_type; + wd_ecc_init_attrs.driver = wd_ecc_setting.driver; + wd_ecc_init_attrs.ctx_params = &ecc_ctx_params; + wd_ecc_init_attrs.alg_init = wd_ecc_common_init; + wd_ecc_init_attrs.alg_poll_ctx = wd_ecc_poll_ctx; + ret = wd_alg_attrs_init(&wd_ecc_init_attrs); + if (ret) { + if (ret == -WD_ENODEV) { + wd_disable_drv(wd_ecc_setting.driver); + wd_alg_drv_unbind(wd_ecc_setting.driver); + wd_ctx_param_uninit(&ecc_ctx_params); + continue; + } + WD_ERR("failed to init alg attrs!\n"); + goto out_params_uninit; } - WD_ERR("failed to init alg attrs!\n"); - goto out_params_uninit; }
wd_alg_set_init(&wd_ecc_setting.status); wd_ctx_param_uninit(&ecc_ctx_params);
return 0; + out_params_uninit: wd_ctx_param_uninit(&ecc_ctx_params); out_driver: diff --git a/wd_rsa.c b/wd_rsa.c index 382e831..ba2e088 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -276,45 +276,46 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para goto out_clear_init; }
-res_retry: - memset(&wd_rsa_setting.config, 0, sizeof(struct wd_ctx_config_internal)); - - /* Get alg driver and dev name */ - wd_rsa_setting.driver = wd_alg_drv_bind(task_type, alg); - if (!wd_rsa_setting.driver) { - WD_ERR("failed to bind a valid driver!\n"); - ret = -WD_EINVAL; - goto out_dlopen; - } + while (ret) { + memset(&wd_rsa_setting.config, 0, sizeof(struct wd_ctx_config_internal)); + + /* Get alg driver and dev name */ + wd_rsa_setting.driver = wd_alg_drv_bind(task_type, alg); + if (!wd_rsa_setting.driver) { + WD_ERR("failed to bind a valid driver!\n"); + ret = -WD_EINVAL; + goto out_dlopen; + }
- rsa_ctx_params.ctx_set_num = rsa_ctx_num; - ret = wd_ctx_param_init(&rsa_ctx_params, ctx_params, - wd_rsa_setting.driver, WD_RSA_TYPE, WD_RSA_GENKEY); - if (ret) { - if (ret == -WD_EAGAIN) { - wd_disable_drv(wd_rsa_setting.driver); - wd_alg_drv_unbind(wd_rsa_setting.driver); - goto res_retry; + rsa_ctx_params.ctx_set_num = rsa_ctx_num; + ret = wd_ctx_param_init(&rsa_ctx_params, ctx_params, + wd_rsa_setting.driver, WD_RSA_TYPE, WD_RSA_GENKEY); + if (ret) { + if (ret == -WD_EAGAIN) { + wd_disable_drv(wd_rsa_setting.driver); + wd_alg_drv_unbind(wd_rsa_setting.driver); + continue; + } + goto out_driver; } - goto out_driver; - }
- wd_rsa_init_attrs.alg = alg; - wd_rsa_init_attrs.sched_type = sched_type; - wd_rsa_init_attrs.driver = wd_rsa_setting.driver; - wd_rsa_init_attrs.ctx_params = &rsa_ctx_params; - wd_rsa_init_attrs.alg_init = wd_rsa_common_init; - wd_rsa_init_attrs.alg_poll_ctx = wd_rsa_poll_ctx; - ret = wd_alg_attrs_init(&wd_rsa_init_attrs); - if (ret) { - if (ret == -WD_ENODEV) { - wd_disable_drv(wd_rsa_setting.driver); - wd_alg_drv_unbind(wd_rsa_setting.driver); - wd_ctx_param_uninit(&rsa_ctx_params); - goto res_retry; + wd_rsa_init_attrs.alg = alg; + wd_rsa_init_attrs.sched_type = sched_type; + wd_rsa_init_attrs.driver = wd_rsa_setting.driver; + wd_rsa_init_attrs.ctx_params = &rsa_ctx_params; + wd_rsa_init_attrs.alg_init = wd_rsa_common_init; + wd_rsa_init_attrs.alg_poll_ctx = wd_rsa_poll_ctx; + ret = wd_alg_attrs_init(&wd_rsa_init_attrs); + if (ret) { + if (ret == -WD_ENODEV) { + wd_disable_drv(wd_rsa_setting.driver); + wd_alg_drv_unbind(wd_rsa_setting.driver); + wd_ctx_param_uninit(&rsa_ctx_params); + continue; + } + WD_ERR("failed to init alg attrs!\n"); + goto out_params_uninit; } - WD_ERR("failed to init alg attrs!\n"); - goto out_params_uninit; }
wd_alg_set_init(&wd_rsa_setting.status);
1.Remove duplicate NULL pointer checks in rsa; 2.Remove wd_rsa_setting.dlh_list check in dh/ecc/rsa, since wd_alg_try_init() returns true, wd_<alg>_setting.dlh_list must be NULL, the branch does not enter.
Signed-off-by: Weili Qian qianweili@huawei.com --- wd_dh.c | 7 ------- wd_ecc.c | 7 ------- wd_rsa.c | 13 +++---------- 3 files changed, 3 insertions(+), 24 deletions(-)
diff --git a/wd_dh.c b/wd_dh.c index df5d90e..4a14737 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -60,13 +60,6 @@ static int wd_dh_open_driver(void) const char *alg_name = "dh"; int ret;
- /* - * Compatible with the normal acquisition of device - * drivers in the init interface. - */ - if (wd_dh_setting.dlh_list) - return 0; - ret = wd_get_lib_file_path("libhisi_hpre.so", lib_path, false); if (ret) return ret; diff --git a/wd_ecc.c b/wd_ecc.c index e401a46..1e042f0 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -116,13 +116,6 @@ static int wd_ecc_open_driver(void) const char *alg_name = "sm2"; int ret;
- /* - * Compatible with the normal acquisition of device - * drivers in the init interface - */ - if (wd_ecc_setting.dlh_list) - return 0; - ret = wd_get_lib_file_path("libhisi_hpre.so", lib_path, false); if (ret) return ret; diff --git a/wd_rsa.c b/wd_rsa.c index ba2e088..d34820d 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -101,13 +101,6 @@ static int wd_rsa_open_driver(void) const char *alg_name = "rsa"; int ret;
- /* - * Compatible with the normal acquisition of device - * drivers in the init interface. - */ - if (wd_rsa_setting.dlh_list) - return 0; - ret = wd_get_lib_file_path("libhisi_hpre.so", lib_path, false); if (ret) return ret; @@ -764,19 +757,19 @@ void wd_rsa_get_kg_out_crt_params(struct wd_rsa_kg_out *kout, return; }
- if (qinv && kout->qinv) { + if (kout->qinv) { qinv->bsize = CRT_PARAM_SZ(kout->key_size); qinv->dsize = kout->qinvbytes; qinv->data = (void *)kout->qinv; }
- if (dq && kout->dq) { + if (kout->dq) { dq->bsize = CRT_PARAM_SZ(kout->key_size); dq->dsize = kout->dqbytes; dq->data = (void *)kout->dq; }
- if (dp && kout->dp) { + if (kout->dp) { dp->bsize = CRT_PARAM_SZ(kout->key_size); dp->dsize = kout->dpbytes; dp->data = (void *)kout->dp;
From: Qi Tao taoqi10@huawei.com
The 'req->dst_bytes' is u32 type, use %u instead of %u to print u32 values.
Signed-off-by: Qi Tao taoqi10@huawei.com Signed-off-by: Weili Qian qianweili@huawei.com --- wd_rsa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/wd_rsa.c b/wd_rsa.c index d34820d..4bd1d30 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -384,7 +384,7 @@ static int fill_rsa_msg(struct wd_rsa_msg *msg, struct wd_rsa_req *req, }
if (unlikely(req->dst_bytes != sess->key_size)) { - WD_ERR("invalid: req dst bytes %hu is error!\n", req->dst_bytes); + WD_ERR("invalid: req dst bytes %u is error!\n", req->dst_bytes); return -WD_EINVAL; } }