206 lines
5.6 KiB
Diff
206 lines
5.6 KiB
Diff
From 5b59c17f84d5a1f6e7c996a499f5a70059d89ee7 Mon Sep 17 00:00:00 2001
|
|
From: Zhiqi Song <songzhiqi1@huawei.com>
|
|
Date: Sat, 22 Oct 2022 15:35:17 +0800
|
|
Subject: uadk_engine: bugfix side effects of right operand
|
|
|
|
The right operand of while condition may contains side effects,
|
|
variables change "rx_cnt++". Move 'rx_cnt++' from condition
|
|
to statement.
|
|
|
|
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
|
|
---
|
|
src/uadk_cipher.c | 13 ++++++++-----
|
|
src/uadk_dh.c | 18 +++++++++++-------
|
|
src/uadk_digest.c | 13 ++++++++-----
|
|
src/uadk_pkey.c | 13 ++++++++-----
|
|
src/uadk_rsa.c | 14 +++++++++-----
|
|
5 files changed, 44 insertions(+), 27 deletions(-)
|
|
|
|
diff --git a/src/uadk_cipher.c b/src/uadk_cipher.c
|
|
index 8e8c5f3..9d4f692 100644
|
|
--- a/src/uadk_cipher.c
|
|
+++ b/src/uadk_cipher.c
|
|
@@ -516,11 +516,13 @@ static int uadk_e_cipher_poll(void *ctx)
|
|
|
|
do {
|
|
ret = wd_cipher_poll_ctx(idx, expt, &recv);
|
|
- if (recv == expt)
|
|
+ if (!ret && recv == expt)
|
|
return 0;
|
|
- else if (ret < 0 && ret != -EAGAIN)
|
|
- return ret;
|
|
- } while (ret == -EAGAIN && (rx_cnt++ < ENGINE_RECV_MAX_CNT));
|
|
+ else if (ret == -EAGAIN)
|
|
+ rx_cnt++;
|
|
+ else
|
|
+ return -1;
|
|
+ } while (rx_cnt < ENGINE_RECV_MAX_CNT);
|
|
|
|
fprintf(stderr, "failed to recv msg: timeout!\n");
|
|
|
|
@@ -539,7 +541,8 @@ static int uadk_e_cipher_env_poll(void *ctx)
|
|
ret = wd_cipher_poll(expt, &recv);
|
|
if (ret < 0 || recv == expt)
|
|
return ret;
|
|
- } while (rx_cnt++ < ENGINE_RECV_MAX_CNT);
|
|
+ rx_cnt++;
|
|
+ } while (rx_cnt < ENGINE_RECV_MAX_CNT);
|
|
|
|
fprintf(stderr, "failed to poll msg: timeout!\n");
|
|
|
|
diff --git a/src/uadk_dh.c b/src/uadk_dh.c
|
|
index 37f84e9..2af2455 100644
|
|
--- a/src/uadk_dh.c
|
|
+++ b/src/uadk_dh.c
|
|
@@ -48,6 +48,7 @@
|
|
#define UADK_E_SUCCESS 1
|
|
#define UADK_E_FAIL 0
|
|
#define UADK_E_POLL_SUCCESS 0
|
|
+#define UADK_E_POLL_FAIL (-1)
|
|
#define UADK_E_INIT_SUCCESS 0
|
|
#define ENV_ENABLED 1
|
|
|
|
@@ -206,17 +207,19 @@ static int uadk_e_dh_poll(void *ctx)
|
|
{
|
|
__u64 rx_cnt = 0;
|
|
__u32 recv = 0;
|
|
- int expect = 1;
|
|
+ int expt = 1;
|
|
int idx = 1;
|
|
int ret;
|
|
|
|
do {
|
|
- ret = wd_dh_poll_ctx(idx, expect, &recv);
|
|
- if (recv == expect)
|
|
+ ret = wd_dh_poll_ctx(idx, expt, &recv);
|
|
+ if (!ret && recv == expt)
|
|
return UADK_E_POLL_SUCCESS;
|
|
- else if (ret < 0 && ret != -EAGAIN)
|
|
- return ret;
|
|
- } while (ret == -EAGAIN && (rx_cnt++ < ENGINE_RECV_MAX_CNT));
|
|
+ else if (ret == -EAGAIN)
|
|
+ rx_cnt++;
|
|
+ else
|
|
+ return UADK_E_POLL_FAIL;
|
|
+ } while (rx_cnt < ENGINE_RECV_MAX_CNT);
|
|
|
|
fprintf(stderr, "failed to recv msg: timeout!\n");
|
|
|
|
@@ -283,7 +286,8 @@ static int uadk_e_dh_env_poll(void *ctx)
|
|
ret = wd_dh_poll(expt, &recv);
|
|
if (ret < 0 || recv == expt)
|
|
return ret;
|
|
- } while (rx_cnt++ < ENGINE_RECV_MAX_CNT);
|
|
+ rx_cnt++;
|
|
+ } while (rx_cnt < ENGINE_RECV_MAX_CNT);
|
|
|
|
fprintf(stderr, "failed to poll msg: timeout!\n");
|
|
|
|
diff --git a/src/uadk_digest.c b/src/uadk_digest.c
|
|
index 8370490..9568a98 100644
|
|
--- a/src/uadk_digest.c
|
|
+++ b/src/uadk_digest.c
|
|
@@ -343,11 +343,13 @@ static int uadk_e_digest_poll(void *ctx)
|
|
|
|
do {
|
|
ret = wd_digest_poll_ctx(CTX_ASYNC, expt, &recv);
|
|
- if (recv == expt)
|
|
+ if (!ret && recv == expt)
|
|
return 0;
|
|
- else if (ret < 0 && ret != -EAGAIN)
|
|
- return ret;
|
|
- } while (ret == -EAGAIN && (rx_cnt++ < ENGINE_RECV_MAX_CNT));
|
|
+ else if (ret == -EAGAIN)
|
|
+ rx_cnt++;
|
|
+ else
|
|
+ return -1;
|
|
+ } while (rx_cnt < ENGINE_RECV_MAX_CNT);
|
|
|
|
fprintf(stderr, "failed to recv msg: timeout!\n");
|
|
|
|
@@ -366,7 +368,8 @@ static int uadk_e_digest_env_poll(void *ctx)
|
|
ret = wd_digest_poll(expt, &recv);
|
|
if (ret < 0 || recv == expt)
|
|
return ret;
|
|
- } while (rx_cnt++ < ENGINE_RECV_MAX_CNT);
|
|
+ rx_cnt++;
|
|
+ } while (rx_cnt < ENGINE_RECV_MAX_CNT);
|
|
|
|
fprintf(stderr, "failed to poll msg: timeout!\n");
|
|
|
|
diff --git a/src/uadk_pkey.c b/src/uadk_pkey.c
|
|
index 211f1cc..6920cff 100644
|
|
--- a/src/uadk_pkey.c
|
|
+++ b/src/uadk_pkey.c
|
|
@@ -110,11 +110,13 @@ static int uadk_ecc_poll(void *ctx)
|
|
|
|
do {
|
|
ret = wd_ecc_poll_ctx(CTX_ASYNC, expt, &recv);
|
|
- if (recv == expt)
|
|
+ if (!ret && recv == expt)
|
|
return 0;
|
|
- else if (ret < 0 && ret != -EAGAIN)
|
|
- return ret;
|
|
- } while (ret == -EAGAIN && (rx_cnt++ < ENGINE_RECV_MAX_CNT));
|
|
+ else if (ret == -EAGAIN)
|
|
+ rx_cnt++;
|
|
+ else
|
|
+ return -1;
|
|
+ } while (rx_cnt < ENGINE_RECV_MAX_CNT);
|
|
|
|
fprintf(stderr, "failed to recv msg: timeout!\n");
|
|
|
|
@@ -153,7 +155,8 @@ static int uadk_e_ecc_env_poll(void *ctx)
|
|
ret = wd_ecc_poll(expt, &recv);
|
|
if (ret < 0 || recv == expt)
|
|
return ret;
|
|
- } while (rx_cnt++ < ENGINE_RECV_MAX_CNT);
|
|
+ rx_cnt++;
|
|
+ } while (rx_cnt < ENGINE_RECV_MAX_CNT);
|
|
|
|
fprintf(stderr, "failed to poll msg: timeout!\n");
|
|
|
|
diff --git a/src/uadk_rsa.c b/src/uadk_rsa.c
|
|
index 74852e7..bcdd6bc 100644
|
|
--- a/src/uadk_rsa.c
|
|
+++ b/src/uadk_rsa.c
|
|
@@ -48,6 +48,7 @@
|
|
#define UADK_E_FAIL 0
|
|
#define UADK_DO_SOFT (-0xE0)
|
|
#define UADK_E_POLL_SUCCESS 0
|
|
+#define UADK_E_POLL_FAIL (-1)
|
|
#define UADK_E_INIT_SUCCESS 0
|
|
#define CHECK_PADDING_FAIL (-1)
|
|
#define ENV_ENABLED 1
|
|
@@ -664,11 +665,13 @@ static int uadk_e_rsa_poll(void *ctx)
|
|
|
|
do {
|
|
ret = wd_rsa_poll_ctx(CTX_ASYNC, expt, &recv);
|
|
- if (recv == expt)
|
|
+ if (!ret && recv == expt)
|
|
return UADK_E_POLL_SUCCESS;
|
|
- else if (ret < 0 && ret != -EAGAIN)
|
|
- return ret;
|
|
- } while (ret == -EAGAIN && (rx_cnt++ < ENGINE_RECV_MAX_CNT));
|
|
+ else if (ret == -EAGAIN)
|
|
+ rx_cnt++;
|
|
+ else
|
|
+ return UADK_E_POLL_FAIL;
|
|
+ } while (rx_cnt < ENGINE_RECV_MAX_CNT);
|
|
|
|
fprintf(stderr, "failed to recv msg: timeout!\n");
|
|
|
|
@@ -700,7 +703,8 @@ static int uadk_e_rsa_env_poll(void *ctx)
|
|
ret = wd_rsa_poll(expt, &recv);
|
|
if (ret < 0 || recv == expt)
|
|
return ret;
|
|
- } while (rx_cnt++ < ENGINE_RECV_MAX_CNT);
|
|
+ rx_cnt++;
|
|
+ } while (rx_cnt < ENGINE_RECV_MAX_CNT);
|
|
|
|
fprintf(stderr, "failed to poll msg: timeout!\n");
|
|
|
|
--
|
|
1.8.3.1
|
|
|