From patchwork Tue Oct 27 13:50:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 307059 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA09BC388F9 for ; Tue, 27 Oct 2020 17:40:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E427208B8 for ; Tue, 27 Oct 2020 17:40:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603820446; bh=OpLbOhOpLkgVcWBbkxBCA/veGdYFoU8WNyf0u5A4wjg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=DeHrhwVK/cm9ItINNQylGID+Wkv7xR6LogSW9YfAuvfDoCopkBB0o3J9o9b88CL5O 7VrG0CZwxOTz09WpEltvl4AXi1QJIjBIVfX3E3xNCvvcX/WtJUgzA+FbDnlg/yt9qW PnG94GyVQCySVQptMArjtN0Y4x3k7y+a5aijmvyI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1821140AbgJ0Rkp (ORCPT ); Tue, 27 Oct 2020 13:40:45 -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 Precedence: bulk List-ID: X-Mailing-List: stable@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; }