Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3026727rwb; Mon, 15 Aug 2022 16:24:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR6JJ2ioQ9+EVRBR9Xgy2G3zYXwpYZgS+65fw6NXdEkBGgjOwHy5BBe3us1FGKh3HO3QHiCE X-Received: by 2002:a17:90b:3ec9:b0:1f5:62d5:4157 with SMTP id rm9-20020a17090b3ec900b001f562d54157mr29588466pjb.183.1660605793734; Mon, 15 Aug 2022 16:23:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605793; cv=none; d=google.com; s=arc-20160816; b=jpRXoSEqh4badJU8GYrAe8SHfRZ64Y2rGv2wvSkmw/he6rEb6NUE5R4ORai+AlRHSr SR4aAWaGJAZMcNabgKqiEIJ+P0fmvz+oNOX70CkOCNGWS8yFaSbOuoX9WY0x4KapoiEt 9TqKyOMFSIARfGJoTW6Awt3HCDCDLg744ojVbjY8UJbCMUctmLtnLZt/tf5TQGfnJC2p iVB/hO2StN7lgVaM6N4eVF4e8Vj3hw/LQxJR4g9OMelV/nKBCyI0eUu8FOJbxrM6BLiu 0O4u7BObzR5DVFlHUbUorkt3xOpNsTvseX/6OLVEhpl6+17+J0nSbpJ/faPTCzTvayZq 89hA== 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=KYIYCv5h+LkOt0VHtiE4Cuvi24Shf6xKeIp+WFIgVzW87TsO4Lj5Qk6m2xTjrD7pj9 Ad46IZ8PHhoeLePCRd8hmOaADhvDBMIT9J4MmnDSgOAs6PO0CZgOFMi8aSkgXEaNwOs6 kUNdqb0GiZ+4NYpTHzRZWx/8c/orDSF+wFuHTVZDoe2SyIon/EqOabngMnGm37kt2Ase bqrMB/rdExqIaK4XQzW528Vc6Uh1qB9fPvc7ugDGO0iuy8ofpKawCrlLLc5utEPkFZRb c+3WDc7wz1sYtJt9W9vl3/XwVfBJKL4gqZf1lBGrdQ6TLuwaIGDNEyK814d62IUc/yht Pagg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FrOIYCFn; 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 y2-20020a056a00180200b0052f25fdf526si12916774pfa.153.2022.08.15.16.23.02; Mon, 15 Aug 2022 16:23:13 -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=FrOIYCFn; 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 S1346970AbiHOV7Y (ORCPT + 99 others); Mon, 15 Aug 2022 17:59:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345211AbiHOV64 (ORCPT ); Mon, 15 Aug 2022 17:58:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C249B10DCCD; Mon, 15 Aug 2022 12:34:55 -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 98A44B80EA7; Mon, 15 Aug 2022 19:34:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 990CFC433C1; Mon, 15 Aug 2022 19:34:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592065; bh=QlOz2Io+byC6AKMjBO+S+1VJ4N/d58bt7s1z5/Zdtc8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FrOIYCFnGXdtrzTHPthc8YhjHofKgYpAmnnP+TBA75XyvfjuSKYWJ3LhR4K4JnL/j XbA6CoAlSwn5aZip5B7e8aN3RrqPLMYkdn1ijN9DynRFGFhnxIFx+XVATfsz3B1Zo/ V+wCnO5ohDChdPFMMvvdPzHGlYpPqUNuoSWZirJ8= 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.18 0725/1095] PCI: dwc: Deallocate EPC memory on dw_pcie_ep_init() errors Date: Mon, 15 Aug 2022 20:02:04 +0200 Message-Id: <20220815180459.369963169@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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