From patchwork Tue Oct 27 13:51:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 311858 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=unavailable 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 AB1D5C5DF9E for ; Tue, 27 Oct 2020 17:56:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67E9F206E3 for ; Tue, 27 Oct 2020 17:56:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603821399; bh=+JLpDtZlMkJC/5oYYOft4oRWdMHOm1L+YooLcOzvMHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=saCNWIXZ+E9nYd8CBnxdeH2OyaCK1t5saaHhw/RPxMLeWwz9Zf/l4QGCz3Am25nKP Y/iPtL2BoDa2OmUm3jMXmL/YPOdwJds/Pzwoc4VGKohLxBRm1fV6jsuVqae9HgaLto 0ALp72ZqCgz4x/0hEDwkRX4BYKAfly8rdc6ZM8yo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2895051AbgJ0OUi (ORCPT ); Tue, 27 Oct 2020 10:20:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:44060 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758472AbgJ0OUM (ORCPT ); Tue, 27 Oct 2020 10:20:12 -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 2D1AB206F7; Tue, 27 Oct 2020 14:20:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603808411; bh=+JLpDtZlMkJC/5oYYOft4oRWdMHOm1L+YooLcOzvMHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ODmVuhu8cf4I5zihPe/1lCnrBWPJ5XezHiDxf+1F5gt/+NZm4iTKWBIHTeK61R9KL FaIfvurM95UscmXCVp6dze3GwplnlM0OaR7XHAYl1rPqNrPAoWbx5datuxBTN4aB9y kvsdGo/BaQLBnEtLJdykFi+e5bwROOODbEn1raDY= 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 4.19 051/264] cypto: mediatek - fix leaks in mtk_desc_ring_alloc Date: Tue, 27 Oct 2020 14:51:49 +0100 Message-Id: <20201027135433.072826298@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135430.632029009@linuxfoundation.org> References: <20201027135430.632029009@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 03b1436f87096..e4d7ef3bfb61d 100644 --- a/drivers/crypto/mediatek/mtk-platform.c +++ b/drivers/crypto/mediatek/mtk-platform.c @@ -473,13 +473,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; }