crypto: hisilicon/hpre - fix "hpre_ctx_init" resource leak
authorHui Tang <tanghui20@huawei.com>
Fri, 19 Mar 2021 10:45:27 +0000 (18:45 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 26 Mar 2021 09:15:57 +0000 (20:15 +1100)
When calling "hpre_ctx_set" fails, stop and put qp,
otherwise will leak qp resource.

Signed-off-by: Hui Tang <tanghui20@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/hisilicon/hpre/hpre_crypto.c

index c90d0b8..d743c54 100644 (file)
@@ -454,9 +454,16 @@ static void hpre_alg_cb(struct hisi_qp *qp, void *resp)
        req->cb(ctx, resp);
 }
 
+static void hpre_stop_qp_and_put(struct hisi_qp *qp)
+{
+       hisi_qm_stop_qp(qp);
+       hisi_qm_free_qps(&qp, 1);
+}
+
 static int hpre_ctx_init(struct hpre_ctx *ctx, u8 type)
 {
        struct hisi_qp *qp;
+       int ret;
 
        qp = hpre_get_qp_and_start(type);
        if (IS_ERR(qp))
@@ -465,7 +472,11 @@ static int hpre_ctx_init(struct hpre_ctx *ctx, u8 type)
        qp->qp_ctx = ctx;
        qp->req_cb = hpre_alg_cb;
 
-       return hpre_ctx_set(ctx, qp, QM_Q_DEPTH);
+       ret = hpre_ctx_set(ctx, qp, QM_Q_DEPTH);
+       if (ret)
+               hpre_stop_qp_and_put(qp);
+
+       return ret;
 }
 
 static int hpre_msg_request_set(struct hpre_ctx *ctx, void *req, bool is_rsa)