From patchwork Mon Mar 16 07:36:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 6015801 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BD8ADBF90F for ; Mon, 16 Mar 2015 07:36:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B85B22046F for ; Mon, 16 Mar 2015 07:36:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 911CF20461 for ; Mon, 16 Mar 2015 07:36:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750844AbbCPHg5 (ORCPT ); Mon, 16 Mar 2015 03:36:57 -0400 Received: from relmlor4.renesas.com ([210.160.252.174]:61919 "EHLO relmlie3.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750822AbbCPHg4 (ORCPT ); Mon, 16 Mar 2015 03:36:56 -0400 Received: from unknown (HELO relmlir1.idc.renesas.com) ([10.200.68.151]) by relmlie3.idc.renesas.com with ESMTP; 16 Mar 2015 16:36:55 +0900 Received: from relmlac4.idc.renesas.com (relmlac4.idc.renesas.com [10.200.69.24]) by relmlir1.idc.renesas.com (Postfix) with ESMTP id 95ADE47CE0; Mon, 16 Mar 2015 16:36:55 +0900 (JST) Received: by relmlac4.idc.renesas.com (Postfix, from userid 0) id 83821480A4; Mon, 16 Mar 2015 16:36:55 +0900 (JST) Received: from relmlac4.idc.renesas.com (localhost [127.0.0.1]) by relmlac4.idc.renesas.com (Postfix) with ESMTP id 7CB69480A3; Mon, 16 Mar 2015 16:36:55 +0900 (JST) Received: from relmlii2.idc.renesas.com [10.200.68.66] by relmlac4.idc.renesas.com with ESMTP id SAJ27485; Mon, 16 Mar 2015 16:36:55 +0900 X-IronPort-AV: E=Sophos;i="5.11,407,1422889200"; d="scan'208";a="183137756" Received: from mail-hk1lp0123.outbound.protection.outlook.com (HELO APAC01-HK1-obe.outbound.protection.outlook.com) ([207.46.51.123]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA; 16 Mar 2015 16:36:55 +0900 Received: from localhost (211.11.155.147) by HKNPR06MB322.apcprd06.prod.outlook.com (10.141.38.16) with Microsoft SMTP Server (TLS) id 15.1.112.19; Mon, 16 Mar 2015 07:36:53 +0000 From: Yoshihiro Shimoda To: , CC: , , Yoshihiro Shimoda Subject: [PATCH v3] usb: renesas_usbhs: fix spinlock suspected in a gadget complete function Date: Mon, 16 Mar 2015 16:36:48 +0900 Message-ID: <1426491408-504-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.4.msysgit.1 MIME-Version: 1.0 X-Originating-IP: [211.11.155.147] X-ClientProxiedBy: TY1PR0201CA0036.apcprd02.prod.outlook.com (25.164.90.174) To HKNPR06MB322.apcprd06.prod.outlook.com (10.141.38.16) Authentication-Results: linuxfoundation.org; dkim=none (message not signed) header.d=none; X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HKNPR06MB322; X-Microsoft-Antispam-PRVS: X-Forefront-Antispam-Report: BMV:1; SFV:NSPM; SFS:(10019020)(6069001)(6009001)(50466002)(40100003)(76506005)(42382002)(42186005)(48376002)(92566002)(78352002)(122386002)(33646002)(229853001)(50226001)(47776003)(36756003)(77156002)(19580405001)(19580395003)(50986999)(66066001)(62966003)(46102003)(87976001)(77096005); DIR:OUT; SFP:1102; SCL:1; SRVR:HKNPR06MB322; H:localhost; FPR:; SPF:None; MLV:sfv; LANG:en; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(5002010); SRVR:HKNPR06MB322; BCL:0; PCL:0; RULEID:; SRVR:HKNPR06MB322; X-Forefront-PRVS: 05177D47DC X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Mar 2015 07:36:53.9606 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HKNPR06MB322 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 According to the gadget.h, a "complete" function will always be called with interrupts disabled. However, sometimes usbhsg_queue_pop() function is called with interrupts enabled. So, this function should be held by usbhs_lock() to disable interruption. Also, this driver has to call spin_unlock() to avoid spinlock recursion by this driver before calling usb_gadget_giveback_request(). Otherwise, there is possible to cause a spinlock suspected in a gadget complete function. Signed-off-by: Yoshihiro Shimoda --- Changes from v2: - This patch is based on Felipe's usb.git / testing/next branch. (commit id = 46f5cace1cd0559c335dfd4a5b8f57456d1bd6a1) - Use usbhs_lock() to disable interruption instead of local_irq_save(). - Modify the commit log. Changes from v1: - Change local_irq_save/restore() area. - Modify the commit log. drivers/usb/renesas_usbhs/mod_gadget.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c index e0384af..dc2aa32 100644 --- a/drivers/usb/renesas_usbhs/mod_gadget.c +++ b/drivers/usb/renesas_usbhs/mod_gadget.c @@ -119,18 +119,34 @@ struct usbhsg_recip_handle { /* * queue push/pop */ -static void usbhsg_queue_pop(struct usbhsg_uep *uep, - struct usbhsg_request *ureq, - int status) +static void __usbhsg_queue_pop(struct usbhsg_uep *uep, + struct usbhsg_request *ureq, + int status) { struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); struct device *dev = usbhsg_gpriv_to_dev(gpriv); + struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); dev_dbg(dev, "pipe %d : queue pop\n", usbhs_pipe_number(pipe)); ureq->req.status = status; + spin_unlock(usbhs_priv_to_lock(priv)); usb_gadget_giveback_request(&uep->ep, &ureq->req); + spin_lock(usbhs_priv_to_lock(priv)); +} + +static void usbhsg_queue_pop(struct usbhsg_uep *uep, + struct usbhsg_request *ureq, + int status) +{ + struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); + struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); + unsigned long flags; + + usbhs_lock(priv, flags); + __usbhsg_queue_pop(uep, ureq, status); + usbhs_unlock(priv, flags); } static void usbhsg_queue_done(struct usbhs_priv *priv, struct usbhs_pkt *pkt)