Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3022289rwb; Mon, 15 Aug 2022 16:19:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR4lKhZ9AVClryWUF3EKPwZQjgQW9cQ5iSrNZnADvs8imKHSiPS1mCmIvtW99yQJ2H4HFM5a X-Received: by 2002:a05:6402:1e8d:b0:441:58db:b6a2 with SMTP id f13-20020a0564021e8d00b0044158dbb6a2mr15949584edf.277.1660605474509; Mon, 15 Aug 2022 16:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605474; cv=none; d=google.com; s=arc-20160816; b=VGHbZS9xtRG1bdxJReVO8nfGWSxg7oj/6fG9tyBMEl4kHC81q8u6ADsewQOrQISUVG rmt2r71G2supc96rp8dgF6j6/twubqG8eOpJjucuRTB1wkNVOaxwAxL090P72Fy2bSSc kWmfOoIeuk11AMiDjl0KMj6SpU6xRSgkozBvhjiTefl+js4se0YulVwNhs7fs2OEMBsW Cx6ba7eGhd8v3vNsUqU9K/6oi2zSYDAObNbcnnPaB476hZT017anZtyoykNo8CaI8vvt pHPXSBOxR0//1N4ZUPS7zLn1gjWX7nujEauA196tBZJuWwP83KRqRrlIW+Khxsl7VUFJ 3f1A== 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=BCvbT2ohT5CuMJiprrIqBtHthERsQ7rqb3d+hCgRPbs=; b=rzpafKYPyBcsrS2U/Gzj3peDDqelDTe8fZEO82SBbvkKDzngeFDaKHy92bb2SIRvA6 hi1zNFrGXQwusr2XyzFFe4U3sT9tMs48SctktJ40UlZTIoN0NNTF21vvqgJlwhX5ra5x HvJnIEfuyAVS+Oxz/g9dzIbHlV2o4yEhrmKMYVx8W/Dn2mVqDNYiqecwrzD3Yb61NsT2 7PeyBhLtMC14glc7pxBVYtcZjMLkIQLlEEw8eXTVJHq5F0jMW6ALsZT2h+lmFDaw58i8 UJqhQ0ZT9Kr9V4OUXaHrlbdOzD5TyEDbPSLGN/xbIQdeuOcMMiOLns11IlhvJH/LMRx7 5hEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=s8oVru1Q; 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 gc29-20020a1709072b1d00b007309b0ab2b4si6854478ejc.518.2022.08.15.16.17.28; Mon, 15 Aug 2022 16:17:54 -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=s8oVru1Q; 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 S1347477AbiHOV5p (ORCPT + 99 others); Mon, 15 Aug 2022 17:57:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350115AbiHOVzw (ORCPT ); Mon, 15 Aug 2022 17:55:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0227C2A715; Mon, 15 Aug 2022 12:33:57 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 3C534610A5; Mon, 15 Aug 2022 19:33:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 266B3C433C1; Mon, 15 Aug 2022 19:33:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592036; bh=0wrrhUS/yrhbpDRp/29eoecL0CIsdPgCiNB8JkyesjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s8oVru1Q7pLhWWVpSXLODTOpYk7oWp8f+0ai7CrrE45N60z/GAYqPPCezMFBvRuee 6EP0B8k7dKY7trV1piF/f9z0AgVSsjvwYLcpn01fn+fkVLNV5CHTCWAI3A54Vdyzww Y6CqpH1/SPLPwB9KkRnKe7U2whHV+ZQCYE7Sdky4= 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 0721/1095] PCI: dwc: Stop link on host_init errors and de-initialization Date: Mon, 15 Aug 2022 20:02:00 +0200 Message-Id: <20220815180459.224705275@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 113fa857b74c947137d845e7e635afcf6a59c43a ] It's logically correct to undo everything that was done when an error is discovered or in the corresponding cleanup counterpart. Otherwise the host controller will be left in an undetermined state. Since the link is set up in the host_init method, deactivate it there in the cleanup-on-error block and stop the link in the antagonistic routine - dw_pcie_host_deinit(). Link deactivation is platform-specific and should be implemented in dw_pcie_ops.stop_link(). Fixes: 886a9c134755 ("PCI: dwc: Move link handling into common code") Link: https://lore.kernel.org/r/20220624143428.8334-2-Sergey.Semin@baikalelectronics.ru Tested-by: Manivannan Sadhasivam Signed-off-by: Serge Semin Signed-off-by: Bjorn Helgaas Reviewed-by: Manivannan Sadhasivam Reviewed-by: Rob Herring Signed-off-by: Sasha Levin --- .../pci/controller/dwc/pcie-designware-host.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c index 9979302532b7..bc9a7df130ef 100644 --- a/drivers/pci/controller/dwc/pcie-designware-host.c +++ b/drivers/pci/controller/dwc/pcie-designware-host.c @@ -421,8 +421,14 @@ int dw_pcie_host_init(struct pcie_port *pp) bridge->sysdata = pp; ret = pci_host_probe(bridge); - if (!ret) - return 0; + if (ret) + goto err_stop_link; + + return 0; + +err_stop_link: + if (pci->ops && pci->ops->stop_link) + pci->ops->stop_link(pci); err_free_msi: if (pp->has_msi_ctrl) @@ -433,8 +439,14 @@ EXPORT_SYMBOL_GPL(dw_pcie_host_init); void dw_pcie_host_deinit(struct pcie_port *pp) { + struct dw_pcie *pci = to_dw_pcie_from_pp(pp); + pci_stop_root_bus(pp->bridge->bus); pci_remove_root_bus(pp->bridge->bus); + + if (pci->ops && pci->ops->stop_link) + pci->ops->stop_link(pci); + if (pp->has_msi_ctrl) dw_pcie_free_msi(pp); } -- 2.35.1