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 cf7f4bb..e74a8c8 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 4127d48..78d0a03 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 fff0a75..60f9fbf 100644 --- a/src/uadk_digest.c +++ b/src/uadk_digest.c @@ -342,11 +342,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");
@@ -365,7 +367,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 d784b01..2e7e439 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 493c4b1..5cd93c8 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");