Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1882467rwb; Fri, 19 Aug 2022 11:01:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR4NQjMPD2vm8jadzLf9NwiaicaaYNeotgsanlMA6B9iY3s04s6OlMxBmJp2dW23LLQTYW6E X-Received: by 2002:a65:60d4:0:b0:419:9871:9cf with SMTP id r20-20020a6560d4000000b00419987109cfmr7272821pgv.214.1660932082308; Fri, 19 Aug 2022 11:01:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660932082; cv=none; d=google.com; s=arc-20160816; b=p1ls0N6j9k0uCdNZQR3hsSI4Dk2kI9E8XMNA8J+BhkCnCtbDycuMv+DuxccIHcY6jd NCVRddjeEqyZsknMd1EbpNFv/s/LZR9AbXCj3McnY5O10hUkadYqZn9ZxCbGLUV+MZQ8 TnlERHvE6RlKwFKTg7BXgf4RTXxDnKj0Lcw60bW5SiZy8QGmPbl6+1puGBRaxasvfQiK uoDQh6I1qc2NuVt41m9UXaHYF+pYIysUnYmNOjAihONqa/Wn4ewdg3gXJxd7c9hTwYtQ R1oGCKWUZ9RPJ0pQu0vNgx7nIaJ2P3Iaw/Pt3IA5hmaQ2PM5GSRS1XPCmRevE/QVA0S0 lKOw== 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=O8cvGEapTJphmlE396OFxKgk80SZaBP9/cE0Zkq+Zbo=; b=T8o+hIslDioOSm+OIiAI0FMtURGCN/ZcN36Sv3eOfZWOzr0hPoMaGqSV2qbRoIMB6G sa7K/hlniwKUbUiLs8PNnwcAD97uNQ/r/IIBx8KsTdeGmoe9ESBaDgXEB2/CaHFocEQl c7w8oydD2uOFAjgjNz32e+Z1/8x9Uji6j6sFy6XPhaeaF8mYQRmaLidRI6apPC9eMgNH oXtHFdGh30vTm50ofHU/+nmp3SXbRaZdnQWET7ZwsHpTMnVUUDtKhfL8/PvL8pUI5Xay PZN5OSSaXdoCnfiVFGvV1w2gXQiSpJvuBPUJB1GrM/iUqDdd4brI77nk9fL2EpBlW5fo ALBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cWg+E5lY; 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 j6-20020a170903024600b0016bf48465e7si4652561plh.380.2022.08.19.11.01.08; Fri, 19 Aug 2022 11:01:22 -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=cWg+E5lY; 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 S1352535AbiHSQXL (ORCPT + 99 others); Fri, 19 Aug 2022 12:23:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352834AbiHSQRx (ORCPT ); Fri, 19 Aug 2022 12:17:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B2FD10959D; Fri, 19 Aug 2022 09:01:04 -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 25EC7B82814; Fri, 19 Aug 2022 16:00:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BCD2C433C1; Fri, 19 Aug 2022 16:00:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660924849; bh=lz4X5Ku6NUjeE1KEPLQdE0QrdlGITKrDmm4Ce6fnshc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cWg+E5lYmEhz5lFXA6puLqyTVAcAftgN3RWFZQiJrrAIzB+IjN3+LBuhjoksxEUaO 1VDNQcY5D+aRpmQqlpC7TGm8D4C1CWnm8rMUkmrb5BQtYKqT/HmnFxLucLvFsRqkQn t2xExQDn1NJ+59gpwseIXNWE5TPoZUDin8ptU10c= 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.10 302/545] PCI: dwc: Deallocate EPC memory on dw_pcie_ep_init() errors Date: Fri, 19 Aug 2022 17:41:12 +0200 Message-Id: <20220819153842.851044532@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@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 ad7da4ea43a5..95ed719402d7 100644 --- a/drivers/pci/controller/dwc/pcie-designware-ep.c +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c @@ -773,8 +773,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) { @@ -783,6 +784,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