From patchwork Wed Jan 13 09:13:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 59657 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp3235983lbb; Wed, 13 Jan 2016 01:13:29 -0800 (PST) X-Received: by 10.98.10.66 with SMTP id s63mr41405636pfi.119.1452676409243; Wed, 13 Jan 2016 01:13:29 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p77si749843pfa.42.2016.01.13.01.13.29; Wed, 13 Jan 2016 01:13:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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 stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932117AbcAMJN1 (ORCPT + 2 others); Wed, 13 Jan 2016 04:13:27 -0500 Received: from mail-wm0-f41.google.com ([74.125.82.41]:33632 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932513AbcAMJNP (ORCPT ); Wed, 13 Jan 2016 04:13:15 -0500 Received: by mail-wm0-f41.google.com with SMTP id f206so286690323wmf.0 for ; Wed, 13 Jan 2016 01:13:14 -0800 (PST) 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:references; bh=t5vgtILaAlPdxq5k21DiKSpm3SAVrIhOy2TQcSaMK4o=; b=ShczKU/oJCUkq39uk7vpj7tI9/0s90QY5Ahtz9stH8Hl8Ngyar9KL13nUZxQr1hg/E +ztMQgfACyiKCusqVaSjSdWU8Z+R9AuZsoSQsLxl6sqDrxHgdsjF5oV8TFJAnEeVpkog 1TpJromRoWO/tfEnUiWySJRvGBdijag3SNpGM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=t5vgtILaAlPdxq5k21DiKSpm3SAVrIhOy2TQcSaMK4o=; b=SWV9rQebDhEBcnYh33SgK7l5WiJ3WfNdmnJcCz51Gd1TYgV8g+CwTeZg7AN1WrHi/q LrwyOp6fBUtzhXn9kSw0uIcldbp4QlWuFifyXD6LjCXV0PASIEN/JSJQVh/AiVqRutj+ QMdl9D6QosKBEgzvod5yJrX1fqfnbxqcGoDdKsXgLFeqMMV0GRp0G8cAboQak284L7pC MUYSoBWaT1h2tKYznLkUIia2Ft/p2msy6PIgHWdQLFLoZIL7XpAXCIq6eN7nB1iL4lE0 I7rWl3hnx8eyva4lfmlyMnNCyg7T+ifexWc1+i8/gwhmIpeuQZh1mtD06+Nkkv6pttvt rp9A== X-Gm-Message-State: ALoCoQmjiCJ1zMCyr8nAfehKkUZXnrmwd10qgGUsViiDEmuOni0LvVnZI0Dj0JhwKK6JtyLdNbSL8ZA7L3HKikiRFFG61qKKYg== X-Received: by 10.194.71.172 with SMTP id w12mr104145044wju.77.1452676393904; Wed, 13 Jan 2016 01:13:13 -0800 (PST) Received: from localhost.localdomain (host-92-13-246-184.as43234.net. [92.13.246.184]) by smtp.gmail.com with ESMTPSA id r10sm443339wjz.24.2016.01.13.01.13.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Jan 2016 01:13:13 -0800 (PST) From: Srinivas Kandagatla To: Felipe Balbi , linux-usb@vger.kernel.org Cc: tim.bird@sonymobile.com, linux-arm-msm@vger.kernel.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org, ivan.ivanov@linaro.org, Srinivas Kandagatla , Stable Subject: [PATCH v2] usb: phy: msm: fix error handling in probe. Date: Wed, 13 Jan 2016 09:13:10 +0000 Message-Id: <1452676390-31269-1-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1452593376-7163-1-git-send-email-srinivas.kandagatla@linaro.org> References: <1452593376-7163-1-git-send-email-srinivas.kandagatla@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org This driver registers for extcon events as part of its probe, but never unregisters them in case of error in the probe path. There were multiple issues noticed due to this missing error handling. One of them is random crashes if the regulators are not ready yet by the time probe is invoked. Ivan's previous attempt [1] to fix this issue, did not really address all the failure cases like regualtor/get_irq failures. [1] https://lkml.org/lkml/2015/9/7/62 Without this patch the kernel would carsh with log: ... Unable to handle kernel paging request at virtual address 17d78410 pgd = ffffffc001a5c000 [17d78410] *pgd=00000000b6806003, *pud=00000000b6806003, *pmd=0000000000000000 Internal error: Oops: 96000005 [#1] PREEMPT SMP Modules linked in: CPU: 0 PID: 6 Comm: kworker/u8:0 Not tainted 4.4.0+ #48 Hardware name: Qualcomm Technologies, Inc. APQ 8016 SBC (DT) Workqueue: deferwq deferred_probe_work_func task: ffffffc03686e900 ti: ffffffc0368b0000 task.ti: ffffffc0368b0000 PC is at raw_notifier_chain_register+0x1c/0x44 LR is at extcon_register_notifier+0x88/0xc8 pc : [] lr : [] pstate: 80000085 sp : ffffffc0368b3a70 x29: ffffffc0368b3a70 x28: ffffffc03680c310 x27: ffffffc035518000 x26: ffffffc035518000 x25: ffffffc03bfa20e0 x24: ffffffc035580a18 x23: 0000000000000000 x22: ffffffc035518458 x21: ffffffc0355e9a60 x20: ffffffc035518000 x19: 0000000000000000 x18: 0000000000000028 x17: 0000000000000003 x16: ffffffc0018153c8 x15: 0000000000000001 x14: ffffffc03686f0f8 x13: ffffffc03686f0f8 x12: 0000000000000003 x11: 0000000000000001 x10: 0000000000000001 x9 : ffffffc03686f0f8 x8 : 0000e3872014c1a1 x7 : 0000000000000028 x6 : 0000000000000000 x5 : 0000000000000001 x4 : 0000000000000000 x3 : 00000000354fb170 x2 : 0000000017d78400 x1 : ffffffc0355e9a60 x0 : ffffffc0354fb268 Fixes: 591fc116f330 ("usb: phy: msm: Use extcon framework for VBUS and ID detection") CC: Stable Signed-off-by: Srinivas Kandagatla --- Changes since v1: -added fixes tag and CC stable drivers/usb/phy/phy-msm-usb.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe stable" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c index 0d19a6d..970a30e 100644 --- a/drivers/usb/phy/phy-msm-usb.c +++ b/drivers/usb/phy/phy-msm-usb.c @@ -1599,6 +1599,8 @@ static int msm_otg_read_dt(struct platform_device *pdev, struct msm_otg *motg) &motg->id.nb); if (ret < 0) { dev_err(&pdev->dev, "register ID notifier failed\n"); + extcon_unregister_notifier(motg->vbus.extcon, + EXTCON_USB, &motg->vbus.nb); return ret; } @@ -1660,15 +1662,6 @@ static int msm_otg_probe(struct platform_device *pdev) if (!motg) return -ENOMEM; - pdata = dev_get_platdata(&pdev->dev); - if (!pdata) { - if (!np) - return -ENXIO; - ret = msm_otg_read_dt(pdev, motg); - if (ret) - return ret; - } - motg->phy.otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg), GFP_KERNEL); if (!motg->phy.otg) @@ -1710,6 +1703,15 @@ static int msm_otg_probe(struct platform_device *pdev) if (!motg->regs) return -ENOMEM; + pdata = dev_get_platdata(&pdev->dev); + if (!pdata) { + if (!np) + return -ENXIO; + ret = msm_otg_read_dt(pdev, motg); + if (ret) + return ret; + } + /* * NOTE: The PHYs can be multiplexed between the chipidea controller * and the dwc3 controller, using a single bit. It is important that @@ -1717,8 +1719,10 @@ static int msm_otg_probe(struct platform_device *pdev) */ if (motg->phy_number) { phy_select = devm_ioremap_nocache(&pdev->dev, USB2_PHY_SEL, 4); - if (!phy_select) - return -ENOMEM; + if (!phy_select) { + ret = -ENOMEM; + goto unregister_extcon; + } /* Enable second PHY with the OTG port */ writel(0x1, phy_select); } @@ -1728,7 +1732,8 @@ static int msm_otg_probe(struct platform_device *pdev) motg->irq = platform_get_irq(pdev, 0); if (motg->irq < 0) { dev_err(&pdev->dev, "platform_get_irq failed\n"); - return motg->irq; + ret = motg->irq; + goto unregister_extcon; } regs[0].supply = "vddcx"; @@ -1737,7 +1742,7 @@ static int msm_otg_probe(struct platform_device *pdev) ret = devm_regulator_bulk_get(motg->phy.dev, ARRAY_SIZE(regs), regs); if (ret) - return ret; + goto unregister_extcon; motg->vddcx = regs[0].consumer; motg->v3p3 = regs[1].consumer; @@ -1834,6 +1839,12 @@ disable_clks: clk_disable_unprepare(motg->clk); if (!IS_ERR(motg->core_clk)) clk_disable_unprepare(motg->core_clk); +unregister_extcon: + extcon_unregister_notifier(motg->id.extcon, + EXTCON_USB_HOST, &motg->id.nb); + extcon_unregister_notifier(motg->vbus.extcon, + EXTCON_USB, &motg->vbus.nb); + return ret; }