From patchwork Fri Aug 31 22:55:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 145708 Delivered-To: patch@linaro.org Received: by 2002:a2e:5d9b:0:0:0:0:0 with SMTP id v27-v6csp6463lje; Fri, 31 Aug 2018 15:53:29 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdaj3/cNRFfvNwBSMNMBeNju31vCvT2tPxXFgOPNTwYtN8GaysJr45Qrj1ED/zyWgft1YApy X-Received: by 2002:a65:49cc:: with SMTP id t12-v6mr16355661pgs.27.1535756009352; Fri, 31 Aug 2018 15:53:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535756009; cv=none; d=google.com; s=arc-20160816; b=wtmvBKh36ZO1M7qOj3q7R4HJHZfqMjIuzkjXzDYFeePEBBx74yEoOr4f7WCwC6Pz9y kSOlY487P/Xe6lzTf361ivbQIigm/ChgWL9G2rWEbDxD95Bb/PDkdsSsNyPjbPgKYF9K RZy3TxmzWyOD/Nxr7+J2OnxUiW1je5i7AuGkklv4qauYwxcL3RozKIu+3yuxN/VBiuQA GlXsQWuR5KmyeuXaO1aDFjFlIBSA5cJPp32bC/yOAzvTITwlASEvXLW8Wl/PSeDcXp+t tkV2oXUTacDKVRxO0kBS+QA00cgQ8tQRUWbiBHbQRcIRabLTSKDqYqY81bvRbd4CI9/y IZIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=JWravq+t0iWKBP7yOtilwFWvbxreMAwW6S9fE2u+f6g=; b=rutU7Rqywca5UdLn8motGtLOGqk3/BQWs95J+fz82zXzKRIuXMAfmDihdNskb/nsf7 WwfwLF4XU/3RYc5F2O1p5ZYGn6AikMBVoYSC6Tdh694Vk7b27tNPi+5qU7CRoJzGls6P zfmoeXWIiJg2qw1Zq8n2YaH74oupk6PZRQWiDwBgZ7BI0d+InJLU3HMRM8GzcIpkp/Uf l5GtU2WnzlmsCP5vgiZ19UCwSTy0mDs9Byvhmhfs+9S9RpHu1zXjejULzxZ9wRfcxsQy W9m1x+gwHa8nMBCyU3OKFL59TILvlepotSDmGb+7zMORRApa2p7evFVPOeqWSNZ2ikjB jJxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ZgDBkcR/"; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e67-v6si10544189plb.272.2018.08.31.15.53.29; Fri, 31 Aug 2018 15:53:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ZgDBkcR/"; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727565AbeIADDG (ORCPT + 13 others); Fri, 31 Aug 2018 23:03:06 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:42605 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726869AbeIADDG (ORCPT ); Fri, 31 Aug 2018 23:03:06 -0400 Received: by mail-pl1-f196.google.com with SMTP id g23-v6so6069600plq.9 for ; Fri, 31 Aug 2018 15:53:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=JWravq+t0iWKBP7yOtilwFWvbxreMAwW6S9fE2u+f6g=; b=ZgDBkcR/VjdcudwwwJ6CfSW+6dyq500I3VqPlXfU1Xo6S0bRAY8pvxy8/Sw2e36lv2 7xykDWIBHgdv4KY1tIuL0geE4Q8m/dI5CmKYKJzEgP7MdTV7X/Z9/3qmrMFUo8fPc9zy 1/Giw/GZWazUltZkx68S8EBgoPGpe28LcWGhw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=JWravq+t0iWKBP7yOtilwFWvbxreMAwW6S9fE2u+f6g=; b=DlK5x8JODbdogjkvvvSGkctgz+SNwbfvgb57xngOATKYQfds1eBtAko6PQ2Du/VZD0 Dpv4O/u1AEj0H1WUhzknmYR5xyJ7NjA+wPGMcuCSEyH81OInGXl9xXTd0pO8SwN7eJp7 bOVkjTRmrDhcH+RiyDdsEKhQd/godKi21qKqfVEmFkGVCzVGRfMyneC6N9KNBSPPSPBr /EbUlcUSTjkxqZDSF+Q5o4XOpsiXVjoviYW8cfU5phdWM48hjZ4Zmdc3s27MfrT620Tq 0dOk0RhaBk+HNmiwCr+I0SURorUgRq+OlhayunfFJ+SJUVeSVjscOTPAsLn597vYgbNh gXcw== X-Gm-Message-State: APzg51AVEPxaGvCKOMIkewtgEJYW29VHjLYEUQopCqBJ39WOsSmllA9T /7hP4wj/qX6U+syIyAI59veBrA== X-Received: by 2002:a17:902:46a4:: with SMTP id p33-v6mr17749933pld.205.1535756007693; Fri, 31 Aug 2018 15:53:27 -0700 (PDT) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id a19-v6sm26522056pfj.38.2018.08.31.15.53.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Aug 2018 15:53:27 -0700 (PDT) From: Bjorn Andersson To: Stanimir Varbanov , Lorenzo Pieralisi , Bjorn Helgaas Cc: linux-pci@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] PCI: qcom: Fix error handling in pm_runtime support Date: Fri, 31 Aug 2018 15:55:10 -0700 Message-Id: <20180831225510.32230-1-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.18.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The driver does not cope with the fact that probe can fail in a number of cases after enabling pm_runtime on the device, this results in warnings about "Unbalanced pm_runtime_enable". Further more if probe fails after invoking host_init the power-domain will be left referenced. As it's not possible for the error handling in qcom_pcie_host_init() to handle errors happening after returning from that function the pm_runtime_get_sync() is moved to probe() as well. Fixes: 854b69efbdd2 ("PCI: qcom: add runtime pm support to pcie_port") Acked-by: Stanimir Varbanov Signed-off-by: Bjorn Andersson --- Changes since v1: - Dropped remove function, as this can't be called - Handle pm_runtime_get_sync() errors - Add "Fixes" tag drivers/pci/controller/dwc/pcie-qcom.c | 56 ++++++++++++++++++-------- 1 file changed, 39 insertions(+), 17 deletions(-) -- 2.18.0 diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c index d2373e4d141c..3bfaad052736 100644 --- a/drivers/pci/controller/dwc/pcie-qcom.c +++ b/drivers/pci/controller/dwc/pcie-qcom.c @@ -1117,7 +1117,6 @@ static int qcom_pcie_host_init(struct pcie_port *pp) struct qcom_pcie *pcie = to_qcom_pcie(pci); int ret; - pm_runtime_get_sync(pci->dev); qcom_ep_reset_assert(pcie); ret = pcie->ops->init(pcie); @@ -1154,7 +1153,6 @@ static int qcom_pcie_host_init(struct pcie_port *pp) phy_power_off(pcie->phy); err_deinit: pcie->ops->deinit(pcie); - pm_runtime_put(pci->dev); return ret; } @@ -1244,6 +1242,12 @@ static int qcom_pcie_probe(struct platform_device *pdev) return -ENOMEM; pm_runtime_enable(dev); + ret = pm_runtime_get_sync(dev); + if (ret < 0) { + pm_runtime_disable(dev); + return ret; + } + pci->dev = dev; pci->ops = &dw_pcie_ops; pp = &pci->pp; @@ -1253,44 +1257,56 @@ static int qcom_pcie_probe(struct platform_device *pdev) pcie->ops = of_device_get_match_data(dev); pcie->reset = devm_gpiod_get_optional(dev, "perst", GPIOD_OUT_LOW); - if (IS_ERR(pcie->reset)) - return PTR_ERR(pcie->reset); + if (IS_ERR(pcie->reset)) { + ret = PTR_ERR(pcie->reset); + goto err_pm_runtime_put; + } res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "parf"); pcie->parf = devm_ioremap_resource(dev, res); - if (IS_ERR(pcie->parf)) - return PTR_ERR(pcie->parf); + if (IS_ERR(pcie->parf)) { + ret = PTR_ERR(pcie->parf); + goto err_pm_runtime_put; + } res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi"); pci->dbi_base = devm_pci_remap_cfg_resource(dev, res); - if (IS_ERR(pci->dbi_base)) - return PTR_ERR(pci->dbi_base); + if (IS_ERR(pci->dbi_base)) { + ret = PTR_ERR(pci->dbi_base); + goto err_pm_runtime_put; + } res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "elbi"); pcie->elbi = devm_ioremap_resource(dev, res); - if (IS_ERR(pcie->elbi)) - return PTR_ERR(pcie->elbi); + if (IS_ERR(pcie->elbi)) { + ret = PTR_ERR(pcie->elbi); + goto err_pm_runtime_put; + } pcie->phy = devm_phy_optional_get(dev, "pciephy"); - if (IS_ERR(pcie->phy)) - return PTR_ERR(pcie->phy); + if (IS_ERR(pcie->phy)) { + ret = PTR_ERR(pcie->phy); + goto err_pm_runtime_put; + } ret = pcie->ops->get_resources(pcie); if (ret) - return ret; + goto err_pm_runtime_put; pp->ops = &qcom_pcie_dw_ops; if (IS_ENABLED(CONFIG_PCI_MSI)) { pp->msi_irq = platform_get_irq_byname(pdev, "msi"); - if (pp->msi_irq < 0) - return pp->msi_irq; + if (pp->msi_irq < 0) { + ret = pp->msi_irq; + goto err_pm_runtime_put; + } } ret = phy_init(pcie->phy); if (ret) { pm_runtime_disable(&pdev->dev); - return ret; + goto err_pm_runtime_put; } platform_set_drvdata(pdev, pcie); @@ -1299,10 +1315,16 @@ static int qcom_pcie_probe(struct platform_device *pdev) if (ret) { dev_err(dev, "cannot initialize host\n"); pm_runtime_disable(&pdev->dev); - return ret; + goto err_pm_runtime_put; } return 0; + +err_pm_runtime_put: + pm_runtime_put(dev); + pm_runtime_disable(dev); + + return ret; } static const struct of_device_id qcom_pcie_match[] = {