From patchwork Fri May 25 19:09:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 136989 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp3966772lji; Fri, 25 May 2018 12:09:40 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp0Sw1HDn+0T7vv9nWrrfqgUhrdEJ1ZF+MWLFz1zzcaWAiMqACjxwSig27XqP9yo1ZQzFZB X-Received: by 2002:a17:902:6686:: with SMTP id e6-v6mr3800141plk.35.1527275380711; Fri, 25 May 2018 12:09:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527275380; cv=none; d=google.com; s=arc-20160816; b=XcLjv1qDXk5ZToxVLv3EnexA7Ug/SQNqimfZTOYBVVSx/OtjmStENNJpwg7BL8RgzC G4fEHavzMeb3RvFhKFomcU16Do6+SEnXd56r+c+Wl/6447QNe1kFANE2KLvMxu2rOuXG vWVvc8Upxq1NGU2MkdvOvBoFciqH6qrdvTFrXcsNLz0ddX6IfichXTnEKvTWv9fdcsS5 pDT/WnrbbLu1IajxWgIGv1p/Vzv9keIAh1FH1hQoKjbPMVsnpmBy1QRb2SSAx/JPBRjd WL7BVd0m0RJO8QLOC+EjZ95R978juuhI3D94IXkXnycrFBMtzwACnniX+rDT4dpRzh44 DHKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-authentication-results; bh=mcE1Q7HS46XJzx4SPiVFcNnITk8mRj+JyJ+B3yMZN48=; b=Czvkmx05S88651KguX3SltNo/pNdOWZAaGTOjtt5BWyNXbm+nPpPVDt4qcVBMb9YD8 6F0tI13/Ecxj1UX7UfXzSAdsVEG03DQ/WVpPuF2WAB9aJFdqtG7T+BFZxP1aI3AAJaby b2f7L5c6e9uyaS7sZAhqGqV4gBt4UGL/NtnbUh3pkbwsVMZ9IuTKoNRDz6uaHV0zhXxe GHqOq3rX6LGKK4o1YhE+iqygaI5g78QrVXDncPXC5NFVR2R9rJqug2bCMQDRidCM618b 5r3q4HLCVOLf9/GJ+d+1ZWl5dB59CtxpzaUFpCerl0SrWT4Ij3+lru2RaQLTBXNiyNWx n0ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=c5nu5bO6; 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=fail (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 n3-v6si23748262pld.116.2018.05.25.12.09.40; Fri, 25 May 2018 12:09:40 -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=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=c5nu5bO6; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967937AbeEYTJj (ORCPT + 13 others); Fri, 25 May 2018 15:09:39 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:36434 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967918AbeEYTJi (ORCPT ); Fri, 25 May 2018 15:09:38 -0400 Received: by mail-pg0-f66.google.com with SMTP id u7-v6so2667887pgp.3 for ; Fri, 25 May 2018 12:09:37 -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:in-reply-to; bh=f5au9HlA9dZ7LPZjTIRYERK6frK3jctlAW/xzEyIJV8=; b=c5nu5bO6ZQywC9AIWhrYjSOC2aOa0fqhVmyI4UWqOV+0+59TpNUV8QKgpEP6qNahDh WWbkhxliZ5utJpu9Mg7mEOKv4f7bd7URFQZ+zR5pQsQ6cQWsTs1K/IMaO+gCjAGEwPVs UnHu/D3qCRZtACBfvPDu40Bs4dWqECSq+fQVg= 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:in-reply-to; bh=f5au9HlA9dZ7LPZjTIRYERK6frK3jctlAW/xzEyIJV8=; b=LyRgIDDLJOw3pGO/gbdgdwYy7/tr08WyFUz+Dm+76sIaBqMBIqrLjzegszR4izLyuk Q2Av2XEwSCvfMSe2LX/gKxqNiXCCZQvriiEz5TibWucpxM8pAUylH7f1B9WAGymZ9HZO swfEM55ySc+fwb1RSv6by23ZJ1hLrbXbhOqMtEmhW+Yfrhv5MEvhY81EixdL2yT7mH/S bmYEhLXUSXfaBZnbuEEgT7HPT6SOpMnRGcD400XajQp02TmpyqkFdFuiuGDvKaW68eTl jNVm8/LRYldk6Ft+T95jxFxOJYcfq3Oa3KwD+UOA0kScTNmuR452ALdTMihsPayP5qiA jqBA== X-Gm-Message-State: ALKqPweJEvplnlMWtL8BI7MQ7jdzwuMkZ7wUFHE48MmAszjvKsmdSOL3 Yex7aCdC9vo/6Le405G7YC5tfw== X-Received: by 2002:a65:498e:: with SMTP id r14-v6mr2901009pgs.78.1527275377324; Fri, 25 May 2018 12:09:37 -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 y83-v6sm66706177pfd.21.2018.05.25.12.09.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 May 2018 12:09:36 -0700 (PDT) From: Bjorn Andersson To: Stanimir Varbanov , Lorenzo Pieralisi , Bjorn Helgaas Cc: Srinivas Kandagatla , linux-pci@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] PCI: qcom: Fix error handling in pm_runtime support Date: Fri, 25 May 2018 12:09:34 -0700 Message-Id: <20180525190934.1042-1-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180523104425.6650-1-srinivas.kandagatla@linaro.org> 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. Signed-off-by: Bjorn Andersson --- I'm sorry for not spotting this last week when we discussed the previous patch. drivers/pci/dwc/pcie-qcom.c | 65 ++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 19 deletions(-) -- 2.17.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Acked-by: Stanimir Varbanov diff --git a/drivers/pci/dwc/pcie-qcom.c b/drivers/pci/dwc/pcie-qcom.c index 3f35098b71b1..f2453196278f 100644 --- a/drivers/pci/dwc/pcie-qcom.c +++ b/drivers/pci/dwc/pcie-qcom.c @@ -1088,8 +1088,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); @@ -1126,7 +1124,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_sync(pci->dev); return ret; } @@ -1207,7 +1204,6 @@ static int qcom_pcie_probe(struct platform_device *pdev) struct qcom_pcie *pcie; int ret; - pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); if (!pcie) return -ENOMEM; @@ -1217,6 +1213,7 @@ static int qcom_pcie_probe(struct platform_device *pdev) return -ENOMEM; pm_runtime_enable(dev); + pm_runtime_get_sync(dev); pci->dev = dev; pci->ops = &dw_pcie_ops; @@ -1227,53 +1224,82 @@ 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->root_bus_nr = -1; 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) - return ret; + goto err_pm_runtime_put; platform_set_drvdata(pdev, pcie); ret = dw_pcie_host_init(pp); if (ret) { dev_err(dev, "cannot initialize host\n"); - return ret; + goto err_pm_runtime_put; } + return 0; + +err_pm_runtime_put: + pm_runtime_put(dev); + pm_runtime_disable(dev); + + return ret; +} + +static int qcom_pcie_remove(struct platform_device *pdev) +{ + struct qcom_pcie *pcie = platform_get_drvdata(pdev); + struct device *dev = pcie->pci->dev; + + pm_runtime_put(dev); + pm_runtime_disable(dev); + return 0; } @@ -1289,6 +1315,7 @@ static const struct of_device_id qcom_pcie_match[] = { static struct platform_driver qcom_pcie_driver = { .probe = qcom_pcie_probe, + .remove = qcom_pcie_remove, .driver = { .name = "qcom-pcie", .suppress_bind_attrs = true,