Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1407855pxk; Thu, 10 Sep 2020 14:43:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwc1dX61auEiaEd4wfzdYUrTGiyJb0TdXiJgnWhlscaa+dT1KUkqNUD6ryGcCoRLL7Qe+WZ X-Received: by 2002:a50:fd83:: with SMTP id o3mr11323791edt.176.1599774210187; Thu, 10 Sep 2020 14:43:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599774210; cv=none; d=google.com; s=arc-20160816; b=g6aI5qQAg/+9Y8vybMcBpGVQn8vVVhnEj5CpIiCEcEThb6RRXjV+Hyx2CUCEaE6/cy fJTLIW6a0C4ykkDGoiVkkfab/P2wp2qCmwk0BiLyctVWwhPe0lEwWDKlv4bh841ttSkv RHWUmKIyBU3cZ7j75KXmt7Hz8i883NiTG5cJdTY+v4E6xigQlaVzWf+eEmgPkxbGcPqy MnjoYt+pxyHILF9WSj+qHxxQ18tSdyekHrjf1oZvoXjsJMRsyCOU61eg3Z+KXaspB9Nl prx0xTSmS3WGrVJMB+wksO7vQaqkx1NFxQJCMAb4BsRa9OfaO1ETKm+4P6vi5Kb6tzky 5NKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=1T04YGDXO0fl5bVuHOOig0Pyh8uYKSSzp7tysgO6RtI=; b=0H2LtFljZUf7WB1AoTZQ9EfUPls5lUgWhnmWBf9D5pDCRdG+mhmoEhSNvARaV4SafI zcNOLKDDdvpbVRmkfPnbe5H0fu6E6Mja20sH5X1TquNv2JMiG3TcNFHFYouShw5Zp487 XIZBXquingpD/B4TVAt6bP/s3QIpLxGqzA8Pl0VVedM8TCMZ8PCGDGlaHjGUiyLc4B+p Qzj4a7A/6yTcSLY4hcd8+SOpjthK6uEd4Crau1WFXi55ebMQwmEwqT+Nam+M3T+ah3HA eKWqqDs7CfEEOTZQTYVXY2IfIFXH6mIHShO2rNUI2lzsIdxiedx8JMjAu4Zpvj+PgRKv yWfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j16si5333815edj.408.2020.09.10.14.43.01; Thu, 10 Sep 2020 14:43:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728507AbgIJVmf (ORCPT + 99 others); Thu, 10 Sep 2020 17:42:35 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:11767 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730338AbgIJL6D (ORCPT ); Thu, 10 Sep 2020 07:58:03 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id BE17D38075CA3ECD775F for ; Thu, 10 Sep 2020 19:57:53 +0800 (CST) Received: from huawei.com (10.67.165.24) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.487.0; Thu, 10 Sep 2020 19:57:51 +0800 From: Longfang Liu To: CC: Subject: [PATCH 5/5] crypto: hisilicon - fixed memory allocation error Date: Thu, 10 Sep 2020 19:56:43 +0800 Message-ID: <1599739003-23448-6-git-send-email-liulongfang@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1599739003-23448-1-git-send-email-liulongfang@huawei.com> References: <1599739003-23448-1-git-send-email-liulongfang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-CFilter-Loop: Reflected Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 1. Fix the bug of 'mac' memory leak as allocating 'pbuf' failing. 2. Fix the bug of 'qps' leak as allocating 'qp_ctx' failing. Signed-off-by: Longfang Liu --- drivers/crypto/hisilicon/sec2/sec_crypto.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/hisilicon/sec2/sec_crypto.c b/drivers/crypto/hisilicon/sec2/sec_crypto.c index 543d9ee..bb49342 100644 --- a/drivers/crypto/hisilicon/sec2/sec_crypto.c +++ b/drivers/crypto/hisilicon/sec2/sec_crypto.c @@ -340,11 +340,14 @@ static int sec_alg_resource_alloc(struct sec_ctx *ctx, ret = sec_alloc_pbuf_resource(dev, res); if (ret) { dev_err(dev, "fail to alloc pbuf dma resource!\n"); - goto alloc_fail; + goto alloc_pbuf_fail; } } return 0; +alloc_pbuf_fail: + if (ctx->alg_type == SEC_AEAD) + sec_free_mac_resource(dev, qp_ctx->res); alloc_fail: sec_free_civ_resource(dev, res); @@ -455,8 +458,10 @@ static int sec_ctx_base_init(struct sec_ctx *ctx) ctx->fake_req_limit = QM_Q_DEPTH >> 1; ctx->qp_ctx = kcalloc(sec->ctx_q_num, sizeof(struct sec_qp_ctx), GFP_KERNEL); - if (!ctx->qp_ctx) - return -ENOMEM; + if (!ctx->qp_ctx) { + ret = -ENOMEM; + goto err_destroy_qps; + } for (i = 0; i < sec->ctx_q_num; i++) { ret = sec_create_qp_ctx(&sec->qm, ctx, i, 0); @@ -465,12 +470,15 @@ static int sec_ctx_base_init(struct sec_ctx *ctx) } return 0; + err_sec_release_qp_ctx: for (i = i - 1; i >= 0; i--) sec_release_qp_ctx(ctx, &ctx->qp_ctx[i]); - sec_destroy_qps(ctx->qps, sec->ctx_q_num); kfree(ctx->qp_ctx); +err_destroy_qps: + sec_destroy_qps(ctx->qps, sec->ctx_q_num); + return ret; } -- 2.8.1