Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3255725rwb; Mon, 15 Aug 2022 22:27:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR6ScmLAtWcq0Xa1g+pkembA1Pg+PCLpTIdTKqk179+5Idd9/5Nfl2LVQAcvA/o4eyFmcsFg X-Received: by 2002:a17:902:f806:b0:172:55a6:bd25 with SMTP id ix6-20020a170902f80600b0017255a6bd25mr16379286plb.61.1660627632919; Mon, 15 Aug 2022 22:27:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660627632; cv=none; d=google.com; s=arc-20160816; b=awAKeSXW91aryDQORvtwneAuui7rUcD49K4Ozpasx4CZKVI3OGqO1N98P0y5oV3ufp pJ1GE5KZ1SwNjT0HCE1DtPS+L1qmRDns3WveWyKwLcbwwi/Jnndg1AYtOOBl643f5cZx uafJsEUpg03XC9CCdT1n0gSVO4xRcuZRqm/mtw7wPMg6tLpmmp1VfDkhTJscyVHR6gwK IMLth1alx4YKFg5LJMiZIlFbIx5s+MGraIq8vPRhBmdA/ANl1e33VDFIuhM1d4H2Myql 1yf3K9as1e9kqVXkym7ISwTgj4ueyiKYOVKUkHxVXHc/SFuLbJGC+imVZ1JEYpD0ALaD BnOg== 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=yOrxMGyJpTCpYX6GyzV/lkaNs3cLe/CE7Yl0pglLoiQ=; b=DzVXNiStRfQLi0Dlm7n9njJsxbzXIEftXJ0zTEUOz7HZjCzamXtiy/4/k8u611F6TO ky1OWtNyz3Hxxv9tbK/zoqvLfOxk8BS321ogTcKHIBxnUwafQ7Cjjaz7hOOasTGW6gvD AKBjAn/xudeg7UI0/BAilgHggs4NdBZ/qTTb4YO0D91z5XD8LiGABAGvG/px/TSZrhqi 4iJnm7GdrqsQsuYWWC6xJnOM2WaOejdJ8iVCjdhX6pTxKPKLQe1JMYP/Gp6N1yXH+mVH mxaHBiDek8XD9riFl0V5szHP2Y0SDxPFO1dZsBxp/pl4N4K3l2n0z63yv5EoTDLoUD5V loOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jmSTxMTs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o21-20020a056a0015d500b0052e30022678si14177000pfu.3.2022.08.15.22.27.02; Mon, 15 Aug 2022 22:27:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jmSTxMTs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231521AbiHPEkR (ORCPT + 99 others); Tue, 16 Aug 2022 00:40:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230369AbiHPEjf (ORCPT ); Tue, 16 Aug 2022 00:39:35 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02A36CE309; Mon, 15 Aug 2022 13:31:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9F57DB8119A; Mon, 15 Aug 2022 20:31:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D19DDC433D6; Mon, 15 Aug 2022 20:31:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660595470; bh=QlOz2Io+byC6AKMjBO+S+1VJ4N/d58bt7s1z5/Zdtc8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jmSTxMTsXTCLLRkHDaV1ZlFzxwWffaZJbpEM1Q/Vv1s82Zth1U5dRha4M3+RhBTTy kLLASou6rfd6zriRYfnR4xUwtbQ5P+tD3QEG1gRuk4IylO2V0W9k652ugT7wGe2H63 FAzLL5t3HiszyXSPNQEJZnnj2QCxglHk8H4nBB5U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Manivannan Sadhasivam , Serge Semin , Bjorn Helgaas , Rob Herring , Sasha Levin Subject: [PATCH 5.19 0775/1157] PCI: dwc: Deallocate EPC memory on dw_pcie_ep_init() errors Date: Mon, 15 Aug 2022 20:02:11 +0200 Message-Id: <20220815180510.494422349@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Serge Semin [ Upstream commit 8161e9626b50892eaedbd8070ecb1586ecedb109 ] If dw_pcie_ep_init() fails to perform any action after the EPC memory is initialized and the MSI memory region is allocated, the latter parts won't be undone thus causing a memory leak. Add a cleanup-on-error path to fix these leaks. [bhelgaas: commit log] Fixes: 2fd0c9d966cc ("PCI: designware-ep: Pre-allocate memory for MSI in dw_pcie_ep_init") Link: https://lore.kernel.org/r/20220624143428.8334-6-Sergey.Semin@baikalelectronics.ru Tested-by: Manivannan Sadhasivam Signed-off-by: Serge Semin Signed-off-by: Bjorn Helgaas Reviewed-by: Rob Herring Reviewed-by: Manivannan Sadhasivam Signed-off-by: Sasha Levin --- .../pci/controller/dwc/pcie-designware-ep.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c index 0eda8236c125..13c2e73f0eaf 100644 --- a/drivers/pci/controller/dwc/pcie-designware-ep.c +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c @@ -780,8 +780,9 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) ep->msi_mem = pci_epc_mem_alloc_addr(epc, &ep->msi_mem_phys, epc->mem->window.page_size); if (!ep->msi_mem) { + ret = -ENOMEM; dev_err(dev, "Failed to reserve memory for MSI/MSI-X\n"); - return -ENOMEM; + goto err_exit_epc_mem; } if (ep->ops->get_features) { @@ -790,6 +791,19 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) return 0; } - return dw_pcie_ep_init_complete(ep); + ret = dw_pcie_ep_init_complete(ep); + if (ret) + goto err_free_epc_mem; + + return 0; + +err_free_epc_mem: + pci_epc_mem_free_addr(epc, ep->msi_mem_phys, ep->msi_mem, + epc->mem->window.page_size); + +err_exit_epc_mem: + pci_epc_mem_exit(epc); + + return ret; } EXPORT_SYMBOL_GPL(dw_pcie_ep_init); -- 2.35.1