[PATCH v2 4/5] crypto: hisilicon/sec2 - fix resource leakage issues in non-backlog mode

From: ZongYu Wu

Date: Thu May 28 2026 - 07:57:37 EST


From: Wenkai Lin <linwenkai6@xxxxxxxxxxxxx>

The problem that resources are not released in non-backlog mode is fixed.
There are three cases:
1. If the device is abnormal, the send function returns EAGAIN and
prints an error log.
2. If the device queue is full, the send function returns ENOSPC and
does not print anything.
3. The task is sent normally, and EINPROGRESS is returned.

In addition, the step of switching to software computing is deleted so that
the caller can correctly handle the actual situation.

Fixes: f0ae287c5045 ("crypto: hisilicon/sec2 - implement full backlog mode for sec")
Signed-off-by: Wenkai Lin <linwenkai6@xxxxxxxxxxxxx>
Signed-off-by: Zongyu Wu <wuzongyu1@xxxxxxxxxx>
---
drivers/crypto/hisilicon/sec2/sec_crypto.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/crypto/hisilicon/sec2/sec_crypto.c b/drivers/crypto/hisilicon/sec2/sec_crypto.c
index 62125cf1f849..901abe8761e5 100644
--- a/drivers/crypto/hisilicon/sec2/sec_crypto.c
+++ b/drivers/crypto/hisilicon/sec2/sec_crypto.c
@@ -345,6 +345,9 @@ static int sec_alg_send_message_retry(struct sec_req *req)
ret = qp_send_message(req);
} while (ret == -EBUSY && ctr++ < SEC_RETRY_MAX_CNT);

+ if (ret == -EBUSY)
+ return -ENOSPC;
+
return ret;
}

@@ -1983,14 +1986,11 @@ static int sec_process(struct sec_ctx *ctx, struct sec_req *req)
sec_update_iv(req, ctx->alg_type);

ret = ctx->req_op->bd_send(ctx, req);
- if (unlikely((ret != -EBUSY && ret != -EINPROGRESS))) {
+ if (likely(ret == -EINPROGRESS || ret == -EBUSY))
+ return ret;
+ else if (ret != -ENOSPC)
dev_err_ratelimited(ctx->dev, "send sec request failed!\n");
- goto err_send_req;
- }

- return ret;
-
-err_send_req:
/* As failing, restore the IV from user */
if (ctx->c_ctx.c_mode == SEC_CMODE_CBC && !req->c_req.encrypt) {
if (ctx->alg_type == SEC_SKCIPHER)
@@ -2005,12 +2005,6 @@ static int sec_process(struct sec_ctx *ctx, struct sec_req *req)

err_uninit_req:
sec_request_uninit(req);
- if (ctx->alg_type == SEC_AEAD)
- ret = sec_aead_soft_crypto(ctx, req->aead_req.aead_req,
- req->c_req.encrypt);
- else
- ret = sec_skcipher_soft_crypto(ctx, req->c_req.sk_req,
- req->c_req.encrypt);
return ret;
}

--
2.33.0