Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2841036rwb; Mon, 15 Aug 2022 12:23:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR4rUc41uNMRYIfghyEtyq+gXkErEGZWqtV85nSKCGzOYcfJtNZl4j0+0B/l1QJLS7JhQ97q X-Received: by 2002:a17:907:2c48:b0:730:cdc9:2c0b with SMTP id hf8-20020a1709072c4800b00730cdc92c0bmr11125397ejc.482.1660591388689; Mon, 15 Aug 2022 12:23:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660591388; cv=none; d=google.com; s=arc-20160816; b=DwDyNcVx6PXipF2LVQ07e0rzdcaUXbVy3bHMWrh4bbLMpiRnatzF/Zb9COovjrLTfO 08sjNeJCU1nZjlNirZCNvg3m+gIEbr8Eo0wTATPmSfknGgpNahob/2J/GqR5ZJm0jBh9 zYRQE35UdgcnbnLkcPvqkmyrDw3MpM9ZBoa3dRCmghULxQBrmvdewuWzk4R93lIgQH1j pGAzr2CR2adGvPx5+YsV5HXO+o6bhkEH8H4Xvb0LCoroIoC8VkAdgUU70R/V1WBElFU6 4cSUVI7f6QTeOXERWEabYZFdQtxPs5vCRQz9h0KmCXnpBVii4QMuDI5Hcf8Unbazpfns io2w== 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=Etr26f9GK7Cll5jTdqqELOKpRvr7eZuW+2WlvJko6oQ=; b=yYyk3az7I5J1Ufvpi9JU8Paaz2u1X3lWlybCSMHz3C+bZAN4hne8trqWPUi+wO/Ysf dEj6qmdzXnP0NzvZi3qRM5WUAvrcCGc6B7wKEJDBA+ibOPbAgVtW/WTlAOC4NeaxsNht Y9E4bsq2a3iLqxNcOspJ8L9YsFQK0kProq19ZJoGanSrlkIWIHJpjlO7uVE3BuxFg55a Fjtc3FaXN47i1NEX/zWRue5p5+rKGI7rIMB2F1TYE/y4swF1BQka/yQQmPcUX0D4X6Sa eH7jG/hK26UH502ueHd6luzluc2irHDsicyEaDuqDdx0MOZ1zGp5Bm/JpqB0yr76smRk xj4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QZD7eDmg; 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 ff20-20020a1709069c1400b0072ee922047asi6437800ejc.590.2022.08.15.12.22.40; Mon, 15 Aug 2022 12:23:08 -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=QZD7eDmg; 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 S245019AbiHOTUS (ORCPT + 99 others); Mon, 15 Aug 2022 15:20:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344724AbiHOTRV (ORCPT ); Mon, 15 Aug 2022 15:17:21 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEAB654CB4; Mon, 15 Aug 2022 11:38:42 -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 EE314B8108B; Mon, 15 Aug 2022 18:38:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46AA5C433C1; Mon, 15 Aug 2022 18:38:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588719; bh=LOhZuZOT14v6tsIvogwRH0JGe5CzZZhO9MHqkTTLQm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QZD7eDmgKkQxbpkrlpHN0CFp+aY9WxGUPVGlAmrlYaiC5Rfxp2PORD8NyvzcRAv74 MbYIUqE0KdFFl0su/20KQ7nA2tJWbDrWgK1RfOOJRBS5CGHCewGVrJ7uUy49gCPAI3 zHTzBOCbhP837qVBKUSImamv0XCDISf2zSmfde1k= 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.15 463/779] PCI: dwc: Deallocate EPC memory on dw_pcie_ep_init() errors Date: Mon, 15 Aug 2022 20:01:47 +0200 Message-Id: <20220815180357.090644892@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@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 998b698f4085..2af4ed90e12b 100644 --- a/drivers/pci/controller/dwc/pcie-designware-ep.c +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c @@ -777,8 +777,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) { @@ -787,6 +788,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