Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp531704pxx; Wed, 28 Oct 2020 10:25:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfPfND/gZZMOeW5R2i2SNtb/6zYC13jUAhGOchBBR/PkxNY98b2rtIscdcbtMj3P/iGOAW X-Received: by 2002:a05:6402:b87:: with SMTP id cf7mr9257120edb.137.1603905938083; Wed, 28 Oct 2020 10:25:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603905938; cv=none; d=google.com; s=arc-20160816; b=Ow13+cBq74xBrzBzziAjfK5I1Z8oO5yoDoxpz5kJPuWxh1zecDDmtkzkP2bwF0ZMEz 2arbm1yvlgi9nXZzP4Jw+c2oG574DaMhwA0bM91AnGVw63872BCrpQzxRStBJHv2Y7eL 4zirU9nSW5vEA08Z/fV4wza325WB7jL4v4RisuYVlcKM06Jim2qAPfZUzJp8O6GXoKAu LHHSnIWjRgA2CPoRWb0wDTHXVIyqi9n3Ub0xTNv0zjVWmdmDrdakVHYxJPI24vpBYAXE bNbKQBYYTvZflfO9+fjd6BFb+ov/VlNg9rwixpjYmXKw9BRTQqCsYDFq89BxRvAFePJE ugYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3ZxSafw2D0iQdmJusJeq/8LooRHQ4UEwJ3sZaU/JKTg=; b=PARwZqYCXO0Hck/dmTYUJptGyq7M9tiUcXgUJWz21/kPD7DjV7OUd+1Ozec98WXKeS eP9KtByDhO2rIXXMNSnPvNpTcscr7oMMCTOA+U5BmGYGg3r2iRodSAtwbyBA5gq9w8Xj SSNNHQbipaDp3X3i2hRlgTHTuP9xSELvvYLCj0HWbrvFpbVGtBb9czF+r9tQazoCt69q q5GVqHAEQ1p7JosagiMlXDgeM3TubKxyO6OnMoz+2gJU29Xu/PF1hhlh0hD1M+zU45PP TWIzNUdaC0C899zpGBpNC6OCWDXfekZb4km7I1b0jZyPrCK5rihWZTcQB8D/8fAFEJMq uM5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GTyZ0aIH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j13si1208edj.549.2020.10.28.10.25.15; Wed, 28 Oct 2020 10:25:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@kernel.org header.s=default header.b=GTyZ0aIH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1821244AbgJ0Rlf (ORCPT + 99 others); Tue, 27 Oct 2020 13:41:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:60570 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760150AbgJ0Odh (ORCPT ); Tue, 27 Oct 2020 10:33:37 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 29C4C2222C; Tue, 27 Oct 2020 14:33:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809216; bh=OpLbOhOpLkgVcWBbkxBCA/veGdYFoU8WNyf0u5A4wjg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GTyZ0aIHkVotqs9z2YrJLFxYEx5yDOzbfbqlEt+oIOVbOWuWbmb5hfMd6X5kNPryC MZgn0thYX5xekBx9XkBcsBxAuhtwqo5SEQQsnBvNtXYysbn3JU8rKZ/P/6cJ8B/+r4 SKPQK1A0+k8am1kUoR3iBLrLuZoDdju+n2TbcOJw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ryder Lee , Xiaoliang Pang , Herbert Xu , Sasha Levin Subject: [PATCH 5.4 087/408] cypto: mediatek - fix leaks in mtk_desc_ring_alloc Date: Tue, 27 Oct 2020 14:50:25 +0100 Message-Id: <20201027135459.112713647@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiaoliang Pang [ Upstream commit 228d284aac61283cde508a925d666f854b57af63 ] In the init loop, if an error occurs in function 'dma_alloc_coherent', then goto the err_cleanup section, after run i--, in the array ring, the struct mtk_ring with index i will not be released, causing memory leaks Fixes: 785e5c616c849 ("crypto: mediatek - Add crypto driver support for some MediaTek chips") Cc: Ryder Lee Signed-off-by: Xiaoliang Pang Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- 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 ef4339e84d034..efce3a83b35a8 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 -ENOMEM; } -- 2.25.1