From patchwork Fri Oct 31 10:12:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 5203661 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0CA379F30B for ; Fri, 31 Oct 2014 10:12:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0B0B320173 for ; Fri, 31 Oct 2014 10:12:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 99257200FF for ; Fri, 31 Oct 2014 10:12:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756896AbaJaKMq (ORCPT ); Fri, 31 Oct 2014 06:12:46 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:43953 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756230AbaJaKMq (ORCPT ); Fri, 31 Oct 2014 06:12:46 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NEB00AWI0HZGR20@mailout3.w1.samsung.com>; Fri, 31 Oct 2014 10:15:35 +0000 (GMT) X-AuditID: cbfec7f4-b7f6c6d00000120b-9b-5453609be6a9 Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id A2.AF.04619.B9063545; Fri, 31 Oct 2014 10:12:43 +0000 (GMT) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync2.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0NEB007QG0D3LE80@eusync2.samsung.com>; Fri, 31 Oct 2014 10:12:43 +0000 (GMT) From: Marek Szyprowski To: linux-usb@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Kyungmin Park , Robert Baldyga , Paul Zimmerman , Krzysztof Kozlowski , Felipe Balbi Subject: [PATCH v3 1/2] usb: dwc2/gadget: add mutex to serialize init/deinit calls Date: Fri, 31 Oct 2014 11:12:33 +0100 Message-id: <1414750354-19571-1-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <54535F82.7020406@samsung.com> References: <54535F82.7020406@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrMJMWRmVeSWpSXmKPExsVy+t/xK7qzE4JDDPp+MlkcvF9v8fqFocXZ pjfsFjPO72OyWLSsldli7ZG77Bbbp0xnsnhweCe7A4dH35ZVjB5b9n9m9Dh+YzuTx+dNcgEs UVw2Kak5mWWpRfp2CVwZ+47HFuyVrfi09hJzA+M/8S5GTg4JAROJb4unMkPYYhIX7q1n62Lk 4hASWMoo0dywgBnC6WOS+Px1FwtIFZuAoUTX2y42EFtEwEFiydI7YDazwE9GiUs/+EBsYYEQ ie/vH7KD2CwCqhJPf58B28Ar4CHxY9ocqG1yEv9frmACsTkFtCW+9G8FiwsJaEn8fNbPOIGR dwEjwypG0dTS5ILipPRcQ73ixNzi0rx0veT83E2MkID6soNx8TGrQ4wCHIxKPLwrJINDhFgT y4orcw8xSnAwK4nwirgDhXhTEiurUovy44tKc1KLDzEycXBKNTC2F0bt3Wxm8HyS1dfFEVeN 979ZYrjmg77A04+vNLeuf+XYH9Tpv8LZ/e8lwR8X0tJyNBllDxd8KeCefcX3wCOuuXYz6yRq ZXxmBbcxdaU5yWnGzki9k+8n1mb+QNlZ94fcH16Nci3GGRUXpmxarday0ursod99Mc27LNYE XlLZX13w+uw/B3MlluKMREMt5qLiRAA7PMSZBgIAAA== Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds mutex, which protects initialization and deinitialization procedures against suspend/resume methods. Signed-off-by: Marek Szyprowski Acked-by: Paul Zimmerman --- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 9f77b4d1c5ff..58732a9a0019 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -187,6 +187,7 @@ struct s3c_hsotg { struct s3c_hsotg_plat *plat; spinlock_t lock; + struct mutex init_mutex; void __iomem *regs; int irq; diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index d8dda39c9e16..a2e4272a904e 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -2908,6 +2909,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget, return -EINVAL; } + mutex_lock(&hsotg->init_mutex); WARN_ON(hsotg->driver); driver->driver.bus = NULL; @@ -2933,9 +2935,12 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget, dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name); + mutex_unlock(&hsotg->init_mutex); + return 0; err: + mutex_unlock(&hsotg->init_mutex); hsotg->driver = NULL; return ret; } @@ -2957,6 +2962,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget, if (!hsotg) return -ENODEV; + mutex_lock(&hsotg->init_mutex); + /* all endpoints should be shutdown */ for (ep = 1; ep < hsotg->num_of_eps; ep++) s3c_hsotg_ep_disable(&hsotg->eps[ep].ep); @@ -2974,6 +2981,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget, clk_disable(hsotg->clk); + mutex_unlock(&hsotg->init_mutex); + return 0; } @@ -3002,6 +3011,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) dev_dbg(hsotg->dev, "%s: is_on: %d\n", __func__, is_on); + mutex_lock(&hsotg->init_mutex); spin_lock_irqsave(&hsotg->lock, flags); if (is_on) { clk_enable(hsotg->clk); @@ -3013,6 +3023,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) hsotg->gadget.speed = USB_SPEED_UNKNOWN; spin_unlock_irqrestore(&hsotg->lock, flags); + mutex_unlock(&hsotg->init_mutex); return 0; } @@ -3507,6 +3518,7 @@ static int s3c_hsotg_probe(struct platform_device *pdev) } spin_lock_init(&hsotg->lock); + mutex_init(&hsotg->init_mutex); hsotg->irq = ret; @@ -3652,6 +3664,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) unsigned long flags; int ret = 0; + mutex_lock(&hsotg->init_mutex); + if (hsotg->driver) dev_info(hsotg->dev, "suspending usb gadget %s\n", hsotg->driver->driver.name); @@ -3674,6 +3688,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) clk_disable(hsotg->clk); } + mutex_unlock(&hsotg->init_mutex); + return ret; } @@ -3683,7 +3699,9 @@ static int s3c_hsotg_resume(struct platform_device *pdev) unsigned long flags; int ret = 0; + mutex_lock(&hsotg->init_mutex); if (hsotg->driver) { + dev_info(hsotg->dev, "resuming usb gadget %s\n", hsotg->driver->driver.name); @@ -3699,6 +3717,8 @@ static int s3c_hsotg_resume(struct platform_device *pdev) s3c_hsotg_core_connect(hsotg); spin_unlock_irqrestore(&hsotg->lock, flags); + mutex_unlock(&hsotg->init_mutex); + return ret; }