Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2841027rwb; Mon, 15 Aug 2022 12:23:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR6MR3Y+81nOhpDBigQl52lAZDh2u3HA4oL4ztWRlpdOBlFtSwrZ4osQqEzdB/S76s1jLIdb X-Received: by 2002:a17:906:5d0b:b0:731:3310:4188 with SMTP id g11-20020a1709065d0b00b0073133104188mr11512085ejt.208.1660591387686; Mon, 15 Aug 2022 12:23:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660591387; cv=none; d=google.com; s=arc-20160816; b=usX/3Ps5O1Fvxn5Dy6BzvDHcTALg7qitF1K3drBY1T7Y/iakSNrYz0CrV+RThCCmE3 vz6Jia8weUXJAoxNdv6JsSPJtZ67prd5t7Fh8MqXozrq6ueHh2MsQc+mI3ofStf1f5Fi XM8UKFWVl2k11tkFDTqdibQvJ0gusgmdHcAseeqaaPxw3oJnSp4GX7xg7OY1mBIjVCVf wffaw//gi/6gokRBTVAk2zA22R5PRZtqlbDhzQXJtBsdsDmPQfbFo2iAc3chYas9Nb0P qZj2iSY+hlpGjt+Hy1dp5ro0oAlLHL8Hn+8hwRKMpBx5dCBMFrKe+y4xyXL6zs1jGLsc Ti/A== 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=1SrRdtJPdwVVwN1CMdfbsRNKhRGS55+xdNnUHIk1F14=; b=kTiO8PP8AsD2nZ6+A1vIW3SrTHHvUGR+r/JWP65sK5lojKQtoC9wv7XOHjDkX02my9 3l4Ea1U4+Aiex1oIQ0EbikK2hfeY6bxork9+dB56oHSuNeCOa/zsleOd/JSB4D7CNCkb 8shteOwFeuTIPNxCMxLznrp6ynApwiyaKgk8W8Je1YoIAyp7eZDrMi1S25TQ6FRz39wS hceMIaGR8ScuoLNv3ZWWptqJjPVMwjv/S5VGP1D4MN2KQyuaiPFvl8fKoPImlyFeEVlB qnGRNcKCEEGsVFDktWPaRGiZQWyczed5lKlOCQT5Sk2a1usNVE92aXaYapczuflK2c/L Drdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XoN0Ysjs; 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 w18-20020a056402269200b0043e1c8b6187si9608460edd.1.2022.08.15.12.22.40; Mon, 15 Aug 2022 12:23:07 -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=XoN0Ysjs; 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 S245723AbiHOTUF (ORCPT + 99 others); Mon, 15 Aug 2022 15:20:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344570AbiHOTRC (ORCPT ); Mon, 15 Aug 2022 15:17:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 325A454669; Mon, 15 Aug 2022 11:38:31 -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 A41316113C; Mon, 15 Aug 2022 18:38:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 716ADC433C1; Mon, 15 Aug 2022 18:38:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588707; bh=mccXJfaUGltowdpiIPhn0T+HvkdePsdRvpdZGS56ANw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XoN0YsjsaQD2qEujmqTficc8eO4dMUlDxPXweL+h7tzsCghCM5aNBqePcB6Pgd9eC 4j2HSkJBa1hoc3Qr8y8rFpkb+QRfvS99UDbFjQ/Vcs/DSVK0x5+MDwnWwdS0BTsvf7 20EZwV5cuO0eYCSdpMnPl9iB4ZNOrPO7IXQ6lSQ4= 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 459/779] PCI: dwc: Stop link on host_init errors and de-initialization Date: Mon, 15 Aug 2022 20:01:43 +0200 Message-Id: <20220815180356.903092606@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 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 bc0807fe3fc3..3200e906bcda 100644 --- a/drivers/pci/controller/dwc/pcie-designware-host.c +++ b/drivers/pci/controller/dwc/pcie-designware-host.c @@ -414,8 +414,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) @@ -426,8 +432,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