Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2910623pxk; Sun, 6 Sep 2020 19:10:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzogm73FTrqmukRR6tbkPtz29bpjKtRxpem5Wcs5sOiWuKEjF0HvoD3h+Bd1iDSPalE6W/ X-Received: by 2002:a17:906:d9d9:: with SMTP id qk25mr18620307ejb.51.1599444652609; Sun, 06 Sep 2020 19:10:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599444652; cv=none; d=google.com; s=arc-20160816; b=Wt5jIT99KMlnxEdEtReanlxa+EbFBuxg7JmC/hzuLt3uTYzesoMDBDZO4JzCmVRwZN SiJiCDey9p9cR2+nJjSHQcL1JUPni7LNfWFr3x02jKA7s1IhaxRSCv0u/lyD48S+9Puh U3HaMWzTE72R0YrvvCY2TQ7IaH1LaegofKrRqWpWdHAHC0vavxXCAFBaUTAGr0Qg1UFW ri8ibonA7AEQMlAwOesZFdL2GEgA+X2oLk7T13C2caP94MMUsROnuRCbMhPVmxO2QbsL 92/Zm1GT8+sYub3EpOudDpnmRjqKUcMAK8odWo0McF5W7hnW4wyoUm28y6nQBCVZVx5s 474w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=tgNahNYZMXrtXJeygjsMjzSrNWcxFP6xVcE3T4mcxQI=; b=Tw5tdJ+JYnRjBRYxg/Kng/IIwalG1JXToWmJ736vdtohT1aVt3C8JfRbJ8LdJnEnYu DSMuRSZcA4vbhqIbFr2Utdw0GgXZy/8PFoTTIHd83onAYblgZkcClGaa4c7ZNK5isRzr 4QuhHrWOceDdQVmin7gcfWLsTQVHqZEgKEIpWkuOBnz3kLSXzb1ZjB4j0poIJAwJRYta ZrMLe70y0ZHY3v6bSUP8vh17Uab0UF9IwSm+UGwUBdcCKbZDHWFwRsfp/eh8wGD7aJVf rz8X2bzIjvCm/UPXq+KPNvmhsHFqIfCA6ml0oRuso+7tvVl6xmUFeI7N7LMEk3XEIjBb YPgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VvJP719f; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cf25si2315810ejb.67.2020.09.06.19.10.09; Sun, 06 Sep 2020 19:10:52 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VvJP719f; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726220AbgIGCKG (ORCPT + 99 others); Sun, 6 Sep 2020 22:10:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725773AbgIGCKA (ORCPT ); Sun, 6 Sep 2020 22:10:00 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3740C061573; Sun, 6 Sep 2020 19:09:59 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id y6so1316752plt.9; Sun, 06 Sep 2020 19:09:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=tgNahNYZMXrtXJeygjsMjzSrNWcxFP6xVcE3T4mcxQI=; b=VvJP719f8QWQzVGJalFHZZYMi8hRnozPNRGRWB+0qU7ISvLSjCGN+kaeYEAfQnZMye bjBxceSghaxIqi/nyyaR3nXWPxV1PbwDkXMei2gv0ul7scY0lumpayZBugh0JyNG2v0a E9zi19sZFzKED0H+p7+/Ii7+5tLXkmr98qT73yjGOlcMugMDVwB0GXP0NILMXw76HsIz SbWfXuev6KtS/BWjoGCLbUkGb3JstMzNEcrKDrjBI/+T1xNc88VrtytQKO3ojGBu0Jv/ fVSY2ncosrUc/vLxJh91fAxSqsedrjW089Mo0CUVgd92nuP8ULLigzCYxF2GiWoK+Nmz yWOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=tgNahNYZMXrtXJeygjsMjzSrNWcxFP6xVcE3T4mcxQI=; b=LrfpscL5RweMvVmt76VgxNi9fLe/sNRJOlPla5dHjGtlRavFS5dGku8m8YDxPN5DuF H7TCBblsJ9KW4goOR0aJnPClOsHGTtepulRKziibHo1kVQmfWgqfVYAL9d8eets1WZW2 EEBcYTQoELruX05J+KR394W6o0GdECMMjkcYX91IFT435ky++dflyRlhxfcYuYgRCna9 T+yWTTHE2eK5/6Apg0bhMOu1FH9FaCApcIl5DfmQ3ECxMDvWEvsFVlcitTk9+WAg/K47 7L9LAOpCT/WQaynAyISnJarQ25Rn0zfdlh/OZPud+WJDTbbMkPX0Ihb0zsvuFM4/WoLD UkQg== X-Gm-Message-State: AOAM531s300EltZYFpsaB+ISENb4bcaOQvZ0uftK9jgnT+lfI9+aH/zG heXJArjoU/dceXaIp3pS6Rs= X-Received: by 2002:a17:902:ee0b:: with SMTP id z11mr17858138plb.268.1599444598464; Sun, 06 Sep 2020 19:09:58 -0700 (PDT) Received: from localhost.localdomain (ec2-13-52-163-24.us-west-1.compute.amazonaws.com. [13.52.163.24]) by smtp.gmail.com with ESMTPSA id z23sm10531125pgv.57.2020.09.06.19.09.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2020 19:09:57 -0700 (PDT) From: Xiaoliang Pang To: herbert@gondor.apana.org.au, davem@davemloft.net, matthias.bgg@gmail.com, swboyd@chromium.org, yuehaibing@huawei.com, tianjia.zhang@linux.alibaba.com, ryder.lee@mediatek.com Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, dawning.pang@gmail.com Subject: [PATCH v3] cypto: mediatek - fix leaks in mtk_desc_ring_alloc Date: Mon, 7 Sep 2020 10:09:39 +0800 Message-Id: <20200907020939.6817-1-dawning.pang@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org In the init loop, if an error occurs in function 'dma_alloc_coherent', then goto the err_cleanup section, in the cleanup loop, after run i--, the struct mtk_ring rising[i] will not be released, causing a memory leak Signed-off-by: Xiaoliang Pang --- drivers/crypto/mediatek/mtk-platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/mediatek/mtk-platform.c b/drivers/crypto/mediatek/mtk-platform.c index 7e3ad085b5bd..ebb3bdef0dbe 100644 --- a/drivers/crypto/mediatek/mtk-platform.c +++ b/drivers/crypto/mediatek/mtk-platform.c @@ -469,13 +469,13 @@ static int mtk_desc_ring_alloc(struct mtk_cryp *cryp) return 0; err_cleanup: - for (; i--; ) { + do { dma_free_coherent(cryp->dev, MTK_DESC_RING_SZ, ring[i]->res_base, ring[i]->res_dma); dma_free_coherent(cryp->dev, MTK_DESC_RING_SZ, ring[i]->cmd_base, ring[i]->cmd_dma); kfree(ring[i]); - } + }while(i--); return err; } -- 2.17.1