From: Kai Ye yekai13@huawei.com
Unify print format with following rules: 1. failed to do sth. 2. invalid: sth is NULL.
Signed-off-by: Kai Ye yekai13@huawei.com --- drv/hisi_sec.c | 20 ++++++++++---------- wd_aead.c | 12 ++++++------ wd_cipher.c | 20 ++++++++++---------- wd_digest.c | 10 +++++----- 4 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index 16fcb5f..aa86a6b 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -703,7 +703,7 @@ static void parse_cipher_bd2(struct hisi_sec_sqe *sqe,
done = sqe->type2.done_flag & SEC_DONE_MASK; if (done != SEC_HW_TASK_DONE || sqe->type2.error_type) { - WD_ERR("SEC BD %s fail! done=0x%x, etype=0x%x\n", "cipher", + WD_ERR("failed to parse cipher BD2! done=0x%x, etype=0x%x\n", done, sqe->type2.error_type); recv_msg->result = WD_IN_EPARA; } else { @@ -927,7 +927,7 @@ int hisi_sec_cipher_send(handle_t ctx, struct wd_cipher_msg *msg) int ret;
if (!msg) { - WD_ERR("input cipher msg is NULL!\n"); + WD_ERR("invalid: input cipher msg is NULL!\n"); return -WD_EINVAL; }
@@ -1130,7 +1130,7 @@ int hisi_sec_cipher_send_v3(handle_t ctx, struct wd_cipher_msg *msg) int ret;
if (!msg) { - WD_ERR("input cipher msg is NULL!\n"); + WD_ERR("invalid: input cipher msg is NULL!\n"); return -WD_EINVAL; }
@@ -1175,7 +1175,7 @@ static void parse_cipher_bd3(struct hisi_sec_sqe3 *sqe,
done = sqe->done_flag & SEC_DONE_MASK; if (done != SEC_HW_TASK_DONE || sqe->error_type) { - WD_ERR("SEC BD3 %s fail! done=0x%x, etype=0x%x\n", "cipher", + WD_ERR("failed to parse cipher BD3! done=0x%x, etype=0x%x\n", done, sqe->error_type); recv_msg->result = WD_IN_EPARA; } else { @@ -1278,7 +1278,7 @@ static void parse_digest_bd2(struct hisi_sec_sqe *sqe,
done = sqe->type2.done_flag & SEC_DONE_MASK; if (done != SEC_HW_TASK_DONE || sqe->type2.error_type) { - WD_ERR("SEC BD %s fail! done=0x%x, etype=0x%x\n", "digest", + WD_ERR("failed to parse digest BD2! done=0x%x, etype=0x%x\n", done, sqe->type2.error_type); recv_msg->result = WD_IN_EPARA; } else { @@ -1354,7 +1354,7 @@ int hisi_sec_digest_send(handle_t ctx, struct wd_digest_msg *msg) int ret;
if (!msg) { - WD_ERR("input digest msg is NULL!\n"); + WD_ERR("invalid: input digest msg is NULL!\n"); return -WD_EINVAL; }
@@ -1510,7 +1510,7 @@ int hisi_sec_digest_send_v3(handle_t ctx, struct wd_digest_msg *msg) int ret;
if (!msg) { - WD_ERR("input digest msg is NULL!\n"); + WD_ERR("invalid: input digest msg is NULL!\n"); return -WD_EINVAL; }
@@ -1578,7 +1578,7 @@ static void parse_digest_bd3(struct hisi_sec_sqe3 *sqe,
done = sqe->done_flag & SEC_DONE_MASK; if (done != SEC_HW_TASK_DONE || sqe->error_type) { - WD_ERR("SEC BD3 %s fail! done=0x%x, etype=0x%x\n", "digest", + WD_ERR("failed to parse digest BD3! done=0x%x, etype=0x%x\n", done, sqe->error_type); recv_msg->result = WD_IN_EPARA; } else { @@ -1927,7 +1927,7 @@ static void parse_aead_bd2(struct hisi_sec_sqe *sqe, icv = (sqe->type2.done_flag & SEC_ICV_MASK) >> 1; if (done != SEC_HW_TASK_DONE || sqe->type2.error_type || icv == SEC_HW_ICV_ERR) { - WD_ERR("SEC BD aead fail! done=0x%x, etype=0x%x, icv=0x%x\n", + WD_ERR("failed to parse aead BD2! done=0x%x, etype=0x%x, icv=0x%x\n", done, sqe->type2.error_type, icv); recv_msg->result = WD_IN_EPARA; } else { @@ -2195,7 +2195,7 @@ static void parse_aead_bd3(struct hisi_sec_sqe3 *sqe, icv = (sqe->done_flag & SEC_ICV_MASK) >> 1; if (done != SEC_HW_TASK_DONE || sqe->error_type || icv == SEC_HW_ICV_ERR) { - WD_ERR("SEC BD3 aead fail! done=0x%x, etype=0x%x, icv=0x%x\n", + WD_ERR("failed to parse aead BD3! done=0x%x, etype=0x%x, icv=0x%x\n", done, sqe->error_type, icv); recv_msg->result = WD_IN_EPARA; } else { diff --git a/wd_aead.c b/wd_aead.c index 7df8e80..74047b5 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -63,14 +63,14 @@ static void wd_aead_set_static_drv(void) { wd_aead_setting.driver = wd_aead_get_driver(); if (!wd_aead_setting.driver) - WD_ERR("fail to get driver\n"); + WD_ERR("failed to get driver!\n"); } #else static void __attribute__((constructor)) wd_aead_open_driver(void) { wd_aead_setting.dlhandle = dlopen("libhisi_sec.so", RTLD_NOW); if (!wd_aead_setting.dlhandle) - WD_ERR("failed to open libhisi_sec.so\n"); + WD_ERR("failed to open libhisi_sec.so!\n"); }
static void __attribute__((destructor)) wd_aead_close_driver(void) @@ -344,7 +344,7 @@ static int aead_param_check(struct wd_aead_sess *sess, int ret;
if (unlikely(!sess || !req)) { - WD_ERR("aead input sess or req is NULL.\n"); + WD_ERR("invalid: aead input sess or req is NULL!\n"); return -WD_EINVAL; }
@@ -393,7 +393,7 @@ static int aead_param_check(struct wd_aead_sess *sess, static int aead_init_check(struct wd_ctx_config *config, struct wd_sched *sched) { if (!config || !config->ctxs || !config->ctxs[0].ctx || !sched) { - WD_ERR("wd aead config or sched is NULL!\n"); + WD_ERR("invalid: wd aead config or sched is NULL!\n"); return -WD_EINVAL; }
@@ -594,7 +594,7 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req) return -WD_EINVAL;
if (unlikely(!req->cb)) { - WD_ERR("aead input req cb is NULL.\n"); + WD_ERR("invalid: aead input req cb is NULL!\n"); return -WD_EINVAL; }
@@ -647,7 +647,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count) int ret;
if (!count) { - WD_ERR("aead poll ctx input param is NULL!\n"); + WD_ERR("invalid: aead poll ctx input param is NULL!\n"); return -WD_EINVAL; }
diff --git a/wd_cipher.c b/wd_cipher.c index afd8c4d..3a9b323 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -75,14 +75,14 @@ static void wd_cipher_set_static_drv(void) { wd_cipher_setting.driver = wd_cipher_get_driver(); if (!wd_cipher_setting.driver) - WD_ERR("fail to get driver\n"); + WD_ERR("failed to get driver!\n"); } #else static void __attribute__((constructor)) wd_cipher_open_driver(void) { wd_cipher_setting.dlhandle = dlopen("libhisi_sec.so", RTLD_NOW); if (!wd_cipher_setting.dlhandle) - WD_ERR("fail to open libhisi_sec.so\n"); + WD_ERR("failed to open libhisi_sec.so!\n"); }
static void __attribute__((destructor)) wd_cipher_close_driver(void) @@ -158,7 +158,7 @@ static int cipher_init_check(struct wd_ctx_config *config, struct wd_sched *sched) { if (!config || !config->ctxs || !config->ctxs[0].ctx || !sched) { - WD_ERR("wd cipher config or sched is NULL!\n"); + WD_ERR("invalid: wd cipher config or sched is NULL!\n"); return -WD_EINVAL; }
@@ -177,7 +177,7 @@ int wd_cipher_set_key(handle_t h_sess, const __u8 *key, __u32 key_len) int ret;
if (!key || !sess) { - WD_ERR("cipher set key input param err!\n"); + WD_ERR("invalid: cipher set key input param err!\n"); return -WD_EINVAL; }
@@ -205,13 +205,13 @@ handle_t wd_cipher_alloc_sess(struct wd_cipher_sess_setup *setup) struct wd_cipher_sess *sess = NULL;
if (unlikely(!setup)) { - WD_ERR("cipher input setup is NULL!\n"); + WD_ERR("invalid: cipher input setup is NULL!\n"); return (handle_t)0; }
sess = malloc(sizeof(struct wd_cipher_sess)); if (!sess) { - WD_ERR("fail to alloc session memory!\n"); + WD_ERR("failed to alloc session memory!\n"); return (handle_t)0; } memset(sess, 0, sizeof(struct wd_cipher_sess)); @@ -235,7 +235,7 @@ void wd_cipher_free_sess(handle_t h_sess) struct wd_cipher_sess *sess = (struct wd_cipher_sess *)h_sess;
if (unlikely(!sess)) { - WD_ERR("cipher input h_sess is NULL!\n"); + WD_ERR("invalid: cipher input h_sess is NULL!\n"); return; }
@@ -387,12 +387,12 @@ static int wd_cipher_check_params(handle_t h_sess, int ret = 0;
if (unlikely(!h_sess || !req)) { - WD_ERR("cipher input sess or req is NULL!\n"); + WD_ERR("invalid: cipher input sess or req is NULL!\n"); return -WD_EINVAL; }
if (unlikely(mode == CTX_MODE_ASYNC && !req->cb)) { - WD_ERR("cipher req cb is NULL!\n"); + WD_ERR("invalid: cipher req cb is NULL!\n"); return -WD_EINVAL; }
@@ -561,7 +561,7 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count) int ret;
if (unlikely(!count)) { - WD_ERR("wd cipher poll ctx input param is NULL!\n"); + WD_ERR("invalid: cipher poll ctx input param is NULL!\n"); return -WD_EINVAL; }
diff --git a/wd_digest.c b/wd_digest.c index fb29746..0ddc074 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -62,7 +62,7 @@ static void wd_digest_set_static_drv(void) { wd_digest_setting.driver = wd_digest_get_driver(); if (!wd_digest_setting.driver) - WD_ERR("fail to get driver\n"); + WD_ERR("failed to get driver!\n"); } #else static void __attribute__((constructor)) wd_digest_open_driver(void) @@ -70,7 +70,7 @@ static void __attribute__((constructor)) wd_digest_open_driver(void) /* Fix me: vendor driver should be put in /usr/lib/wd/ */ wd_digest_setting.dlhandle = dlopen("libhisi_sec.so", RTLD_NOW); if (!wd_digest_setting.dlhandle) - WD_ERR("fail to open libhisi_sec.so\n"); + WD_ERR("failed to open libhisi_sec.so!\n"); }
static void __attribute__((destructor)) wd_digest_close_driver(void) @@ -252,7 +252,7 @@ static int digest_param_check(struct wd_digest_sess *sess, int ret;
if (unlikely(!sess || !req)) { - WD_ERR("digest input sess or req is NULL.\n"); + WD_ERR("invalid: digest input sess or req is NULL!\n"); return -WD_EINVAL; }
@@ -398,7 +398,7 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req) return -WD_EINVAL;
if (unlikely(!req->cb)) { - WD_ERR("digest input req cb is NULL.\n"); + WD_ERR("invalid: digest input req cb is NULL!\n"); return -WD_EINVAL; }
@@ -451,7 +451,7 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count) int ret;
if (unlikely(!count)) { - WD_ERR("digest count is NULL.\n"); + WD_ERR("invalid: digest poll ctx input param is NULL!\n"); return -WD_EINVAL; }
From: Weili Qian qianweili@huawei.com
Unify print format with following rules: 1.failed to do sth. 2.add prefix "invalid: " for check parameters printf 3.add "!" at the end.unify print format
Signed-off-by: Weili Qian qianweili@huawei.com --- drv/hisi_hpre.c | 125 +++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 65 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index f1d7720..11ef78b 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -134,12 +134,12 @@ static int crypto_bin_to_hpre_bin(char *dst, const char *src, int j;
if (!dst || !src || b_size <= 0 || d_size <= 0) { - WD_ERR("%s: trans to hpre bin parameters err!\n", p_name); + WD_ERR("invalid: %s trans to hpre bin parameters err!\n", p_name); return -WD_EINVAL; }
if (b_size < d_size) { - WD_ERR("%s: trans to hpre bin data too long!\n", p_name); + WD_ERR("invalid: %s trans to hpre bin data too long!\n", p_name); return -WD_EINVAL; }
@@ -165,7 +165,7 @@ static int hpre_bin_to_crypto_bin(char *dst, const char *src, int b_size, int k = 0;
if (!dst || !src || b_size <= 0) { - WD_ERR("%s trans to crypto bin: parameters err!\n", p_name); + WD_ERR("invalid: %s trans to crypto bin parameters err!\n", p_name); return 0; }
@@ -254,10 +254,9 @@ static int fill_rsa_pubkey(struct wd_rsa_pubkey *pubkey, void **data) wd_rsa_get_pubkey_params(pubkey, &wd_e, &wd_n); ret = crypto_bin_to_hpre_bin(wd_e->data, (const char *)wd_e->data, wd_e->bsize, wd_e->dsize, "rsa e"); - if (ret) { - WD_ERR("rsa pubkey e format fail!\n"); + if (ret) return ret; - } + ret = crypto_bin_to_hpre_bin(wd_n->data, (const char *)wd_n->data, wd_n->bsize, wd_n->dsize, "rsa n"); if (ret) @@ -349,7 +348,7 @@ static int rsa_out_transfer(struct wd_rsa_msg *msg, wd_rsa_get_kg_out_crt_params(key, &qinv, &dq, &dp); ret = hpre_tri_bin_transfer(&qinv, &dq, &dp); if (ret) { - WD_ERR("parse rsa genkey qinv&&dq&&dp format fail!\n"); + WD_ERR("failed to parse rsa genkey qinv&&dq&&dp format!\n"); return ret; }
@@ -361,7 +360,7 @@ static int rsa_out_transfer(struct wd_rsa_msg *msg, wd_rsa_get_kg_out_params(key, &d, &n); ret = hpre_tri_bin_transfer(&d, &n, NULL); if (ret) { - WD_ERR("parse rsa genkey1 d&&n format fail!\n"); + WD_ERR("failed to parse rsa genkey1 d&&n format!\n"); return ret; }
@@ -402,7 +401,7 @@ static int rsa_prepare_key(struct wd_rsa_msg *msg, return ret; ret = wd_rsa_kg_in_data((void *)msg->key, (char **)&data); if (ret < 0) { - WD_ERR("Get rsa gen key data in fail!\n"); + WD_ERR("failed to get rsa gen key data!\n"); return ret; } if (hw_msg->alg == HPRE_ALG_NC_CRT) @@ -410,7 +409,7 @@ static int rsa_prepare_key(struct wd_rsa_msg *msg, else hw_msg->alg = HPRE_ALG_KG_STD; } else { - WD_ERR("Invalid rsa operatin type!\n"); + WD_ERR("invalid: rsa operatin type %u is error!\n", req->op_type); return -WD_EINVAL; }
@@ -546,10 +545,10 @@ static int rsa_recv(handle_t ctx, struct wd_rsa_msg *msg)
if (hw_msg.done != HPRE_HW_TASK_DONE || hw_msg.etype || hw_msg.etype1) { - WD_ERR("HPRE do rsa fail!done=0x%x, etype=0x%x, etype1=0x%x\n", + WD_ERR("failed to do rsa task! done=0x%x, etype=0x%x, etype1=0x%x!\n", hw_msg.done, hw_msg.etype, hw_msg.etype1); if (hw_msg.etype1 & HPRE_HW_SVA_ERROR) - WD_ERR("failed to SVA prefetch: status=%u\n", + WD_ERR("failed to SVA prefetch: status=%u!\n", hw_msg.sva_status); if (hw_msg.done == HPRE_HW_TASK_INIT) msg->result = WD_EINVAL; @@ -559,7 +558,7 @@ static int rsa_recv(handle_t ctx, struct wd_rsa_msg *msg) msg->tag = LW_U16(hw_msg.low_tag); ret = rsa_out_transfer(msg, &hw_msg); if (ret) { - WD_ERR("qm rsa out transfer fail!\n"); + WD_ERR("failed to transfer out rsa BD!\n"); msg->result = WD_OUT_EPARA; } else { msg->result = WD_SUCCESS; @@ -591,14 +590,14 @@ static int fill_dh_xp_params(struct wd_dh_msg *msg, ret = crypto_bin_to_hpre_bin(x, (const char *)x, msg->key_bytes, req->xbytes, "dh x"); if (ret) { - WD_ERR("dh x para format fail!\n"); + WD_ERR("failed to transfer dh x para format to hpre bin!\n"); return ret; }
ret = crypto_bin_to_hpre_bin(p, (const char *)p, msg->key_bytes, req->pbytes, "dh p"); if (ret) { - WD_ERR("dh p para format fail!\n"); + WD_ERR("failed to transfer dh p para format to hpre bin!\n"); return ret; }
@@ -654,7 +653,7 @@ static int dh_send(handle_t ctx, struct wd_dh_msg *msg) (const char *)msg->g, msg->key_bytes, msg->gbytes, "dh g"); if (ret) { - WD_ERR("dh g para format fail!\n"); + WD_ERR("failed to transfer dh g para format to hpre bin!\n"); return ret; }
@@ -688,10 +687,10 @@ static int dh_recv(handle_t ctx, struct wd_dh_msg *msg)
if (hw_msg.done != HPRE_HW_TASK_DONE || hw_msg.etype || hw_msg.etype1) { - WD_ERR("HPRE do dh fail!done=0x%x, etype=0x%x, etype1=0x%x\n", + WD_ERR("failed to do dh task! done=0x%x, etype=0x%x, etype1=0x%x!\n", hw_msg.done, hw_msg.etype, hw_msg.etype1); if (hw_msg.etype1 & HPRE_HW_SVA_ERROR) - WD_ERR("failed to SVA prefetch: status=%u\n", + WD_ERR("failed to SVA prefetch: status=%u!\n", hw_msg.sva_status); if (hw_msg.done == HPRE_HW_TASK_INIT) msg->result = WD_EINVAL; @@ -701,7 +700,7 @@ static int dh_recv(handle_t ctx, struct wd_dh_msg *msg) msg->tag = LW_U16(hw_msg.low_tag); ret = dh_out_transfer(msg, &hw_msg); if (ret) { - WD_ERR("dh out transfer fail!\n"); + WD_ERR("failed to transfer out dh BD!\n"); msg->result = WD_OUT_EPARA; } else { msg->result = WD_SUCCESS; @@ -1021,7 +1020,7 @@ static int ecc_prepare_sign_in(struct wd_ecc_msg *msg, int ret;
if (!in->dgst_set) { - WD_ERR("prepare sign_in, hash not set!\n"); + WD_ERR("invalid: prepare sign_in, hash not set!\n"); return -WD_EINVAL; }
@@ -1029,17 +1028,17 @@ static int ecc_prepare_sign_in(struct wd_ecc_msg *msg, k = &in->k; if (!in->k_set) { if (msg->req.op_type == WD_ECDSA_SIGN) { - WD_ERR("random k not set!\n"); + WD_ERR("invalid: random k not set!\n"); return -WD_EINVAL; } hw_msg->sm2_ksel = 1; } else if (is_all_zero(k, msg)) { - WD_ERR("ecc sign in k all zero!\n"); + WD_ERR("invalid: ecc sign in k all zero!\n"); return -WD_EINVAL; }
if (is_all_zero(e, msg)) { - WD_ERR("ecc sign in e all zero!\n"); + WD_ERR("invalid: ecc sign in e all zero!\n"); return -WD_EINVAL; }
@@ -1072,7 +1071,7 @@ static int ecc_prepare_verf_in(struct wd_ecc_msg *msg, int ret;
if (!vin->dgst_set) { - WD_ERR("prepare verf_in, hash not set!\n"); + WD_ERR("invalid: prepare verf_in, hash not set!\n"); return -WD_EINVAL; }
@@ -1081,7 +1080,7 @@ static int ecc_prepare_verf_in(struct wd_ecc_msg *msg, r = &vin->r;
if (is_all_zero(e, msg)) { - WD_ERR("ecc verf in e all zero!\n"); + WD_ERR("invalid: ecc verf in e all zero!\n"); return -WD_EINVAL; }
@@ -1182,17 +1181,13 @@ static int ecc_prepare_dh_compute_in(struct wd_ecc_msg *msg,
ret = crypto_bin_to_hpre_bin(pbk->x.data, (const char *)pbk->x.data, pbk->x.bsize, pbk->x.dsize, "ecdh compute x"); - if (ret) { - WD_ERR("ecc dh compute in x format fail!\n"); + if (ret) return ret; - }
ret = crypto_bin_to_hpre_bin(pbk->y.data, (const char *)pbk->y.data, pbk->y.bsize, pbk->y.dsize, "ecdh compute y"); - if (ret) { - WD_ERR("ecc dh compute in y format fail!\n"); + if (ret) return ret; - }
*data = pbk->x.data;
@@ -1221,12 +1216,12 @@ static int u_is_in_p(struct wd_ecc_msg *msg) if (msg->curve_id == WD_X25519) pbk->x.data[0] &= 0x7f; if (!less_than_latter(&pbk->x, p)) { - WD_ERR("ux is out of p!\n"); + WD_ERR("invalid: ux is out of p!\n"); return -WD_EINVAL; }
if (is_all_zero(&pbk->x, msg)) { - WD_ERR("ux is zero!\n"); + WD_ERR("invalid: ux is zero!\n"); return -WD_EINVAL; }
@@ -1342,7 +1337,7 @@ static int ecc_prepare_iot(struct wd_ecc_msg *msg, ecc_get_io_len(hw_msg->alg, kbytes, &i_sz, &o_sz); ret = ecc_prepare_in(msg, hw_msg, &data); if (ret) { - WD_ERR("ecc_prepare_in fail!\n"); + WD_ERR("failed to prepare ecc in!\n"); return ret; } hw_msg->low_in = LW_U32((uintptr_t)data); @@ -1350,7 +1345,7 @@ static int ecc_prepare_iot(struct wd_ecc_msg *msg,
ret = ecc_prepare_out(msg, &data); if (ret) { - WD_ERR("ecc_prepare_out fail!\n"); + WD_ERR("failed to prepare ecc out!\n"); return ret; }
@@ -1374,7 +1369,7 @@ static __u32 get_hw_keysz(__u32 ksz) else if (ksz <= BITS_TO_BYTES(576)) size = BITS_TO_BYTES(576); else - WD_ERR("failed to get hw keysize : ksz = %u.\n", ksz); + WD_ERR("invalid: keysize %u is error!\n", ksz);
return size; } @@ -1408,12 +1403,12 @@ static int set_param(struct wd_dtb *dst, const struct wd_dtb *src, const char *p_name) { if (unlikely(!src || !src->data)) { - WD_ERR("%s: src or data NULL!\n", p_name); + WD_ERR("invalid: %s src or data NULL!\n", p_name); return -WD_EINVAL; }
if (unlikely(!src->dsize || src->dsize > dst->bsize)) { - WD_ERR("%s: src dsz = %u error, dst bsz = %u!\n", + WD_ERR("invalid: %s src dsz %u, dst bsz %u is error!\n", p_name, src->dsize, dst->bsize); return -WD_EINVAL; } @@ -1470,13 +1465,13 @@ static struct wd_ecc_out *create_ecdh_out(struct wd_ecc_msg *msg) struct wd_ecc_out *out;
if (!hsz) { - WD_ERR("get msg key size error!\n"); + WD_ERR("failed to get msg key size!\n"); return NULL; }
out = malloc(len); if (!out) { - WD_ERR("failed to alloc, sz = %u!\n", len); + WD_ERR("failed to alloc out memory, sz = %u!\n", len); return NULL; }
@@ -1527,13 +1522,13 @@ static struct wd_ecc_msg *create_req(struct wd_ecc_msg *src, __u8 req_idx)
dst = malloc(sizeof(*dst) + sizeof(*src)); if (unlikely(!dst)) { - WD_ERR("failed to alloc dst\n"); + WD_ERR("failed to alloc dst!\n"); return NULL; }
ecc_key = malloc(sizeof(*ecc_key) + sizeof(*prikey)); if (unlikely(!ecc_key)) { - WD_ERR("failed to alloc ecc_key\n"); + WD_ERR("failed to alloc ecc_key!\n"); goto fail_alloc_key; }
@@ -1541,7 +1536,7 @@ static struct wd_ecc_msg *create_req(struct wd_ecc_msg *src, __u8 req_idx) ecc_key->prikey = prikey; prikey->data = malloc(ECC_PRIKEY_SZ(src->key_bytes)); if (unlikely(!prikey->data)) { - WD_ERR("failed to alloc prikey data\n"); + WD_ERR("failed to alloc prikey data!\n"); goto fail_alloc_key_data; } init_prikey(prikey, src->key_bytes); @@ -1551,7 +1546,7 @@ static struct wd_ecc_msg *create_req(struct wd_ecc_msg *src, __u8 req_idx)
ret = init_req(dst, src, ecc_key, req_idx); if (unlikely(ret)) { - WD_ERR("failed to init req, ret = %d\n", ret); + WD_ERR("failed to init req, ret = %d!\n", ret); goto fail_set_prikey; }
@@ -1602,12 +1597,12 @@ static int ecc_fill(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
if (unlikely(!op_type || (op_type >= WD_EC_OP_MAX && op_type != HPRE_SM2_ENC && op_type != HPRE_SM2_DEC))) { - WD_ERR("op_type = %u error!\n", op_type); + WD_ERR("invalid: input op_type %u is error!\n", op_type); return -WD_EINVAL; }
if (!hw_sz) { - WD_ERR("get msg key size error!\n"); + WD_ERR("failed to get msg key size!\n"); return -WD_EINVAL; }
@@ -1666,12 +1661,12 @@ static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg) return ecc_general_send(ctx, msg);
if (unlikely(!ein->k_set)) { - WD_ERR("error: k not set\n"); + WD_ERR("invalid: k not set!\n"); return -WD_EINVAL; }
if (unlikely(!hash->cb || hash->type >= WD_HASH_MAX)) { - WD_ERR("hash parameter error, type = %u\n", hash->type); + WD_ERR("invalid: input hash type %u is error!\n", hash->type); return -WD_EINVAL; }
@@ -1682,19 +1677,19 @@ static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg) */ ret = split_req(msg, msg_dst); if (unlikely(ret)) { - WD_ERR("failed to split req, ret = %d\n", ret); + WD_ERR("failed to split req, ret = %d!\n", ret); return ret; }
ret = ecc_fill(msg_dst[0], &hw_msg[0]); if (unlikely(ret)) { - WD_ERR("failed to fill 1th sqe, ret = %d\n", ret); + WD_ERR("failed to fill 1th sqe, ret = %d!\n", ret); goto fail_fill_sqe; }
ret = ecc_fill(msg_dst[1], &hw_msg[1]); if (unlikely(ret)) { - WD_ERR("failed to fill 2th sqe, ret = %d\n", ret); + WD_ERR("failed to fill 2th sqe, ret = %d!\n", ret); goto fail_fill_sqe; }
@@ -1725,7 +1720,7 @@ static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg) return ecc_general_send(ctx, msg);
if (unlikely(!hash->cb || hash->type >= WD_HASH_MAX)) { - WD_ERR("hash parameter error, type = %u\n", hash->type); + WD_ERR("invalid: input hash type %u is error!\n", hash->type); return -WD_EINVAL; }
@@ -1779,7 +1774,7 @@ static int ecdh_out_transfer(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_ms
ret = hpre_tri_bin_transfer(&key->x, y, NULL); if (ret) { - WD_ERR("parse ecdh out format fail!\n"); + WD_ERR("failed to transfer ecdh format to crypto bin!\n"); return ret; }
@@ -1889,7 +1884,7 @@ static int ecc_out_transfer(struct wd_ecc_msg *msg, hw_msg->alg == HPRE_ALG_X_DH_MULTIPLY) ret = ecdh_out_transfer(msg, hw_msg); else - WD_ERR("ecc out trans fail algorithm %u error!\n", hw_msg->alg); + WD_ERR("invalid: algorithm type %u is error!\n", hw_msg->alg);
return ret; } @@ -1921,7 +1916,7 @@ static __u32 get_hash_bytes(__u8 type) val = BITS_TO_BYTES(512); break; default: - WD_ERR("get hash bytes: type %u error!\n", type); + WD_ERR("invalid: hash type %u is error!\n", type); break; }
@@ -1977,7 +1972,7 @@ static int sm2_kdf(struct wd_dtb *out, struct wd_ecc_point *x2y2, t_out = m_len >= h_bytes ? tmp : p_out; ret = hash->cb(p_in, in_len, t_out, h_bytes, hash->usr); if (ret) { - WD_ERR("failed to hash cb, ret = %d!\n", ret); + WD_ERR("%s failed to do hash cb, ret = %d!\n", __func__, ret); break; }
@@ -2041,7 +2036,7 @@ static int sm2_hash(struct wd_dtb *out, struct wd_ecc_point *x2y2, msg_pack(p_in, &in_len, x2y2->y.data, x2y2->y.dsize); ret = hash->cb(p_in, in_len, hash_out, h_bytes, hash->usr); if (unlikely(ret)) { - WD_ERR("failed to hash cb, ret = %d!\n", ret); + WD_ERR("%s failed to do hash cb, ret = %d!\n", __func__, ret); goto fail; }
@@ -2088,7 +2083,7 @@ static int sm2_convert_enc_out(struct wd_ecc_msg *src, /* C3 = hash(x2 || M || y2) */ ret = sm2_hash(&eout->c3, &x2y2, &ein->plaintext, hash); if (unlikely(ret)) { - WD_ERR("failed to sm2 hash, ret = %d!\n", ret); + WD_ERR("failed to do sm2 hash, ret = %d!\n", ret); return ret; }
@@ -2096,7 +2091,7 @@ static int sm2_convert_enc_out(struct wd_ecc_msg *src, kdf_out = &eout->c2; ret = sm2_kdf(kdf_out, &x2y2, ein->plaintext.dsize, hash); if (unlikely(ret)) { - WD_ERR("failed to sm2 kdf, ret = %d!\n", ret); + WD_ERR("%s failed to do sm2 kdf, ret = %d!\n", __func__, ret); return ret; }
@@ -2138,7 +2133,7 @@ static int sm2_convert_dec_out(struct wd_ecc_msg *src, /* t = KDF(x2 || y2, klen) */ ret = sm2_kdf(&dout->plaintext, &x2y2, din->c2.dsize, &src->hash); if (unlikely(ret)) { - WD_ERR("failed to sm2 kdf, ret = %d!\n", ret); + WD_ERR("%s failed to do sm2 kdf, ret = %d!\n", __func__, ret); return ret; }
@@ -2166,10 +2161,10 @@ static int ecc_sqe_parse(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
if (hw_msg->done != HPRE_HW_TASK_DONE || hw_msg->etype || hw_msg->etype1) { - WD_ERR("HPRE do ecc fail!done=0x%x, etype=0x%x, etype1=0x%x\n", + WD_ERR("failed to do ecc task! done=0x%x, etype=0x%x, etype1=0x%x!\n", hw_msg->done, hw_msg->etype, hw_msg->etype1); if (hw_msg->etype1 & HPRE_HW_SVA_ERROR) - WD_ERR("failed to SVA prefetch: status=%u\n", + WD_ERR("failed to SVA prefetch: status=%u!\n", hw_msg->sva_status);
if (hw_msg->done == HPRE_HW_TASK_INIT) @@ -2181,7 +2176,7 @@ static int ecc_sqe_parse(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg) ret = ecc_out_transfer(msg, hw_msg); if (ret) { msg->result = WD_OUT_EPARA; - WD_ERR("ecc out transfer fail!\n"); + WD_ERR("failed to transfer out ecc BD, ret = %d!\n", ret); } msg->tag = LW_U16(hw_msg->low_tag); } @@ -2247,7 +2242,7 @@ static int sm2_enc_parse(handle_t h_qp, hw_msg->low_tag = 0; /* use sync mode */ ret = ecc_sqe_parse(first, hw_msg); if (ret) { - WD_ERR("failed to parse first BD, ret = %d\n", ret); + WD_ERR("failed to parse first BD, ret = %d!\n", ret); goto free_first; }
@@ -2291,7 +2286,7 @@ static int sm2_dec_parse(handle_t ctx, struct wd_ecc_msg *msg, hw_msg->low_tag = 0; /* use sync mode */ ret = ecc_sqe_parse(dst, hw_msg); if (ret) { - WD_ERR("failed to parse decode BD, ret = %d\n", ret); + WD_ERR("failed to parse decode BD, ret = %d!\n", ret); goto fail; } msg->result = dst->result;
Add unlikely() on the route of doing request to improve branch prefetch success rate.
Signed-off-by: Yang Shen shenyang39@huawei.com --- wd_comp.c | 69 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 34 deletions(-)
diff --git a/wd_comp.c b/wd_comp.c index de71e9c..9a71dfc 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -198,7 +198,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count) *count = 0;
ret = wd_check_ctx(config, CTX_MODE_ASYNC, idx); - if (ret) + if (unlikely(ret)) return ret;
ctx = config->ctxs + idx; @@ -206,7 +206,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count) do { ret = wd_comp_setting.driver->comp_recv(ctx->ctx, &resp_msg, priv); - if (ret < 0) { + if (unlikely(ret < 0)) { if (ret == -WD_HW_EACCESS) WD_ERR("wd comp recv hw error!\n"); return ret; @@ -216,7 +216,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
msg = wd_find_msg_in_pool(&wd_comp_setting.pool, idx, resp_msg.tag); - if (!msg) { + if (unlikely(!msg)) { WD_ERR("failed to get msg from pool!\n"); return -WD_EINVAL; } @@ -335,12 +335,12 @@ static void fill_comp_msg(struct wd_comp_sess *sess, struct wd_comp_msg *msg, static int wd_comp_check_buffer(struct wd_comp_req *req) { if (req->data_fmt == WD_FLAT_BUF) { - if (!req->src || !req->dst) { + if (unlikely(!req->src || !req->dst)) { WD_ERR("invalid: src or dst is NULL!\n"); return -WD_EINVAL; } } else if (req->data_fmt == WD_SGL_BUF) { - if (!req->list_src || !req->list_dst) { + if (unlikely(!req->list_src || !req->list_dst)) { WD_ERR("invalid: list_src or list_dst is NULL!\n"); return -WD_EINVAL; } @@ -360,37 +360,37 @@ static int wd_comp_check_params(struct wd_comp_sess *sess, { int ret;
- if (!sess || !req) { + if (unlikely(!sess || !req)) { WD_ERR("invalid: sess or req is NULL!\n"); return -WD_EINVAL; }
- if (req->data_fmt > WD_SGL_BUF) { + if (unlikely(req->data_fmt > WD_SGL_BUF)) { WD_ERR("invalid: data_fmt is %d!\n", req->data_fmt); return -WD_EINVAL; }
ret = wd_comp_check_buffer(req); - if (ret) + if (unlikely(ret)) return ret;
- if (req->op_type != WD_DIR_COMPRESS && - req->op_type != WD_DIR_DECOMPRESS) { + if (unlikely(req->op_type != WD_DIR_COMPRESS && + req->op_type != WD_DIR_DECOMPRESS)) { WD_ERR("invalid: op_type is %d!\n", req->op_type); return -WD_EINVAL; }
- if (mode == CTX_MODE_ASYNC && !req->cb) { + if (unlikely(mode == CTX_MODE_ASYNC && !req->cb)) { WD_ERR("invalid: async comp cb is NULL!\n"); return -WD_EINVAL; }
- if (mode == CTX_MODE_ASYNC && !req->cb_param) { + if (unlikely(mode == CTX_MODE_ASYNC && !req->cb_param)) { WD_ERR("invalid: async comp cb param is NULL!\n"); return -WD_EINVAL; }
- if (mode == CTX_MODE_SYNC && req->cb) { + if (unlikely(mode == CTX_MODE_SYNC && req->cb)) { WD_ERR("invalid: sync comp cb should be NULL!\n"); return -WD_EINVAL; } @@ -414,7 +414,7 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess, sess->sched_key, CTX_MODE_SYNC); ret = wd_check_ctx(config, CTX_MODE_SYNC, idx); - if (ret) + if (unlikely(ret)) return ret;
ctx = config->ctxs + idx; @@ -422,7 +422,7 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess, pthread_spin_lock(&ctx->lock);
ret = wd_comp_setting.driver->comp_send(ctx->ctx, msg, priv); - if (ret < 0) { + if (unlikely(ret < 0)) { pthread_spin_unlock(&ctx->lock); WD_ERR("wd comp send error, ret = %d!\n", ret); return ret; @@ -431,11 +431,11 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess, do { if (msg->is_polled) { ret = wd_ctx_wait(ctx->ctx, POLL_TIME); - if (ret < 0) + if (unlikely(ret < 0)) WD_ERR("wd ctx wait timeout, ret = %d!\n", ret); } ret = wd_comp_setting.driver->comp_recv(ctx->ctx, msg, priv); - if (ret == -WD_HW_EACCESS) { + if (unlikely(ret == -WD_HW_EACCESS)) { pthread_spin_unlock(&ctx->lock); WD_ERR("wd comp recv hw error!\n"); return ret; @@ -460,10 +460,10 @@ int wd_do_comp_sync(handle_t h_sess, struct wd_comp_req *req) int ret;
ret = wd_comp_check_params(sess, req, CTX_MODE_SYNC); - if (ret) + if (unlikely(ret)) return ret;
- if (!req->src_len) { + if (unlikely(!req->src_len)) { WD_ERR("invalid: req src_len is 0!\n"); return -WD_EINVAL; } @@ -476,7 +476,7 @@ int wd_do_comp_sync(handle_t h_sess, struct wd_comp_req *req) msg.stream_mode = WD_COMP_STATELESS;
ret = wd_comp_sync_job(sess, req, &msg); - if (ret) + if (unlikely(ret)) return ret;
req->src_len = msg.in_cons; @@ -496,10 +496,10 @@ int wd_do_comp_sync2(handle_t h_sess, struct wd_comp_req *req) int ret;
ret = wd_comp_check_params(sess, req, CTX_MODE_SYNC); - if (ret) + if (unlikely(ret)) return ret;
- if (!req->src_len) { + if (unlikely(!req->src_len)) { WD_ERR("invalid: req src_len is 0!\n"); return -WD_EINVAL; } @@ -523,7 +523,7 @@ int wd_do_comp_sync2(handle_t h_sess, struct wd_comp_req *req) }
ret = wd_do_comp_strm(h_sess, &strm_req); - if (ret < 0 || strm_req.status == WD_IN_EPARA) { + if (unlikely(ret < 0 || strm_req.status == WD_IN_EPARA)) { WD_ERR("wd comp, invalid or incomplete data! ret = %d, status = %u!\n", ret, strm_req.status); return ret; @@ -573,7 +573,7 @@ static int append_store_block(struct wd_comp_sess *sess, __u32 isize = sess->isize;
if (sess->alg_type == WD_ZLIB) { - if (req->dst_len < blocksize + sizeof(checksum)) + if (unlikely(req->dst_len < blocksize + sizeof(checksum))) return -WD_EINVAL; memcpy(req->dst, store_block, blocksize); req->dst_len = blocksize; @@ -582,7 +582,8 @@ static int append_store_block(struct wd_comp_sess *sess, memcpy(req->dst + blocksize, &checksum, sizeof(checksum)); req->dst_len += sizeof(checksum); } else if (sess->alg_type == WD_GZIP) { - if (req->dst_len < blocksize + sizeof(checksum) + sizeof(isize)) + if (unlikely(req->dst_len < blocksize + + sizeof(checksum) + sizeof(isize))) return -WD_EINVAL; memcpy(req->dst, store_block, blocksize); req->dst_len = blocksize; @@ -622,10 +623,10 @@ int wd_do_comp_strm(handle_t h_sess, struct wd_comp_req *req) int ret;
ret = wd_comp_check_params(sess, req, CTX_MODE_SYNC); - if (ret) + if (unlikely(ret)) return ret;
- if (req->data_fmt > WD_FLAT_BUF) { + if (unlikely(req->data_fmt > WD_FLAT_BUF)) { WD_ERR("invalid: data_fmt is %d!\n", req->data_fmt); return -WD_EINVAL; } @@ -647,7 +648,7 @@ int wd_do_comp_strm(handle_t h_sess, struct wd_comp_req *req) src_len = req->src_len;
ret = wd_comp_sync_job(sess, req, &msg); - if (ret) + if (unlikely(ret)) return ret;
req->src_len = msg.in_cons; @@ -675,10 +676,10 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req) __u32 idx;
ret = wd_comp_check_params(sess, req, CTX_MODE_ASYNC); - if (ret) + if (unlikely(ret)) return ret;
- if (!req->src_len) { + if (unlikely(!req->src_len)) { WD_ERR("invalid: req src_len is 0!\n"); return -WD_EINVAL; } @@ -687,13 +688,13 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req) sess->sched_key, CTX_MODE_ASYNC); ret = wd_check_ctx(config, CTX_MODE_ASYNC, idx); - if (ret) + if (unlikely(ret)) return ret;
ctx = config->ctxs + idx;
tag = wd_get_msg_from_pool(&wd_comp_setting.pool, idx, (void **)&msg); - if (tag < 0) { + if (unlikely(tag < 0)) { WD_ERR("failed to get msg from pool!\n"); return -WD_EBUSY; } @@ -705,7 +706,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req) pthread_spin_lock(&ctx->lock);
ret = wd_comp_setting.driver->comp_send(ctx->ctx, msg, priv); - if (ret < 0) { + if (unlikely(ret < 0)) { pthread_spin_unlock(&ctx->lock); WD_ERR("wd comp send error, ret = %d!\n", ret); goto fail_with_msg; @@ -714,7 +715,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req) pthread_spin_unlock(&ctx->lock);
ret = wd_add_task_to_async_queue(&wd_comp_env_config, idx); - if (ret) + if (unlikely(ret)) goto fail_with_msg;
return 0;
Unify print format with following rules: 1.failed to do sth. 2.add prefix "invalid: " for check parameters printf 3.add "!" at the end.
Signed-off-by: Yang Shen shenyang39@huawei.com --- drv/hisi_comp.c | 50 +++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c index 0760908..5883bb4 100644 --- a/drv/hisi_comp.c +++ b/drv/hisi_comp.c @@ -192,12 +192,12 @@ struct hisi_zip_ctx { static int buf_size_check_deflate(__u32 *in_size, __u32 *out_size) { if (unlikely(*in_size > HZ_MAX_SIZE)) { - WD_ERR("invalid: out of range in_len(%u)!\n", *in_size); + WD_ERR("invalid: in_len(%u) is out of range!\n", *in_size); return -WD_EINVAL; }
if (unlikely(*out_size > HZ_MAX_SIZE)) { - WD_ERR("warning: out of range avail_out(%u), will set 8MB size max!\n", + WD_ERR("warning: avail_out(%u) is out of range, will set 8MB size max!\n", *out_size); *out_size = HZ_MAX_SIZE; } @@ -295,19 +295,19 @@ static int fill_buf_addr_deflate_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
h_sgl_pool = hisi_qm_get_sglpool(h_qp); if (!h_sgl_pool) { - WD_ERR("failed to get sglpool\n"); + WD_ERR("failed to get sglpool!\n"); return -WD_EINVAL; }
hw_sgl_in = hisi_qm_get_hw_sgl(h_sgl_pool, req->list_src); if (!hw_sgl_in) { - WD_ERR("failed to get hw sgl in\n"); + WD_ERR("failed to get hw sgl in!\n"); return -WD_ENOMEM; }
hw_sgl_out = hisi_qm_get_hw_sgl(h_sgl_pool, req->list_dst); if (!hw_sgl_out) { - WD_ERR("failed to get hw sgl out\n"); + WD_ERR("failed to get hw sgl out!\n"); hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_in); return -WD_ENOMEM; } @@ -419,17 +419,18 @@ static int fill_buf_lz77_zstd(handle_t h_qp, struct hisi_zip_sqe *sqe, void *ctx_buf = NULL;
if (unlikely(!data)) { - WD_ERR("wd_lz77_zstd_data address is NULL\n"); + WD_ERR("invalid: wd_lz77_zstd_data address is NULL!\n"); return -WD_EINVAL; }
if (unlikely(in_size > ZSTD_MAX_SIZE)) { - WD_ERR("invalid input data size of lz77_zstd(%u)\n", in_size); + WD_ERR("invalid: in_len(%u) of lz77_zstd is out of range!\n", + in_size); return -WD_EINVAL; }
if (unlikely(out_size > HZ_MAX_SIZE)) { - WD_ERR("warning: out of range avail_out(%u), will set 8MB size max!\n", + WD_ERR("warning: avail_out(%u) is out of range , will set 8MB size max!\n", out_size); out_size = HZ_MAX_SIZE; } @@ -439,7 +440,7 @@ static int fill_buf_lz77_zstd(handle_t h_qp, struct hisi_zip_sqe *sqe, * the frequency information about input data. */ if (unlikely(out_size < ZSTD_FREQ_DATA_SIZE + lit_size)) { - WD_ERR("output buffer size of lz77_zstd is not enough(%u)\n", + WD_ERR("invalid: sequences output size(%u) is not enough!\n", ZSTD_FREQ_DATA_SIZE + in_size); return -WD_EINVAL; } @@ -491,12 +492,13 @@ static int fill_buf_lz77_zstd_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe, int ret;
if (unlikely(in_size > ZSTD_MAX_SIZE)) { - WD_ERR("invalid input data size of lz77_zstd(%u)\n", in_size); + WD_ERR("invalid: in_len(%u) of lz77_zstd is out of range!\n", + in_size); return -WD_EINVAL; }
if (unlikely(!data)) { - WD_ERR("wd_lz77_zstd_data address is NULL\n"); + WD_ERR("invalid: wd_lz77_zstd_data address is NULL!\n"); return -WD_EINVAL; }
@@ -513,26 +515,26 @@ static int fill_buf_lz77_zstd_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
h_sgl_pool = hisi_qm_get_sglpool(h_qp); if (!h_sgl_pool) { - WD_ERR("failed to get sglpool\n"); + WD_ERR("failed to get sglpool!\n"); return -WD_EINVAL; }
hw_sgl_in = hisi_qm_get_hw_sgl(h_sgl_pool, req->list_src); if (!hw_sgl_in) { - WD_ERR("failed to get hw sgl in\n"); + WD_ERR("failed to get hw sgl in!\n"); return -WD_ENOMEM; }
hw_sgl_out_lit = hisi_qm_get_hw_sgl(h_sgl_pool, req->list_dst); if (!hw_sgl_out_lit) { - WD_ERR("failed to get hw sgl out for literals\n"); + WD_ERR("failed to get hw sgl out for literals!\n"); ret = -WD_ENOMEM; goto err_free_sgl_in; }
hw_sgl_out_seq = hisi_qm_get_hw_sgl(h_sgl_pool, seq_start); if (!hw_sgl_out_seq) { - WD_ERR("failed to get hw sgl out for sequences\n"); + WD_ERR("failed to get hw sgl out for sequences!\n"); ret = -WD_ENOMEM; goto err_free_sgl_out_lit; } @@ -626,7 +628,7 @@ static int fill_comp_level_lz77_zstd(struct hisi_zip_sqe *sqe, enum wd_comp_leve sqe->dw9 = val; break; default: - WD_ERR("invalid: comp_lv in unsupported (%d)\n", comp_lv); + WD_ERR("invalid: comp_lv(%d) is unsupport!\n", comp_lv); return -WD_EINVAL; }
@@ -821,7 +823,7 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
if ((hw_type <= HISI_QM_API_VER2_BASE && alg_type > WD_GZIP) || (hw_type >= HISI_QM_API_VER3_BASE && alg_type >= WD_COMP_ALG_MAX)) { - WD_ERR("invalid algorithm type(%d)\n", alg_type); + WD_ERR("invalid: algorithm type is %d!\n", alg_type); return -WD_EINVAL; }
@@ -870,13 +872,13 @@ static int hisi_zip_comp_send(handle_t ctx, struct wd_comp_msg *msg, void *priv)
ret = fill_zip_comp_sqe(qp, msg, &sqe); if (ret < 0) { - WD_ERR("failed to fill zip sqe(%d)!\n", ret); + WD_ERR("failed to fill zip sqe, ret = %d!\n", ret); return ret; } ret = hisi_qm_send(h_qp, &sqe, 1, &count); if (ret < 0) { if (ret != -WD_EBUSY) - WD_ERR("qm send is err(%d)!\n", ret); + WD_ERR("failed to send to hardware, ret = %d!\n", ret);
return ret; } @@ -919,7 +921,7 @@ static void free_hw_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
h_sgl_pool = hisi_qm_get_sglpool(h_qp); if (!h_sgl_pool) { - WD_ERR("failed to get sglpool to free hw sgl\n"); + WD_ERR("failed to get sglpool to free hw sgl!\n"); return; }
@@ -949,7 +951,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
alg_type = get_alg_type(type); if (alg_type < 0) { - WD_ERR("failed to get request algorithm type(%u)\n", type); + WD_ERR("invalid: hardware type is %u!\n", type); return -WD_EINVAL; }
@@ -960,7 +962,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe, if (qp->q_info.qp_mode == CTX_MODE_ASYNC) { recv_msg = wd_comp_get_msg(qp->q_info.idx, tag); if (!recv_msg) { - WD_ERR("failed to get send msg! idx = %u, tag = %u.\n", + WD_ERR("failed to get send msg! idx = %u, tag = %u!\n", qp->q_info.idx, tag); return -WD_EINVAL; } @@ -970,7 +972,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
if (status != 0 && status != HZ_NEGACOMPRESS && status != HZ_CRC_ERR && status != HZ_DECOMP_END) { - WD_ERR("bad status(ctx_st=0x%x, s=0x%x, t=%u)\n", + WD_ERR("bad request(ctx_st = 0x%x, status = 0x%x, algorithm type = %u)!\n", ctx_st, status, type); recv_msg->req.status = WD_IN_EPARA; } @@ -993,7 +995,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe, if (ctx_st == HZ_DECOMP_NO_SPACE) recv_msg->req.status = WD_EAGAIN;
- dbg("zip recv lst =%hu, ctx_st=0x%x, status=0x%x, alg=%u\n", lstblk, ctx_st, status, type); + dbg("zip recv lst =%hu, ctx_st=0x%x, status=0x%x, alg=%u!\n", lstblk, ctx_st, status, type); if (lstblk && (status == HZ_DECOMP_END)) recv_msg->req.status = WD_STREAM_END;
From: Weili Qian qianweili@huawei.com
Add unlikely() on the route of doing request to improve branch prefetch success rate.
Signed-off-by: Weili Qian qianweili@huawei.com --- v1/drv/hisi_hpre_udrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c index ba32114..bd87cbe 100644 --- a/v1/drv/hisi_hpre_udrv.c +++ b/v1/drv/hisi_hpre_udrv.c @@ -1976,7 +1976,7 @@ static int fill_sm2_dec_sqe(void *message, struct qm_queue_info *info, __u16 i) }
ret = qm_fill_ecc_sqe_general(dst, info, i); - if (ret) + if (unlikely(ret)) goto free_out;
return ret;
Unify print format with following rules: 1.failed to do sth. 2.add prefix "invalid: " for check parameters printf 3.add "!" at the end.
Signed-off-by: Yang Shen shenyang39@huawei.com --- wd_comp.c | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-)
diff --git a/wd_comp.c b/wd_comp.c index 8d0c603..de71e9c 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -60,14 +60,14 @@ static void wd_comp_set_static_drv(void) { wd_comp_setting.driver = wd_comp_get_driver(); if (!wd_comp_setting.driver) - WD_ERR("fail to get driver\n"); + WD_ERR("failed to get driver!\n"); } #else static void __attribute__((constructor)) wd_comp_open_driver(void) { wd_comp_setting.dlhandle = dlopen("libhisi_zip.so", RTLD_NOW); if (!wd_comp_setting.dlhandle) - WD_ERR("Fail to open libhisi_zip.so\n"); + WD_ERR("failed to open libhisi_zip.so!\n"); }
static void __attribute__((destructor)) wd_comp_close_driver(void) @@ -88,12 +88,12 @@ int wd_comp_init(struct wd_ctx_config *config, struct wd_sched *sched) int ret;
if (!config || !config->ctxs || !config->ctxs[0].ctx || !sched) { - WD_ERR("invalid params, config or sched is NULL!\n"); + WD_ERR("invalid: config or sched is NULL!\n"); return -WD_EINVAL; }
if (!wd_is_sva(config->ctxs[0].ctx)) { - WD_ERR("err, non sva, please check system!\n"); + WD_ERR("failed to find sva device, please check system!\n"); return -WD_EINVAL; }
@@ -191,7 +191,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count) int ret;
if (unlikely(!count)) { - WD_ERR("comp poll input count is NULL\n"); + WD_ERR("invalid: comp poll count is 0!\n"); return -WD_EINVAL; }
@@ -208,7 +208,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count) priv); if (ret < 0) { if (ret == -WD_HW_EACCESS) - WD_ERR("wd comp recv hw err!\n"); + WD_ERR("wd comp recv hw error!\n"); return ret; }
@@ -217,7 +217,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count) msg = wd_find_msg_in_pool(&wd_comp_setting.pool, idx, resp_msg.tag); if (!msg) { - WD_ERR("get msg from pool is NULL!\n"); + WD_ERR("failed to get msg from pool!\n"); return -WD_EINVAL; }
@@ -341,7 +341,7 @@ static int wd_comp_check_buffer(struct wd_comp_req *req) } } else if (req->data_fmt == WD_SGL_BUF) { if (!req->list_src || !req->list_dst) { - WD_ERR("invalid: src or dst is NULL!\n"); + WD_ERR("invalid: list_src or list_dst is NULL!\n"); return -WD_EINVAL; } } @@ -381,17 +381,17 @@ static int wd_comp_check_params(struct wd_comp_sess *sess, }
if (mode == CTX_MODE_ASYNC && !req->cb) { - WD_ERR("async comp input cb is NULL!\n"); + WD_ERR("invalid: async comp cb is NULL!\n"); return -WD_EINVAL; }
if (mode == CTX_MODE_ASYNC && !req->cb_param) { - WD_ERR("async comp input cb param is NULL!\n"); + WD_ERR("invalid: async comp cb param is NULL!\n"); return -WD_EINVAL; }
if (mode == CTX_MODE_SYNC && req->cb) { - WD_ERR("sync comp input cb should be NULL!\n"); + WD_ERR("invalid: sync comp cb should be NULL!\n"); return -WD_EINVAL; }
@@ -409,6 +409,7 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess, __u64 recv_count = 0; __u32 idx; int ret; + idx = wd_comp_setting.sched.pick_next_ctx(h_sched_ctx, sess->sched_key, CTX_MODE_SYNC); @@ -423,7 +424,7 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess, ret = wd_comp_setting.driver->comp_send(ctx->ctx, msg, priv); if (ret < 0) { pthread_spin_unlock(&ctx->lock); - WD_ERR("wd comp send err(%d)!\n", ret); + WD_ERR("wd comp send error, ret = %d!\n", ret); return ret; }
@@ -431,17 +432,17 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess, if (msg->is_polled) { ret = wd_ctx_wait(ctx->ctx, POLL_TIME); if (ret < 0) - WD_ERR("wd ctx wait timeout(%d)!\n", ret); + WD_ERR("wd ctx wait timeout, ret = %d!\n", ret); } ret = wd_comp_setting.driver->comp_recv(ctx->ctx, msg, priv); if (ret == -WD_HW_EACCESS) { pthread_spin_unlock(&ctx->lock); - WD_ERR("wd comp recv hw err!\n"); + WD_ERR("wd comp recv hw error!\n"); return ret; } else if (ret == -WD_EAGAIN) { if (++recv_count > MAX_RETRY_COUNTS) { pthread_spin_unlock(&ctx->lock); - WD_ERR("wd comp recv timeout fail!\n"); + WD_ERR("wd comp recv timeout!\n"); return -WD_ETIMEDOUT; } } @@ -523,8 +524,7 @@ int wd_do_comp_sync2(handle_t h_sess, struct wd_comp_req *req)
ret = wd_do_comp_strm(h_sess, &strm_req); if (ret < 0 || strm_req.status == WD_IN_EPARA) { - WD_ERR("wd comp, invalid or incomplete data! " - "ret(%d), req.status(%u)\n", + WD_ERR("wd comp, invalid or incomplete data! ret = %d, status = %u!\n", ret, strm_req.status); return ret; } @@ -622,10 +622,8 @@ int wd_do_comp_strm(handle_t h_sess, struct wd_comp_req *req) int ret;
ret = wd_comp_check_params(sess, req, CTX_MODE_SYNC); - if (ret) { - WD_ERR("fail to check params!\n"); + if (ret) return ret; - }
if (req->data_fmt > WD_FLAT_BUF) { WD_ERR("invalid: data_fmt is %d!\n", req->data_fmt); @@ -696,7 +694,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
tag = wd_get_msg_from_pool(&wd_comp_setting.pool, idx, (void **)&msg); if (tag < 0) { - WD_ERR("busy, failed to get msg from pool!\n"); + WD_ERR("failed to get msg from pool!\n"); return -WD_EBUSY; } fill_comp_msg(sess, msg, req); @@ -709,7 +707,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req) ret = wd_comp_setting.driver->comp_send(ctx->ctx, msg, priv); if (ret < 0) { pthread_spin_unlock(&ctx->lock); - WD_ERR("wd comp send err(%d)!\n", ret); + WD_ERR("wd comp send error, ret = %d!\n", ret); goto fail_with_msg; }
@@ -780,7 +778,7 @@ int wd_comp_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode) int ret;
if (type >= WD_DIR_MAX) { - WD_ERR("wrong type(%u))!\n", type); + WD_ERR("invalid: op_type is %u!\n", type); return -WD_EINVAL; }
@@ -804,7 +802,7 @@ int wd_comp_get_env_param(__u32 node, __u32 type, __u32 mode, int ret;
if (type >= WD_DIR_MAX) { - WD_ERR("wrong type(%u))!\n", type); + WD_ERR("invalid: op_type is %u!\n", type); return -WD_EINVAL; }
Add unlikely() on the route of doing request to improve branch prefetch success rate.
Signed-off-by: Yang Shen shenyang39@huawei.com --- drv/hisi_comp.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c index 5883bb4..860da43 100644 --- a/drv/hisi_comp.c +++ b/drv/hisi_comp.c @@ -246,7 +246,7 @@ static int fill_buf_deflate_generic(struct hisi_zip_sqe *sqe, }
ret = buf_size_check_deflate(&in_size, &out_size); - if (ret) + if (unlikely(ret)) return ret;
fill_buf_size_deflate(sqe, in_size, out_size); @@ -294,19 +294,19 @@ static int fill_buf_addr_deflate_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe, handle_t h_sgl_pool;
h_sgl_pool = hisi_qm_get_sglpool(h_qp); - if (!h_sgl_pool) { + if (unlikely(!h_sgl_pool)) { WD_ERR("failed to get sglpool!\n"); return -WD_EINVAL; }
hw_sgl_in = hisi_qm_get_hw_sgl(h_sgl_pool, req->list_src); - if (!hw_sgl_in) { + if (unlikely(!hw_sgl_in)) { WD_ERR("failed to get hw sgl in!\n"); return -WD_ENOMEM; }
hw_sgl_out = hisi_qm_get_hw_sgl(h_sgl_pool, req->list_dst); - if (!hw_sgl_out) { + if (unlikely(!hw_sgl_out)) { WD_ERR("failed to get hw sgl out!\n"); hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_in); return -WD_ENOMEM; @@ -345,7 +345,7 @@ static int fill_buf_deflate_slg_generic(handle_t h_qp, struct hisi_zip_sqe *sqe, fill_buf_type_sgl(sqe);
ret = fill_buf_addr_deflate_sgl(h_qp, sqe, msg); - if (ret) + if (unlikely(ret)) return ret;
if (head != NULL && msg->req.op_type == WD_DIR_COMPRESS) { @@ -514,26 +514,26 @@ static int fill_buf_lz77_zstd_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe, fill_buf_size_lz77_zstd(sqe, in_size, lits_size, out_size - lits_size);
h_sgl_pool = hisi_qm_get_sglpool(h_qp); - if (!h_sgl_pool) { + if (unlikely(!h_sgl_pool)) { WD_ERR("failed to get sglpool!\n"); return -WD_EINVAL; }
hw_sgl_in = hisi_qm_get_hw_sgl(h_sgl_pool, req->list_src); - if (!hw_sgl_in) { + if (unlikely(!hw_sgl_in)) { WD_ERR("failed to get hw sgl in!\n"); return -WD_ENOMEM; }
hw_sgl_out_lit = hisi_qm_get_hw_sgl(h_sgl_pool, req->list_dst); - if (!hw_sgl_out_lit) { + if (unlikely(!hw_sgl_out_lit)) { WD_ERR("failed to get hw sgl out for literals!\n"); ret = -WD_ENOMEM; goto err_free_sgl_in; }
hw_sgl_out_seq = hisi_qm_get_hw_sgl(h_sgl_pool, seq_start); - if (!hw_sgl_out_seq) { + if (unlikely(!hw_sgl_out_seq)) { WD_ERR("failed to get hw sgl out for sequences!\n"); ret = -WD_ENOMEM; goto err_free_sgl_out_lit; @@ -680,7 +680,7 @@ static void get_data_size_lz77_zstd(struct hisi_zip_sqe *sqe, enum wd_comp_op_ty struct wd_lz77_zstd_data *data = recv_msg->req.priv; void *ctx_buf = recv_msg->ctx_buf;
- if (!data) + if (unlikely(!data)) return;
data->lit_num = sqe->comp_data_length; @@ -782,7 +782,7 @@ static int hisi_zip_init(struct wd_ctx_config_internal *config, void *priv) qm_priv.qp_mode = config->ctxs[i].ctx_mode; qm_priv.idx = i; h_qp = hisi_qm_alloc_qp(&qm_priv, h_ctx); - if (!h_qp) + if (unlikely(!h_qp)) goto out; }
@@ -821,14 +821,14 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg, __u8 state; int ret;
- if ((hw_type <= HISI_QM_API_VER2_BASE && alg_type > WD_GZIP) || - (hw_type >= HISI_QM_API_VER3_BASE && alg_type >= WD_COMP_ALG_MAX)) { + if (unlikely((hw_type <= HISI_QM_API_VER2_BASE && alg_type > WD_GZIP) || + (hw_type >= HISI_QM_API_VER3_BASE && alg_type >= WD_COMP_ALG_MAX))) { WD_ERR("invalid: algorithm type is %d!\n", alg_type); return -WD_EINVAL; }
ret = ops[alg_type].fill_buf[msg->req.data_fmt]((handle_t)qp, sqe, msg); - if (ret) + if (unlikely(ret)) return ret;
ops[alg_type].fill_sqe_type(sqe); @@ -838,7 +838,7 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg, ops[alg_type].fill_tag(sqe, msg->tag);
ret = ops[alg_type].fill_comp_level(sqe, msg->comp_lv); - if (ret) + if (unlikely(ret)) return ret;
state = (msg->stream_mode == WD_COMP_STATEFUL) ? HZ_STATEFUL : @@ -871,12 +871,12 @@ static int hisi_zip_comp_send(handle_t ctx, struct wd_comp_msg *msg, void *priv) int ret;
ret = fill_zip_comp_sqe(qp, msg, &sqe); - if (ret < 0) { + if (unlikely(ret < 0)) { WD_ERR("failed to fill zip sqe, ret = %d!\n", ret); return ret; } ret = hisi_qm_send(h_qp, &sqe, 1, &count); - if (ret < 0) { + if (unlikely(ret < 0)) { if (ret != -WD_EBUSY) WD_ERR("failed to send to hardware, ret = %d!\n", ret);
@@ -920,7 +920,7 @@ static void free_hw_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe, handle_t h_sgl_pool;
h_sgl_pool = hisi_qm_get_sglpool(h_qp); - if (!h_sgl_pool) { + if (unlikely(!h_sgl_pool)) { WD_ERR("failed to get sglpool to free hw sgl!\n"); return; } @@ -950,7 +950,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe, __u32 tag;
alg_type = get_alg_type(type); - if (alg_type < 0) { + if (unlikely(alg_type < 0)) { WD_ERR("invalid: hardware type is %u!\n", type); return -WD_EINVAL; } @@ -961,7 +961,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
if (qp->q_info.qp_mode == CTX_MODE_ASYNC) { recv_msg = wd_comp_get_msg(qp->q_info.idx, tag); - if (!recv_msg) { + if (unlikely(!recv_msg)) { WD_ERR("failed to get send msg! idx = %u, tag = %u!\n", qp->q_info.idx, tag); return -WD_EINVAL; @@ -970,8 +970,8 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
recv_msg->req.status = 0;
- if (status != 0 && status != HZ_NEGACOMPRESS && - status != HZ_CRC_ERR && status != HZ_DECOMP_END) { + if (unlikely(status != 0 && status != HZ_NEGACOMPRESS && + status != HZ_CRC_ERR && status != HZ_DECOMP_END)) { WD_ERR("bad request(ctx_st = 0x%x, status = 0x%x, algorithm type = %u)!\n", ctx_st, status, type); recv_msg->req.status = WD_IN_EPARA; @@ -1019,7 +1019,7 @@ static int hisi_zip_comp_recv(handle_t ctx, struct wd_comp_msg *recv_msg, int ret;
ret = hisi_qm_recv(h_qp, &sqe, 1, &count); - if (ret < 0) + if (unlikely(ret < 0)) return ret;
return parse_zip_sqe(qp, &sqe, recv_msg);
From: Weili Qian qianweili@huawei.com
Unify print format with following rules: 1.failed to do sth. 2.add prefix "invalid: " for check parameters printf 3.add "!" at the end.
Signed-off-by: Weili Qian qianweili@huawei.com --- wd_dh.c | 44 +++++++++--------- wd_ecc.c | 136 +++++++++++++++++++++++++++---------------------------- wd_rsa.c | 118 +++++++++++++++++++++++------------------------ 3 files changed, 149 insertions(+), 149 deletions(-)
diff --git a/wd_dh.c b/wd_dh.c index f5d70a2..c0d3e00 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -51,14 +51,14 @@ static void wd_dh_set_static_drv(void) { wd_dh_setting.driver = wd_dh_get_driver(); if (!wd_dh_setting.driver) - WD_ERR("fail to get driver\n"); + WD_ERR("failed to get dh driver!\n"); } #else static void __attribute__((constructor)) wd_dh_open_driver(void) { wd_dh_setting.dlhandle = dlopen("libhisi_hpre.so", RTLD_NOW); if (!wd_dh_setting.dlhandle) - WD_ERR("Fail to open libhisi_hpre.so\n"); + WD_ERR("failed to open libhisi_hpre.so!\n"); }
static void __attribute__((destructor)) wd_dh_close_driver(void) @@ -71,7 +71,7 @@ static void __attribute__((destructor)) wd_dh_close_driver(void) void wd_dh_set_driver(struct wd_dh_driver *drv) { if (!drv) { - WD_ERR("drv NULL\n"); + WD_ERR("invalid: dh drv is NULL!\n"); return; }
@@ -81,12 +81,12 @@ void wd_dh_set_driver(struct wd_dh_driver *drv) static int param_check(struct wd_ctx_config *config, struct wd_sched *sched) { if (!config || !config->ctxs || !config->ctxs[0].ctx || !sched) { - WD_ERR("config or sched NULL\n"); + WD_ERR("invalid: config or sched is NULL!\n"); return -WD_EINVAL; }
if (!wd_is_sva(config->ctxs[0].ctx)) { - WD_ERR("no sva, do not dh init\n"); + WD_ERR("invalid: the mode is non sva, please check system!\n"); return -WD_EINVAL; }
@@ -103,13 +103,13 @@ int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
ret = wd_init_ctx_config(&wd_dh_setting.config, config); if (ret) { - WD_ERR("failed to wd initialize ctx config, ret = %d\n", ret); + WD_ERR("failed to initialize ctx config, ret = %d!\n", ret); return ret; }
ret = wd_init_sched(&wd_dh_setting.sched, sched); if (ret) { - WD_ERR("failed to wd initialize sched, ret = %d\n", ret); + WD_ERR("failed to initialize sched, ret = %d!\n", ret); goto out; }
@@ -137,7 +137,7 @@ int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched) ret = wd_dh_setting.driver->init(&wd_dh_setting.config, priv, wd_dh_setting.driver->alg_name); if (ret < 0) { - WD_ERR("failed to drv init, ret= %d\n", ret); + WD_ERR("failed to init dh driver, ret= %d!\n", ret); goto out_init; }
@@ -159,7 +159,7 @@ out: void wd_dh_uninit(void) { if (!wd_dh_setting.priv) { - WD_ERR("repeat uninit dh\n"); + WD_ERR("invalid: repeat uninit dh!\n"); return; }
@@ -184,7 +184,7 @@ static int fill_dh_msg(struct wd_dh_msg *msg, struct wd_dh_req *req, msg->key_bytes = sess->key_size;
if (unlikely(req->pri_bytes < sess->key_size)) { - WD_ERR("req pri bytes = %hu error!\n", req->pri_bytes); + WD_ERR("invalid: req pri bytes %hu is error!\n", req->pri_bytes); return -WD_EINVAL; }
@@ -195,12 +195,12 @@ static int fill_dh_msg(struct wd_dh_msg *msg, struct wd_dh_req *req, msg->g = (__u8 *)req->pv; msg->gbytes = req->pvbytes; } else { - WD_ERR("op_type = %hhu error!\n", req->op_type); + WD_ERR("invalid: op_type %hhu is error!\n", req->op_type); return -WD_EINVAL; }
if (!msg->g) { - WD_ERR("request dh g is NULL!\n"); + WD_ERR("invalid: request dh g is NULL!\n"); return -WD_EINVAL; }
@@ -268,7 +268,7 @@ int wd_do_dh_sync(handle_t sess, struct wd_dh_req *req) int ret;
if (unlikely(!sess || !req)) { - WD_ERR("input param NULL!\n"); + WD_ERR("invalid: input param NULL!\n"); return -WD_EINVAL; }
@@ -310,7 +310,7 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req) __u32 idx;
if (unlikely(!req || !sess || !req->cb)) { - WD_ERR("input param NULL!\n"); + WD_ERR("invalid: input param NULL!\n"); return -WD_EINVAL; }
@@ -363,7 +363,7 @@ int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count) int ret;
if (unlikely(!count)) { - WD_ERR("count is NULL!\n"); + WD_ERR("invalid: count is NULL!\n"); return -WD_EINVAL; }
@@ -415,7 +415,7 @@ int wd_dh_poll(__u32 expt, __u32 *count) int wd_dh_get_mode(handle_t sess, __u8 *alg_mode) { if (!sess || !alg_mode) { - WD_ERR("dh get mode: param NULL!\n"); + WD_ERR("invalid: dh get mode, param NULL!\n"); return -WD_EINVAL; }
@@ -427,7 +427,7 @@ int wd_dh_get_mode(handle_t sess, __u8 *alg_mode) __u32 wd_dh_key_bits(handle_t sess) { if (!sess) { - WD_ERR("get dh key bits, sess NULL!\n"); + WD_ERR("invalid: get dh key bits, sess NULL!\n"); return 0; }
@@ -439,7 +439,7 @@ int wd_dh_set_g(handle_t sess, struct wd_dtb *g) struct wd_dh_sess *sess_t = (struct wd_dh_sess *)sess;
if (!sess_t || !g) { - WD_ERR("param NULL!\n"); + WD_ERR("invalid: dh set g, param NULL!\n"); return -WD_EINVAL; }
@@ -460,7 +460,7 @@ int wd_dh_set_g(handle_t sess, struct wd_dtb *g) void wd_dh_get_g(handle_t sess, struct wd_dtb **g) { if (!sess || !g) { - WD_ERR("param NULL!\n"); + WD_ERR("invalid: dh get g, param NULL!\n"); return; }
@@ -472,7 +472,7 @@ handle_t wd_dh_alloc_sess(struct wd_dh_sess_setup *setup) struct wd_dh_sess *sess;
if (!setup) { - WD_ERR("alloc dh sess setup NULL!\n"); + WD_ERR("invalid: alloc dh sess setup NULL!\n"); return (handle_t)0; }
@@ -483,7 +483,7 @@ handle_t wd_dh_alloc_sess(struct wd_dh_sess_setup *setup) setup->key_bits != 2048 && setup->key_bits != 3072 && setup->key_bits != 4096) { - WD_ERR("alloc dh sess key_bit %u err!\n", setup->key_bits); + WD_ERR("invalid: alloc dh sess key_bit %u is err!\n", setup->key_bits); return (handle_t)0; }
@@ -522,7 +522,7 @@ void wd_dh_free_sess(handle_t sess) struct wd_dh_sess *sess_t = (struct wd_dh_sess *)sess;
if (!sess_t) { - WD_ERR("free rsa sess param NULL!\n"); + WD_ERR("invalid: free dh sess param NULL!\n"); return; }
diff --git a/wd_ecc.c b/wd_ecc.c index d925bc3..af62b9a 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -105,14 +105,14 @@ static void wd_ecc_set_static_drv(void) { wd_ecc_setting.driver = wd_ecc_get_driver(); if (!wd_ecc_setting.driver) - WD_ERR("fail to get driver\n"); + WD_ERR("failed to get ecc driver!\n"); } #else static void __attribute__((constructor)) wd_ecc_open_driver(void) { wd_ecc_setting.dlhandle = dlopen("libhisi_hpre.so", RTLD_NOW); if (!wd_ecc_setting.dlhandle) - WD_ERR("failed to open libhisi_hpre.so\n"); + WD_ERR("failed to open libhisi_hpre.so!\n"); }
static void __attribute__((destructor)) wd_ecc_close_driver(void) @@ -125,7 +125,7 @@ static void __attribute__((destructor)) wd_ecc_close_driver(void) void wd_ecc_set_driver(struct wd_ecc_driver *drv) { if (!drv) { - WD_ERR("drv NULL\n"); + WD_ERR("invalid: ecc drv is NULL!\n"); return; }
@@ -135,12 +135,12 @@ void wd_ecc_set_driver(struct wd_ecc_driver *drv) static int init_param_check(struct wd_ctx_config *config, struct wd_sched *sched) { if (!config || !config->ctxs || !config->ctxs[0].ctx || !sched) { - WD_ERR("config or sched NULL\n"); + WD_ERR("invalid: config or sched is NULL!\n"); return -WD_EINVAL; }
if (!wd_is_sva(config->ctxs[0].ctx)) { - WD_ERR("no sva, not do ecc init\n"); + WD_ERR("invalid: the mode is non sva, please check system!\n"); return -WD_EINVAL; }
@@ -191,7 +191,7 @@ int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched) ret = wd_ecc_setting.driver->init(&wd_ecc_setting.config, priv, wd_ecc_setting.driver->alg_name); if (ret < 0) { - WD_ERR("failed to drv init, ret = %d\n", ret); + WD_ERR("failed to init ecc driver, ret = %d!\n", ret); goto out_init; }
@@ -212,7 +212,7 @@ out: void wd_ecc_uninit(void) { if (!wd_ecc_setting.priv) { - WD_ERR("repeat uninit ecc\n"); + WD_ERR("invalid: repeat uninit ecc!\n"); return; }
@@ -236,7 +236,7 @@ static int trans_to_binpad(char *dst, const char *src, int j;
if (unlikely(!dst || !src || !b_size || !d_size || b_size < d_size)) { - WD_ERR("%s: trans to hpre bin params err!\n", p_name); + WD_ERR("invalid: %s trans to hpre bin params err!\n", p_name); return -WD_EINVAL; }
@@ -265,7 +265,7 @@ static __u32 get_key_bsz(__u32 ksz) else if (ksz <= BITS_TO_BYTES(576)) size = BITS_TO_BYTES(576); else - WD_ERR("failed to get key buffer size : key size = %u.\n", ksz); + WD_ERR("invalid: get key size %u is error!\n", ksz);
return size; } @@ -386,7 +386,7 @@ static struct wd_ecc_pubkey *create_ecc_pubkey(struct wd_ecc_sess *sess) hsz = get_key_bsz(sess->key_size); pubkey = malloc(sizeof(struct wd_ecc_pubkey)); if (!pubkey) { - WD_ERR("failed to malloc!\n"); + WD_ERR("failed to malloc pubkey!\n"); return NULL; }
@@ -419,7 +419,7 @@ static struct wd_ecc_in *create_ecc_in(struct wd_ecc_sess *sess, __u32 num) __u32 hsz, len;
if (!sess->key_size || sess->key_size > ECC_MAX_KEY_SIZE) { - WD_ERR("sess key size %u error!\n", sess->key_size); + WD_ERR("invalid: sess key size %u is error!\n", sess->key_size); return NULL; }
@@ -447,7 +447,7 @@ static struct wd_ecc_in *create_sm2_sign_in(struct wd_ecc_sess *sess, __u64 len;
if (ksz != SM2_KEY_SIZE) { - WD_ERR("sess key size %u error!\n", ksz); + WD_ERR("invalid: sess key size %u is error!\n", ksz); return NULL; }
@@ -488,7 +488,7 @@ static struct wd_ecc_in *create_sm2_enc_in(struct wd_ecc_sess *sess, __u64 len;
if (ksz != SM2_KEY_SIZE) { - WD_ERR("sess key size %u error!\n", sess->key_size); + WD_ERR("invalid: sess key size %u is error!\n", sess->key_size); return NULL; }
@@ -525,7 +525,7 @@ static void *create_sm2_ciphertext(struct wd_ecc_sess *sess, __u32 m_len, void *start;
if (unlikely(ksz != SM2_KEY_SIZE)) { - WD_ERR("sess key size %u error!\n", ksz); + WD_ERR("invalid: sess key size %u is error!\n", ksz); return NULL; }
@@ -539,7 +539,7 @@ static void *create_sm2_ciphertext(struct wd_ecc_sess *sess, __u32 m_len, (__u64)m_len + (__u64)h_byts; start = malloc(*len); if (unlikely(!start)) { - WD_ERR("failed to alloc, sz = %llu!\n", *len); + WD_ERR("failed to alloc start, sz = %llu!\n", *len); return NULL; }
@@ -579,7 +579,7 @@ static struct wd_ecc_out *create_ecc_out(struct wd_ecc_sess *sess, __u32 num) __u32 hsz, len;
if (!sess->key_size || sess->key_size > ECC_MAX_KEY_SIZE) { - WD_ERR("sess key size %u error!\n", sess->key_size); + WD_ERR("invalid: sess key size %u is error!\n", sess->key_size); return NULL; }
@@ -678,12 +678,12 @@ static int set_param_single(struct wd_dtb *dst, const struct wd_dtb *src, const char *p_name) { if (unlikely(!src || !src->data)) { - WD_ERR("%s: src or data NULL!\n", p_name); + WD_ERR("invalid: %s src or data NULL!\n", p_name); return -WD_EINVAL; }
if (!src->dsize || src->dsize > dst->dsize) { - WD_ERR("%s: src dsz = %u error, dst dsz = %u!\n", + WD_ERR("invalid: %s src dsz %u or dst dsz %u is error!\n", p_name, src->dsize, dst->dsize); return -WD_EINVAL; } @@ -698,7 +698,7 @@ static int set_param_single(struct wd_dtb *dst, const struct wd_dtb *src, int wd_ecc_get_key_bits(handle_t sess) { if (!sess) { - WD_ERR("get ecc key bits, sess NULL!\n"); + WD_ERR("invalid: get ecc key bits, sess NULL!\n"); return -WD_EINVAL; }
@@ -800,7 +800,7 @@ static int fill_param_by_id(struct wd_ecc_curve *c, }
if (item->key_bits != key_bits) { - WD_ERR("curve %u and key bits %u not match!\n", id, key_bits); + WD_ERR("invalid: curve %u and key bits %u not match!\n", id, key_bits); return -WD_EINVAL; }
@@ -833,7 +833,7 @@ static int set_key_cv(struct wd_ecc_curve *dst, int ret;
if (unlikely(!src)) { - WD_ERR("set key cv: praram NULL!\n"); + WD_ERR("invalid: set key cv, praram NULL!\n"); return -WD_EINVAL; }
@@ -870,22 +870,22 @@ static int fill_user_curve_cfg(struct wd_ecc_curve *param, if (setup->cv.type == WD_CV_CFG_ID) { curve_id = setup->cv.cfg.id; ret = fill_param_by_id(param, setup->key_bits, curve_id); - dbg("set curve id %u\n", curve_id); + dbg("set curve id %u!\n", curve_id); } else if (setup->cv.type == WD_CV_CFG_PARAM) { ret = set_key_cv(param, src_param); if (ret) { WD_ERR("failed to set key cv!\n"); return ret; } - dbg("set curve by user param\n"); + dbg("set curve by user param!\n"); } else { - WD_ERR("fill curve cfg:type %u error!\n", setup->cv.type); + WD_ERR("invalid: fill curve cfg type %u is error!\n", setup->cv.type); return -WD_EINVAL; }
if (!param->p.dsize || param->p.dsize > BITS_TO_BYTES(setup->key_bits)) { - WD_ERR("fill curve cfg:dsize %u error!\n", param->p.dsize); + WD_ERR("invalid: fill curve cfg dsize %u is error!\n", param->p.dsize); return -WD_EINVAL; }
@@ -974,19 +974,19 @@ static bool is_alg_support(const char *alg) static int setup_param_check(struct wd_ecc_sess_setup *setup) { if (unlikely(!setup || !setup->alg)) { - WD_ERR("input parameter error!\n"); + WD_ERR("invalid: input parameter error!\n"); return -WD_EINVAL; }
if (unlikely(!is_alg_support(setup->alg))) { - WD_ERR("algorithms %s not supported!\n", setup->alg); + WD_ERR("invalid: algorithms %s not supported!\n", setup->alg); return -WD_EINVAL; }
setup_curve_cfg(setup);
if (unlikely(!is_key_width_support(setup->key_bits))) { - WD_ERR("key_bits %u error!\n", setup->key_bits); + WD_ERR("invalid: key_bits %u is error!\n", setup->key_bits); return -WD_EINVAL; }
@@ -1035,7 +1035,7 @@ handle_t wd_ecc_alloc_sess(struct wd_ecc_sess_setup *setup)
ret = create_sess_key(setup, sess); if (ret) { - WD_ERR("failed creat ecc sess keys!\n"); + WD_ERR("failed to creat ecc sess keys!\n"); goto sess_err; }
@@ -1061,7 +1061,7 @@ void wd_ecc_free_sess(handle_t sess) struct wd_ecc_sess *sess_t = (struct wd_ecc_sess *)sess;
if (!sess_t) { - WD_ERR("free ecc sess parameter err!\n"); + WD_ERR("invalid: free ecc sess parameter err!\n"); return; }
@@ -1076,7 +1076,7 @@ struct wd_ecc_key *wd_ecc_get_key(handle_t sess) struct wd_ecc_sess *sess_t = (struct wd_ecc_sess *)sess;
if (!sess_t) { - WD_ERR("get ecc key sess NULL!\n"); + WD_ERR("invalid: get ecc key sess NULL!\n"); return NULL; }
@@ -1091,14 +1091,14 @@ int wd_ecc_set_prikey(struct wd_ecc_key *ecc_key, int ret;
if (!ecc_key || !prikey) { - WD_ERR("set ecc prikey parameter NULL!\n"); + WD_ERR("invalid: set ecc prikey parameter NULL!\n"); return -WD_EINVAL; }
ecc_prikey = ecc_key->prikey; d = ecc_key->d; if (!ecc_prikey || !d) { - WD_ERR("ecc_prikey or d NULL!\n"); + WD_ERR("invalid: ecc_prikey or d NULL!\n"); return -WD_EINVAL; }
@@ -1113,7 +1113,7 @@ int wd_ecc_get_prikey(struct wd_ecc_key *ecc_key, struct wd_dtb **prikey) { if (!ecc_key || !prikey) { - WD_ERR("get ecc prikey parameter err!\n"); + WD_ERR("invalid: get ecc prikey parameter err!\n"); return -WD_EINVAL; }
@@ -1129,14 +1129,14 @@ int wd_ecc_set_pubkey(struct wd_ecc_key *ecc_key, struct wd_ecc_point *pubkey) int ret;
if (!ecc_key || !pubkey) { - WD_ERR("set ecc pubkey parameter err!\n"); + WD_ERR("invalid: set ecc pubkey parameter err!\n"); return -WD_EINVAL; }
pub = ecc_key->pub; ecc_pubkey = ecc_key->pubkey; if (!ecc_pubkey || !pub) { - WD_ERR("ecc_pubkey or pub NULL!\n"); + WD_ERR("invalid: ecc_pubkey or pub NULL!\n"); return -WD_EINVAL; }
@@ -1161,7 +1161,7 @@ int wd_ecc_get_pubkey(struct wd_ecc_key *ecc_key, struct wd_ecc_point **pubkey) { if (!ecc_key || !pubkey) { - WD_ERR("get ecc pubkey parameter err!\n"); + WD_ERR("invalid: get ecc pubkey parameter err!\n"); return -WD_EINVAL; }
@@ -1174,7 +1174,7 @@ int wd_ecc_get_curve(struct wd_ecc_key *ecc_key, struct wd_ecc_curve **cv) { if (!ecc_key || !cv) { - WD_ERR("get ecc pubkey parameter err!\n"); + WD_ERR("invalid: get ecc pubkey parameter err!\n"); return -WD_EINVAL; }
@@ -1192,7 +1192,7 @@ void wd_ecc_get_prikey_params(struct wd_ecc_key *key, struct wd_ecc_prikey *prk;
if (!key || !key->prikey) { - WD_ERR("input NULL in get ecc prikey param!\n"); + WD_ERR("invalid: input NULL in get ecc prikey param!\n"); return; }
@@ -1226,7 +1226,7 @@ void wd_ecc_get_pubkey_params(struct wd_ecc_key *key, struct wd_ecc_pubkey *pbk;
if (!key || !key->pubkey) { - WD_ERR("input NULL in get ecc pubkey param!\n"); + WD_ERR("invalid: input NULL in get ecc pubkey param!\n"); return; }
@@ -1259,7 +1259,7 @@ struct wd_ecc_in *wd_ecxdh_new_in(handle_t sess, struct wd_ecc_point *in) int ret;
if (!s || !in) { - WD_ERR("new ecc dh in parameter error!\n"); + WD_ERR("invalid: new ecc dh in parameter error!\n"); return NULL; }
@@ -1288,7 +1288,7 @@ struct wd_ecc_out *wd_ecxdh_new_out(handle_t sess) struct wd_ecc_out *ecc_out;
if (!sess) { - WD_ERR("new ecc dh out sess NULL!\n"); + WD_ERR("invalid: new ecc dh out sess NULL!\n"); return NULL; }
@@ -1304,7 +1304,7 @@ void wd_ecxdh_get_out_params(struct wd_ecc_out *out, struct wd_ecc_point **key) struct wd_ecc_dh_out *dh_out = (void *)out;
if (!dh_out) { - WD_ERR("input NULL in get ecdh out!\n"); + WD_ERR("invalid: input NULL in get ecdh out!\n"); return; }
@@ -1317,13 +1317,13 @@ void wd_ecc_del_in(handle_t sess, struct wd_ecc_in *in) __u32 bsz;
if (!in) { - WD_ERR("del ecc in parameter error!\n"); + WD_ERR("invalid: del ecc in parameter error!\n"); return; }
bsz = in->size; if (!bsz) { - WD_ERR("del ecc in: bsz 0!\n"); + WD_ERR("invalid: del ecc in, bsz 0!\n"); return; }
@@ -1336,13 +1336,13 @@ void wd_ecc_del_out(handle_t sess, struct wd_ecc_out *out) __u32 bsz;
if (!out) { - WD_ERR("del ecc out parameter error!\n"); + WD_ERR("invalid: del ecc out parameter error!\n"); return; }
bsz = out->size; if (!bsz) { - WD_ERR("del ecc out: bsz 0!\n"); + WD_ERR("invalid: del ecc out, bsz 0!\n"); return; }
@@ -1374,7 +1374,7 @@ static int fill_ecc_msg(struct wd_ecc_msg *msg, struct wd_ecc_req *req, key = &sess->key; break; default: - WD_ERR("ecc request op type = %u error!\n", req->op_type); + WD_ERR("invalid: ecc request op type %u is error!\n", req->op_type); return -WD_EINVAL; } msg->key = key; @@ -1390,7 +1390,7 @@ static int fill_ecc_msg(struct wd_ecc_msg *msg, struct wd_ecc_req *req,
if (!msg->req.src || (!req->dst && (req->op_type != WD_ECDSA_VERIFY && req->op_type != WD_SM2_VERIFY))) { - WD_ERR("req in/out NULL!\n"); + WD_ERR("invalid: req in/out NULL!\n"); return -WD_EINVAL; }
@@ -1468,7 +1468,7 @@ int wd_do_ecc_sync(handle_t h_sess, struct wd_ecc_req *req) int ret;
if (unlikely(!h_sess || !req)) { - WD_ERR("input parameter NULL!\n"); + WD_ERR("invalid: input parameter NULL!\n"); return -WD_EINVAL; }
@@ -1504,7 +1504,7 @@ static void get_sign_out_params(struct wd_ecc_out *out, struct wd_ecc_sign_out *sout = (void *)out;
if (!sout) { - WD_ERR("input NULL in get ecc sign out!\n"); + WD_ERR("invalid: input NULL in get ecc sign out!\n"); return; }
@@ -1556,7 +1556,7 @@ static int generate_random(struct wd_ecc_sess *sess, struct wd_dtb *k)
ret = rand_t.cb(k->data, k->dsize, rand_t.usr); if (ret) - WD_ERR("failed to rand cb: ret = %d!\n", ret); + WD_ERR("failed to do rand cb, ret = %d!\n", ret);
return ret; } @@ -1580,7 +1580,7 @@ static int sm2_compute_za_hash(__u8 *za, __u32 *len, struct wd_dtb *id,
if (id && (!BYTES_TO_BITS(id->dsize) || !id->data || BYTES_TO_BITS(id->dsize) > UINT16_MAX)) { - WD_ERR("id error: lens = %u!\n", id->dsize); + WD_ERR("invalid: id error, lens = %u!\n", id->dsize); return -WD_EINVAL; }
@@ -1633,7 +1633,7 @@ static int sm2_compute_digest(struct wd_ecc_sess *sess, struct wd_dtb *hash_msg,
hash_bytes = get_hash_bytes(hash->type); if (unlikely(!hash_bytes || hash_bytes > SM2_KEY_SIZE)) { - WD_ERR("hash type = %hhu error!\n", hash->type); + WD_ERR("invalid: hash type %hhu is error!\n", hash->type); return -WD_EINVAL; }
@@ -1675,7 +1675,7 @@ static struct wd_ecc_in *new_sign_in(struct wd_ecc_sess *sess, int ret;
if (!sess || !e) { - WD_ERR("failed to new ecc sign in: sess or e NULL!\n"); + WD_ERR("invalid: new ecc sign in, sess or e NULL!\n"); return NULL; }
@@ -1758,7 +1758,7 @@ static struct wd_ecc_in *create_sm2_verf_in(struct wd_ecc_sess *sess, __u32 hsz;
if (sess->key_size != SM2_KEY_SIZE) { - WD_ERR("sess key size %u error!\n", sess->key_size); + WD_ERR("invalid: sess key size %u is error!\n", sess->key_size); return NULL; }
@@ -1820,7 +1820,7 @@ static struct wd_ecc_in *new_verf_in(handle_t sess, int ret;
if (!sess_t || !r || !e || !s) { - WD_ERR("new ecc verf in parameter error!\n"); + WD_ERR("invalid: new ecc verf in parameter error!\n"); return NULL; }
@@ -1879,7 +1879,7 @@ static struct wd_ecc_out *wd_ecc_new_sign_out(struct wd_ecc_sess *sess) struct wd_ecc_out *ecc_out;
if (!sess) { - WD_ERR("new ecc sout ctx NULL!\n"); + WD_ERR("invalid: new ecc sout ctx NULL!\n"); return NULL; }
@@ -1900,7 +1900,7 @@ struct wd_ecc_out *wd_sm2_new_kg_out(handle_t sess) struct wd_ecc_out *ecc_out;
if (!sess) { - WD_ERR("new sm2 kg out sess NULL!\n"); + WD_ERR("invalid: new sm2 kg out sess NULL!\n"); return NULL; }
@@ -1919,7 +1919,7 @@ void wd_sm2_get_kg_out_params(struct wd_ecc_out *out, struct wd_sm2_kg_out *kout = (void *)out;
if (!kout) { - WD_ERR("input NULL in get sm2 kg out!\n"); + WD_ERR("invalid: input NULL in get sm2 kg out!\n"); return; }
@@ -1940,7 +1940,7 @@ struct wd_ecc_in *wd_sm2_new_enc_in(handle_t sess, int ret;
if (!sess_t || !plaintext) { - WD_ERR("new sm2 enc in parameter error!\n"); + WD_ERR("invalid: new sm2 enc in parameter error!\n"); return NULL; }
@@ -1991,7 +1991,7 @@ struct wd_ecc_in *wd_sm2_new_dec_in(handle_t sess, int ret;
if (!sess_t || !c1 || !c2 || !c3) { - WD_ERR("new sm2 dec in parameter error!\n"); + WD_ERR("invalid: new sm2 dec in parameter error!\n"); return NULL; }
@@ -2035,7 +2035,7 @@ struct wd_ecc_out *wd_sm2_new_enc_out(handle_t sess, __u32 plaintext_len) __u64 len = 0;
if (!sess_t) { - WD_ERR("new ecc sout sess NULL!\n"); + WD_ERR("invalid: new ecc sout sess NULL!\n"); return NULL; }
@@ -2090,7 +2090,7 @@ void wd_sm2_get_enc_out_params(struct wd_ecc_out *out, struct wd_sm2_enc_out *eout = (void *)out;
if (!eout) { - WD_ERR("input NULL in get sm2 enc out!\n"); + WD_ERR("invalid: input NULL in get sm2 enc out!\n"); return; }
@@ -2110,7 +2110,7 @@ void wd_sm2_get_dec_out_params(struct wd_ecc_out *out, struct wd_sm2_dec_out *dout = (void *)out;
if (!dout) { - WD_ERR("input NULL in get sm2 dec out!\n"); + WD_ERR("invalid: input NULL in get sm2 dec out!\n"); return; }
@@ -2156,7 +2156,7 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req) int idx;
if (unlikely(!req || !sess || !req->cb)) { - WD_ERR("input parameter NULL!\n"); + WD_ERR("invalid: input parameter NULL!\n"); return -WD_EINVAL; }
@@ -2207,7 +2207,7 @@ int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count) int ret;
if (unlikely(!count)) { - WD_ERR("param count is NULL!"); + WD_ERR("invalid: param count is NULL!\n"); return -WD_EINVAL; }
@@ -2234,7 +2234,7 @@ int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count) msg = wd_find_msg_in_pool(&wd_ecc_setting.pool, idx, recv_msg.tag); if (!msg) { - WD_ERR("get msg from pool is NULL!\n"); + WD_ERR("failed to get msg from pool!\n"); return -WD_EINVAL; }
diff --git a/wd_rsa.c b/wd_rsa.c index 8fc405f..8371475 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -91,14 +91,14 @@ static void wd_rsa_set_static_drv(void) { wd_rsa_setting.driver = wd_rsa_get_driver(); if (!wd_rsa_setting.driver) - WD_ERR("fail to get driver\n"); + WD_ERR("failed to get rsa driver!\n"); } #else static void __attribute__((constructor)) wd_rsa_open_driver(void) { wd_rsa_setting.dlhandle = dlopen("libhisi_hpre.so", RTLD_NOW); if (!wd_rsa_setting.dlhandle) - WD_ERR("Fail to open libhisi_hpre.so\n"); + WD_ERR("failed to open libhisi_hpre.so!\n"); }
static void __attribute__((destructor)) wd_rsa_close_driver(void) @@ -111,7 +111,7 @@ static void __attribute__((destructor)) wd_rsa_close_driver(void) void wd_rsa_set_driver(struct wd_rsa_driver *drv) { if (!drv) { - WD_ERR("drv NULL\n"); + WD_ERR("invalid: rsa drv is NULL!\n"); return; }
@@ -121,12 +121,12 @@ void wd_rsa_set_driver(struct wd_rsa_driver *drv) static int param_check(struct wd_ctx_config *config, struct wd_sched *sched) { if (!config || !config->ctxs[0].ctx || !sched) { - WD_ERR("config or sched NULL\n"); + WD_ERR("invalid: config or sched NULL!\n"); return -WD_EINVAL; }
if (!wd_is_sva(config->ctxs[0].ctx)) { - WD_ERR("no sva, do not rsa init\n"); + WD_ERR("invalid: the mode is non sva, please check system!\n"); return -WD_EINVAL; }
@@ -177,7 +177,7 @@ int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched) ret = wd_rsa_setting.driver->init(&wd_rsa_setting.config, priv, wd_rsa_setting.driver->alg_name); if (ret < 0) { - WD_ERR("failed to drv init, ret = %d\n", ret); + WD_ERR("failed to init rsa driver, ret = %d!\n", ret); goto out_init; }
@@ -198,7 +198,7 @@ out: void wd_rsa_uninit(void) { if (!wd_rsa_setting.priv) { - WD_ERR("repeat uninit rsa\n"); + WD_ERR("invalid: repeat uninit rsa!\n"); return; }
@@ -240,24 +240,24 @@ static int fill_rsa_msg(struct wd_rsa_msg *msg, struct wd_rsa_req *req, key = (__u8 *)req->src; break; default: - WD_ERR("rsa msguest op type err!\n"); + WD_ERR("invalid: rsa msg req op type %u is err!\n", msg->req.op_type); return -WD_EINVAL; }
if (unlikely(!key)) { - WD_ERR("rsa msguest key null!\n"); + WD_ERR("invalid: rsa msg key null!\n"); return -WD_EINVAL; }
if (msg->req.op_type == WD_RSA_SIGN || msg->req.op_type == WD_RSA_VERIFY) { if (unlikely(msg->req.src_bytes != sess->key_size)) { - WD_ERR("sign or verf src_bytes != key_size!\n"); + WD_ERR("invalid: sign or verf src_bytes != key_size!\n"); return -WD_EINVAL; }
if (unlikely(req->dst_bytes != sess->key_size)) { - WD_ERR("req dst bytes = %hu error!\n", req->dst_bytes); + WD_ERR("invalid: req dst bytes %hu is error!\n", req->dst_bytes); return -WD_EINVAL; } } @@ -329,7 +329,7 @@ int wd_do_rsa_sync(handle_t h_sess, struct wd_rsa_req *req) int ret;
if (unlikely(!h_sess || !req)) { - WD_ERR("input param NULL!\n"); + WD_ERR("invalid: input param NULL!\n"); return -WD_EINVAL; }
@@ -370,7 +370,7 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req) __u32 idx;
if (unlikely(!req || !sess || !req->cb)) { - WD_ERR("input param NULL!\n"); + WD_ERR("invalid: input param NULL!\n"); return -WD_EINVAL; }
@@ -417,7 +417,7 @@ int wd_rsa_poll_ctx(__u32 idx, __u32 expt, __u32 *count) int ret;
if (unlikely(!count)) { - WD_ERR("param count is NULL!"); + WD_ERR("invalid: param count is NULL!\n"); return -WD_EINVAL; }
@@ -443,7 +443,7 @@ int wd_rsa_poll_ctx(__u32 idx, __u32 expt, __u32 *count) msg = wd_find_msg_in_pool(&wd_rsa_setting.pool, idx, recv_msg.tag); if (!msg) { - WD_ERR("get msg from pool is NULL!\n"); + WD_ERR("failed to get msg from pool!\n"); return -WD_EINVAL; }
@@ -468,7 +468,7 @@ int wd_rsa_poll(__u32 expt, __u32 *count) int wd_rsa_kg_in_data(struct wd_rsa_kg_in *ki, char **data) { if (!ki || !data) { - WD_ERR("param is NULL!\n"); + WD_ERR("invalid: param is NULL!\n"); return -WD_EINVAL; }
@@ -479,7 +479,7 @@ int wd_rsa_kg_in_data(struct wd_rsa_kg_in *ki, char **data) int wd_rsa_kg_out_data(struct wd_rsa_kg_out *ko, char **data) { if (!ko || !data) { - WD_ERR("param is NULL!\n"); + WD_ERR("invalid: param is NULL!\n"); return -WD_EINVAL; }
@@ -497,32 +497,32 @@ struct wd_rsa_kg_in *wd_rsa_new_kg_in(handle_t sess, struct wd_dtb *e, int kg_in_size;
if (!c || !e || !p || !q) { - WD_ERR("sess malloc kg_in memory fail!\n"); + WD_ERR("invalid: sess malloc kg_in memory params err!\n"); return NULL; }
if (!c->key_size || c->key_size > RSA_MAX_KEY_SIZE) { - WD_ERR("key size err at create kg in!\n"); + WD_ERR("invalid: key size err at create kg in!\n"); return NULL; }
if (!e->dsize || e->dsize > c->key_size) { - WD_ERR("e para err at create kg in!\n"); + WD_ERR("invalid: e para err at create kg in!\n"); return NULL; } if (!p->dsize || p->dsize > CRT_PARAM_SZ(c->key_size)) { - WD_ERR("p para err at create kg in!\n"); + WD_ERR("invalid: p para err at create kg in!\n"); return NULL; } if (!q->dsize || q->dsize > CRT_PARAM_SZ(c->key_size)) { - WD_ERR("q para err at create kg in!\n"); + WD_ERR("invalid: q para err at create kg in!\n"); return NULL; }
kg_in_size = GEN_PARAMS_SZ(c->key_size); kg_in = malloc(kg_in_size + sizeof(*kg_in)); if (!kg_in) { - WD_ERR("sess malloc kg_in memory fail!\n"); + WD_ERR("failed to malloc kg_in memory!\n"); return NULL; } memset(kg_in, 0, kg_in_size + sizeof(*kg_in)); @@ -545,7 +545,7 @@ void wd_rsa_get_kg_in_params(struct wd_rsa_kg_in *kin, struct wd_dtb *e, struct wd_dtb *q, struct wd_dtb *p) { if (!kin || !e || !q || !p) { - WD_ERR("para err at get input parameters key generate !\n"); + WD_ERR("invalid: para err at get input parameters key generate!\n"); return; }
@@ -563,7 +563,7 @@ void wd_rsa_get_kg_in_params(struct wd_rsa_kg_in *kin, struct wd_dtb *e, static void del_kg(void *k) { if (!k) { - WD_ERR("del key generate params err!\n"); + WD_ERR("invalid: del key generate params err!\n"); return; }
@@ -583,13 +583,13 @@ struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess) __u32 kz;
if (!c) { - WD_ERR("sess null at new rsa key gen out!\n"); + WD_ERR("invalid: sess null at new rsa key gen out!\n"); return NULL; }
kz = c->key_size; if (!kz || kz > RSA_MAX_KEY_SIZE) { - WD_ERR("new kg out key size error!\n"); + WD_ERR("invalid: new kg out key size error!\n"); return NULL; }
@@ -600,7 +600,7 @@ struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess)
kg_out = malloc(kg_out_size + sizeof(*kg_out)); if (!kg_out) { - WD_ERR("sess malloc kg_out memory fail!\n"); + WD_ERR("failed to malloc kg_out memory!\n"); return NULL; }
@@ -621,7 +621,7 @@ struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess) void wd_rsa_del_kg_out(handle_t sess, struct wd_rsa_kg_out *kout) { if (!kout) { - WD_ERR("param null at del kg out!\n"); + WD_ERR("invalid: param null at del kg out!\n"); return; }
@@ -633,7 +633,7 @@ void wd_rsa_get_kg_out_params(struct wd_rsa_kg_out *kout, struct wd_dtb *d, struct wd_dtb *n) { if (!kout) { - WD_ERR("input null at get key gen params!\n"); + WD_ERR("invalid: input null at get key gen params!\n"); return; }
@@ -655,7 +655,7 @@ void wd_rsa_get_kg_out_crt_params(struct wd_rsa_kg_out *kout, struct wd_dtb *dq, struct wd_dtb *dp) { if (!kout || !qinv || !dq || !dp) { - WD_ERR("input null at get key gen crt para!\n"); + WD_ERR("invalid: input null at get key gen crt para!\n"); return; }
@@ -743,7 +743,7 @@ static int create_sess_key(struct wd_rsa_sess_setup *setup, CRT_PARAMS_SZ(sess->key_size); sess->prikey = malloc(len); if (!sess->prikey) { - WD_ERR("alloc prikey2 fail!\n"); + WD_ERR("failed to alloc sess prikey2!\n"); return -WD_ENOMEM; } pkey2 = &sess->prikey->pkey2; @@ -754,7 +754,7 @@ static int create_sess_key(struct wd_rsa_sess_setup *setup, GEN_PARAMS_SZ(sess->key_size); sess->prikey = malloc(len); if (!sess->prikey) { - WD_ERR("alloc prikey1 fail!\n"); + WD_ERR("failed to alloc sess prikey1!\n"); return -WD_ENOMEM; } pkey1 = &sess->prikey->pkey1; @@ -767,7 +767,7 @@ static int create_sess_key(struct wd_rsa_sess_setup *setup, sess->pubkey = malloc(len); if (!sess->pubkey) { free(sess->prikey); - WD_ERR("alloc pubkey fail!\n"); + WD_ERR("failed to alloc sess pubkey!\n"); return -WD_ENOMEM; }
@@ -783,7 +783,7 @@ static void del_sess_key(struct wd_rsa_sess *sess) struct wd_rsa_pubkey *pub = sess->pubkey;
if (!prk || !pub) { - WD_ERR("del sess key error: prk or pub NULL\n"); + WD_ERR("invalid: del sess key error, prk or pub NULL!\n"); return; }
@@ -808,7 +808,7 @@ handle_t wd_rsa_alloc_sess(struct wd_rsa_sess_setup *setup) int ret;
if (!setup) { - WD_ERR("alloc rsa sess setup NULL!\n"); + WD_ERR("invalid: alloc rsa sess setup NULL!\n"); return(handle_t)0; }
@@ -816,7 +816,7 @@ handle_t wd_rsa_alloc_sess(struct wd_rsa_sess_setup *setup) setup->key_bits != 2048 && setup->key_bits != 3072 && setup->key_bits != 4096) { - WD_ERR("alloc rsa sess key_bit %u err!\n", setup->key_bits); + WD_ERR("invalid: alloc rsa sess key_bit %u err!\n", setup->key_bits); return (handle_t)0; }
@@ -829,7 +829,7 @@ handle_t wd_rsa_alloc_sess(struct wd_rsa_sess_setup *setup)
ret = create_sess_key(setup, sess); if (ret) { - WD_ERR("fail creating rsa sess keys!\n"); + WD_ERR("failed to create rsa sess keys!\n"); goto sess_err; }
@@ -855,7 +855,7 @@ void wd_rsa_free_sess(handle_t sess) struct wd_rsa_sess *sess_t = (struct wd_rsa_sess *)sess;
if (!sess_t) { - WD_ERR("free rsa sess param err!\n"); + WD_ERR("invalid: free rsa sess param err!\n"); return; }
@@ -869,7 +869,7 @@ void wd_rsa_free_sess(handle_t sess) bool wd_rsa_is_crt(handle_t sess) { if (!sess) { - WD_ERR("rsa is crt judge, sess NULL, return false!\n"); + WD_ERR("invalid: rsa is crt judge, sess NULL, return false!\n"); return false; }
@@ -879,7 +879,7 @@ bool wd_rsa_is_crt(handle_t sess) __u32 wd_rsa_get_key_bits(handle_t sess) { if (!sess) { - WD_ERR("get rsa key bits, sess NULL!\n"); + WD_ERR("invalid: get rsa key bits, sess NULL!\n"); return 0; }
@@ -891,13 +891,13 @@ int wd_rsa_set_pubkey_params(handle_t sess, struct wd_dtb *e, struct wd_dtb *n) struct wd_rsa_sess *c = (struct wd_rsa_sess *)sess;
if (!c || !c->pubkey || !c->pubkey->key_size) { - WD_ERR("sess NULL in set rsa public key!\n"); + WD_ERR("invalid: sess NULL in set rsa public key!\n"); return -WD_EINVAL; }
if (e) { if (!e->dsize || !e->data || e->dsize > c->pubkey->key_size) { - WD_ERR("e err in set rsa public key!\n"); + WD_ERR("invalid: e err in set rsa public key!\n"); return -WD_EINVAL; }
@@ -908,7 +908,7 @@ int wd_rsa_set_pubkey_params(handle_t sess, struct wd_dtb *e, struct wd_dtb *n)
if (n) { if (!n->dsize || !n->data || n->dsize > c->pubkey->key_size) { - WD_ERR("n err in set rsa public key!\n"); + WD_ERR("invalid: n err in set rsa public key!\n"); return -WD_EINVAL; }
@@ -924,7 +924,7 @@ void wd_rsa_get_pubkey_params(struct wd_rsa_pubkey *pbk, struct wd_dtb **e, struct wd_dtb **n) { if (!pbk) { - WD_ERR("input NULL in get rsa public key!\n"); + WD_ERR("invalid: input NULL in get rsa public key!\n"); return; } if (e) @@ -940,13 +940,13 @@ int wd_rsa_set_prikey_params(handle_t sess, struct wd_dtb *d, struct wd_dtb *n) struct wd_rsa_sess *c = (struct wd_rsa_sess *)sess;
if (!c || wd_rsa_is_crt(sess) || !c->prikey) { - WD_ERR("sess err in set rsa private key1!\n"); + WD_ERR("invalid: sess err in set rsa private key1!\n"); return -WD_EINVAL; } pkey1 = &c->prikey->pkey1; if (d) { if (!d->dsize || !d->data || d->dsize > pkey1->key_size) { - WD_ERR("d err in set rsa private key1!\n"); + WD_ERR("invalid: d err in set rsa private key1!\n"); return -WD_EINVAL; }
@@ -956,7 +956,7 @@ int wd_rsa_set_prikey_params(handle_t sess, struct wd_dtb *d, struct wd_dtb *n) } if (n) { if (!n->dsize || !n->data || n->dsize > pkey1->key_size) { - WD_ERR("en err in set rsa private key1!\n"); + WD_ERR("invalid: en err in set rsa private key1!\n"); return -WD_EINVAL; }
@@ -974,7 +974,7 @@ void wd_rsa_get_prikey_params(struct wd_rsa_prikey *pvk, struct wd_dtb **d, struct wd_rsa_prikey1 *pkey1;
if (!pvk) { - WD_ERR("pvk is NULL!\n"); + WD_ERR("invalid: pvk is NULL!\n"); return; }
@@ -1041,43 +1041,43 @@ int wd_rsa_set_crt_prikey_params(handle_t sess, struct wd_dtb *dq, int ret = -WD_EINVAL;
if (!sess || !wd_rsa_is_crt(sess)) { - WD_ERR("sess err in set rsa crt private key2!\n"); + WD_ERR("invalid: sess err in set rsa crt private key2!\n"); return ret; }
if (!dq || !dp || !qinv || !q || !p) { - WD_ERR("para err in set rsa crt private key2!\n"); + WD_ERR("invalid: para err in set rsa crt private key2!\n"); return ret; }
pkey2 = &c->prikey->pkey2; ret = rsa_prikey2_param_set(pkey2, dq, WD_CRT_PRIKEY_DQ); if (ret) { - WD_ERR("dq err in set rsa private key2!\n"); + WD_ERR("failed to set dq for rsa private key2!\n"); return ret; }
ret = rsa_prikey2_param_set(pkey2, dp, WD_CRT_PRIKEY_DP); if (ret) { - WD_ERR("dp err in set rsa private key2!\n"); + WD_ERR("failed to set dp for rsa private key2!\n"); return ret; }
ret = rsa_prikey2_param_set(pkey2, qinv, WD_CRT_PRIKEY_QINV); if (ret) { - WD_ERR("qinv err in set rsa private key2!\n"); + WD_ERR("failed to set qinv for rsa private key2!\n"); return ret; }
ret = rsa_prikey2_param_set(pkey2, q, WD_CRT_PRIKEY_Q); if (ret) { - WD_ERR("q err in set rsa private key2!\n"); + WD_ERR("failed to set q for rsa private key2!\n"); return ret; }
ret = rsa_prikey2_param_set(pkey2, p, WD_CRT_PRIKEY_P); if (ret) { - WD_ERR("p err in set rsa private key2!\n"); + WD_ERR("failed to set p for rsa private key2!\n"); return ret; }
@@ -1092,7 +1092,7 @@ void wd_rsa_get_crt_prikey_params(struct wd_rsa_prikey *pvk, struct wd_rsa_prikey2 *pkey2;
if (!pvk) { - WD_ERR("pvk is NULL!\n"); + WD_ERR("invalid: pvk is NULL!\n"); return; }
@@ -1113,7 +1113,7 @@ void wd_rsa_get_crt_prikey_params(struct wd_rsa_prikey *pvk, void wd_rsa_get_pubkey(handle_t sess, struct wd_rsa_pubkey **pubkey) { if (!sess || !pubkey) { - WD_ERR("param is NULL!\n"); + WD_ERR("invalid: param is NULL!\n"); return; }
@@ -1123,7 +1123,7 @@ void wd_rsa_get_pubkey(handle_t sess, struct wd_rsa_pubkey **pubkey) void wd_rsa_get_prikey(handle_t sess, struct wd_rsa_prikey **prikey) { if (!sess || !prikey) { - WD_ERR("param is NULL!\n"); + WD_ERR("invalid: param is NULL!\n"); return; }
From: Weili Qian qianweili@huawei.com
When BD fails to send to the hardware, the requested memory needs to be freed.
Signed-off-by: Weili Qian qianweili@huawei.com --- drv/hisi_hpre.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index 11ef78b..e46efef 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -1699,7 +1699,11 @@ static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg) goto fail_fill_sqe; }
- return hisi_qm_send(h_qp, &hw_msg, SM2_SQE_NUM, &send_cnt); + ret = hisi_qm_send(h_qp, &hw_msg, SM2_SQE_NUM, &send_cnt); + if (unlikely(ret)) + goto fail_fill_sqe; + + return ret;
fail_fill_sqe: free_req(msg_dst[0]); @@ -1713,6 +1717,7 @@ static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg) struct wd_sm2_dec_in *din = (void *)msg->req.src; struct wd_hash_mt *hash = &msg->hash; struct wd_ecc_msg *dst; + int ret;
/* c2 data lens <= 4096 bit */ if (din->c2.dsize <= BITS_TO_BYTES(4096) && @@ -1739,11 +1744,21 @@ static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg) /* dst->req.dst last store point "struct wd_ecc_msg *" */ dst->req.dst = create_ecdh_out(dst); if (unlikely(!dst->req.dst)) { - free(dst); - return -WD_ENOMEM; + ret = -WD_ENOMEM; + goto free_dst; }
- return ecc_general_send(ctx, dst); + ret = ecc_general_send(ctx, dst); + if (unlikely(ret)) + goto free_req_dst; + + return ret; + +free_req_dst: + free(dst->req.dst); +free_dst: + free(dst); + return ret; }
static int ecc_send(handle_t ctx, struct wd_ecc_msg *msg)