Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1114863pxk; Fri, 4 Sep 2020 00:24:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFPWWKIWG3fiOrzcShOlnJggcvDnzrJkNdWJfjfXgqvyV3OIngBQTSmr3kY2ymw3yFDD+w X-Received: by 2002:a50:d545:: with SMTP id f5mr6947994edj.322.1599204290297; Fri, 04 Sep 2020 00:24:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599204290; cv=none; d=google.com; s=arc-20160816; b=ckVHkhLKOcxxXjVlXSeutts5gkMRxRKHgV+/Jl07Ryiqxe6TZc2ngQsHh6Bo7SqWPy bwLz5XVrvWDmtGrQ+wbzbNT7zAaam98gZ/zTSW/RtKRxcuo0HU9Qmc6f0pwJvmzckYwp Gn8aEW7bIqZD2DvL00fPuZ5nrmRuIxaHhhUw1URVGHGQQcCLvv+BNVbao0Yp0X2WQHM/ MCsuR7K0Ku9t/5IOJmpln3kPTyEifUEuuNO8vt5fGN1IQA0bYbc1a0+XkgAieXwwPeIC KS2zNYmwf4ihNk1zwbQYSurqzOMwx67xAdG86Y7Lx5JQ3MI174mGb03exg0bWDJBpw3k BqkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:message-id:subject:cc:to:from:date; bh=Yh092UE00fxyD8BKLhBDE0GPfWWTDfHPeKaDWoEIRig=; b=CcYhLPRA2Bag+cTM9RKHSSusjbCrPwnmb6uO3KnGxM8rWas3/cxTE4au9j9wJx51UF 6UE9tbbHkKJCUZsANrdZcsL2yi78fsmddHl5yHkvY/X+jtLPBn0HcpihAedrym0mYnzl nI3uzDxGG/s5k6zPcs3fmDmhrVP68S86xhP3sjyeKuaNbTeoL+Lftdr++4FJ8qWQhAsF ti2+TgzWO/lNX2Rg2GpFCchaebG3edeEhwUiR3h1SkPC4qMa+rDGSrKRI6Oeadaz7aU5 w4i0Wd66LPanljsFLI1nBnbuMgDUVM5Fj3Z2bS3On8EaQwNOMuDJXFVZLLWROg0GdjWz tcQQ== 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 ov32si4046045ejb.9.2020.09.04.00.24.24; Fri, 04 Sep 2020 00:24:50 -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 S1726251AbgIDHWZ (ORCPT + 99 others); Fri, 4 Sep 2020 03:22:25 -0400 Received: from helcar.hmeau.com ([216.24.177.18]:42594 "EHLO fornost.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726114AbgIDHWY (ORCPT ); Fri, 4 Sep 2020 03:22:24 -0400 Received: from gwarestrin.arnor.me.apana.org.au ([192.168.0.7]) by fornost.hmeau.com with smtp (Exim 4.92 #5 (Debian)) id 1kE62k-0008TA-Ec; Fri, 04 Sep 2020 17:21:55 +1000 Received: by gwarestrin.arnor.me.apana.org.au (sSMTP sendmail emulation); Fri, 04 Sep 2020 17:21:54 +1000 Date: Fri, 4 Sep 2020 17:21:54 +1000 From: Herbert Xu To: Xiaoliang Pang Cc: davem@davemloft.net, matthias.bgg@gmail.com, swboyd@chromium.org, yuehaibing@huawei.com, tianjia.zhang@linux.alibaba.com, ryder.lee@mediatek.com, 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: Re: [PATCH] cypto: mediatek - fix leaks in mtk_desc_ring_alloc Message-ID: <20200904072154.GA24603@gondor.apana.org.au> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200903063800.27288-1-dawning.pang@gmail.com> X-Newsgroups: apana.lists.os.linux.cryptoapi,apana.lists.os.linux.kernel User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Xiaoliang Pang wrote: > 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 | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/crypto/mediatek/mtk-platform.c b/drivers/crypto/mediatek/mtk-platform.c > index 7e3ad085b5bd..05d341e4a696 100644 > --- a/drivers/crypto/mediatek/mtk-platform.c > +++ b/drivers/crypto/mediatek/mtk-platform.c > @@ -469,7 +469,7 @@ static int mtk_desc_ring_alloc(struct mtk_cryp *cryp) > return 0; > > err_cleanup: > - for (; i--; ) { > + for (; i >= 0; --i) { How about a do while loop instead? Thanks, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt