From patchwork Tue Jan 12 10:09:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 59602 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2644039lbb; Tue, 12 Jan 2016 02:10:40 -0800 (PST) X-Received: by 10.67.14.74 with SMTP id fe10mr190264029pad.151.1452593440462; Tue, 12 Jan 2016 02:10:40 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bf9si7201886pac.163.2016.01.12.02.10.39; Tue, 12 Jan 2016 02:10:40 -0800 (PST) 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; dkim=pass header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762035AbcALKKd (ORCPT + 29 others); Tue, 12 Jan 2016 05:10:33 -0500 Received: from mail-wm0-f53.google.com ([74.125.82.53]:38387 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752970AbcALKKY (ORCPT ); Tue, 12 Jan 2016 05:10:24 -0500 Received: by mail-wm0-f53.google.com with SMTP id b14so311415368wmb.1 for ; Tue, 12 Jan 2016 02:10:23 -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; bh=V3OYMP7LXvfn8ad4PhuniBHWruxZzKT8kCeCP3mIlEI=; b=VCgXvnXajgElwmKcr566a7P61XiyQGtBx0pv0iYj3sgMzqtbTCnAE3U8YG6rGCuf2d YWYIcoznLhl1WvEGyPPujTy1jpUrjElEcJYUMv4L8Op514k1/b923JMQIreAdNrxLKc0 cOUlNhhU/TG5VhVwVD3UJimO4mliYJBEfDR3g= 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; bh=V3OYMP7LXvfn8ad4PhuniBHWruxZzKT8kCeCP3mIlEI=; b=SVqTwpEiD4vZnZd+rVBO8tcorO81NG4riSTN3s+9M0w8FWZZQ4w/pE2W4CdVJzqFW/ WGwssl/abd0tbsZXXd3NVg6BVetGtR407Zw7AWQDBjv6ehaGdEOj+ir+iemAskSgLdUZ vlkIpVU2J/e4KMBbr1CfnWESsi3ktlqIR1+EvX0Z0PRMpqgmJTx1yA06Qt6O18JY1krn 3DU4fQnoxtuhBZslPEYBxdTBPqLJiV7Ge6VDyCdDcTgc5vn1E9coC/QylGMYx9QGzBch RmLIcE8hx67MWMBSiLuP8x6f7XWQZoxZwiA/is07hzEPYsacFvISJLpTGJpUcIzWQZpV 1xOQ== X-Gm-Message-State: ALoCoQnu5s5xfGJ6YwL1BxhI1RKDBTpupsV0CMcZ39NQWfKNSyegu0X877Qj/WfZKIkv9DkU4XErEsZ1w9vuRNpH11lhHQ4dnQ== X-Received: by 10.194.173.233 with SMTP id bn9mr138751254wjc.1.1452593423142; Tue, 12 Jan 2016 02:10:23 -0800 (PST) Received: from localhost.localdomain (host-92-13-246-184.as43234.net. [92.13.246.184]) by smtp.gmail.com with ESMTPSA id c203sm16813338wmd.5.2016.01.12.02.10.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Jan 2016 02:10:22 -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 Subject: [PATCH] usb: phy: msm: fix error handling in probe. Date: Tue, 12 Jan 2016 10:09:36 +0000 Message-Id: <1452593376-7163-1-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 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 Signed-off-by: Srinivas Kandagatla --- drivers/usb/phy/phy-msm-usb.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) -- 1.9.1 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; }