From patchwork Fri Jun 10 11:37:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 69758 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp244519qgf; Fri, 10 Jun 2016 04:38:05 -0700 (PDT) X-Received: by 10.67.7.71 with SMTP id da7mr1899284pad.136.1465558685085; Fri, 10 Jun 2016 04:38:05 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f62si12874126pfa.18.2016.06.10.04.38.04; Fri, 10 Jun 2016 04:38:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932571AbcFJLiB (ORCPT + 30 others); Fri, 10 Jun 2016 07:38:01 -0400 Received: from comal.ext.ti.com ([198.47.26.152]:34651 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752583AbcFJLiA (ORCPT ); Fri, 10 Jun 2016 07:38:00 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id u5ABbe5E015378; Fri, 10 Jun 2016 06:37:40 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id u5ABbvL3021481; Fri, 10 Jun 2016 06:37:57 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.294.0; Fri, 10 Jun 2016 06:37:57 -0500 Received: from [192.168.2.6] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id u5ABbtgY029167; Fri, 10 Jun 2016 06:37:56 -0500 Subject: [PATCH v2] usb: dwc3: fix runtime PM in error path To: , References: <1465548878-30085-1-git-send-email-rogerq@ti.com> CC: , From: Roger Quadros Message-ID: <575AA693.8030001@ti.com> Date: Fri, 10 Jun 2016 14:37:55 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: <1465548878-30085-1-git-send-email-rogerq@ti.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If there is a failure after pm_runtime_enable/get_sync() we need to call pm_runtime_disable/put_sync(). Otherwise it will lead to an unbalanced pm_runtime_enable() on the subsequent probe if the earlier probe bailed out due to -EPROBE_DEFER. pm_runtime_get_sync() can fail as well so deal with that case too. Signed-off-by: Roger Quadros --- v2: - deal with pm_runtime_get_sync() failure drivers/usb/dwc3/core.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) -- 2.7.4 diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 131e7eb..d51c9a9 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -959,14 +959,17 @@ static int dwc3_probe(struct platform_device *pdev) pm_runtime_use_autosuspend(dev); pm_runtime_set_autosuspend_delay(dev, DWC3_DEFAULT_AUTOSUSPEND_DELAY); pm_runtime_enable(dev); - pm_runtime_get_sync(dev); + ret = pm_runtime_get_sync(dev); + if (ret < 0) + goto err1; + pm_runtime_forbid(dev); ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); if (ret) { dev_err(dwc->dev, "failed to allocate event buffers\n"); ret = -ENOMEM; - goto err0; + goto err2; } if (IS_ENABLED(CONFIG_USB_DWC3_HOST) && @@ -983,12 +986,12 @@ static int dwc3_probe(struct platform_device *pdev) ret = dwc3_alloc_scratch_buffers(dwc); if (ret) - goto err1; + goto err3; ret = dwc3_core_init(dwc); if (ret) { dev_err(dev, "failed to initialize core\n"); - goto err2; + goto err4; } /* Check the maximum_speed parameter */ @@ -1020,23 +1023,29 @@ static int dwc3_probe(struct platform_device *pdev) ret = dwc3_core_init_mode(dwc); if (ret) - goto err3; + goto err5; dwc3_debugfs_init(dwc); pm_runtime_put(dev); return 0; -err3: +err5: dwc3_event_buffers_cleanup(dwc); -err2: +err4: dwc3_free_scratch_buffers(dwc); -err1: +err3: dwc3_free_event_buffers(dwc); dwc3_ulpi_exit(dwc); +err2: + pm_runtime_allow(&pdev->dev); +err1: + pm_runtime_put_sync(&pdev->dev); + pm_runtime_disable(&pdev->dev); + err0: /* * restore res->start back to its original value so that, in case the