From patchwork Sun Jun 24 22:08:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 10484883 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8430E6019D for ; Sun, 24 Jun 2018 22:09:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11B16287CE for ; Sun, 24 Jun 2018 22:09:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03B53287F4; Sun, 24 Jun 2018 22:09:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15B5F287CE for ; Sun, 24 Jun 2018 22:09:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752034AbeFXWJC convert rfc822-to-8bit (ORCPT ); Sun, 24 Jun 2018 18:09:02 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:45320 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751979AbeFXWJA (ORCPT ); Sun, 24 Jun 2018 18:09:00 -0400 Received: from localhost ([127.0.0.1] helo=bazinga.breakpoint.cc) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1fXDBm-0000Vg-EW; Mon, 25 Jun 2018 00:08:54 +0200 From: Sebastian Andrzej Siewior To: linux-usb@vger.kernel.org Cc: tglx@linutronix.de, Greg Kroah-Hartman , Sebastian Andrzej Siewior , Oliver Neukum , =?UTF-8?q?Bj=C3=B8rn=20Mork?= Subject: [PATCH 02/12] usb: cdc-wdm: use irqsave() in USB's complete callback Date: Mon, 25 Jun 2018 00:08:35 +0200 Message-Id: <20180624220845.6726-3-bigeasy@linutronix.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180624220845.6726-1-bigeasy@linutronix.de> References: <20180624220845.6726-1-bigeasy@linutronix.de> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The USB completion callback does not disable interrupts while acquiring the lock. We want to remove the local_irq_disable() invocation from __usb_hcd_giveback_urb() and therefore it is required for the callback handler to disable the interrupts while acquiring the lock. The callback may be invoked either in IRQ or BH context depending on the USB host controller. Use the _irqsave() variant of the locking primitives. Cc: Greg Kroah-Hartman Cc: Oliver Neukum Cc: "Bjørn Mork" Signed-off-by: Sebastian Andrzej Siewior --- drivers/usb/class/cdc-wdm.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c index 203bbd378858..bec581fb7c63 100644 --- a/drivers/usb/class/cdc-wdm.c +++ b/drivers/usb/class/cdc-wdm.c @@ -142,10 +142,12 @@ static struct wdm_device *wdm_find_device_by_minor(int minor) static void wdm_out_callback(struct urb *urb) { struct wdm_device *desc; + unsigned long flags; + desc = urb->context; - spin_lock(&desc->iuspin); + spin_lock_irqsave(&desc->iuspin, flags); desc->werr = urb->status; - spin_unlock(&desc->iuspin); + spin_unlock_irqrestore(&desc->iuspin, flags); kfree(desc->outbuf); desc->outbuf = NULL; clear_bit(WDM_IN_USE, &desc->flags); @@ -154,11 +156,12 @@ static void wdm_out_callback(struct urb *urb) static void wdm_in_callback(struct urb *urb) { + unsigned long flags; struct wdm_device *desc = urb->context; int status = urb->status; int length = urb->actual_length; - spin_lock(&desc->iuspin); + spin_lock_irqsave(&desc->iuspin, flags); clear_bit(WDM_RESPONDING, &desc->flags); if (status) { @@ -220,11 +223,12 @@ static void wdm_in_callback(struct urb *urb) set_bit(WDM_READ, &desc->flags); wake_up(&desc->wait); } - spin_unlock(&desc->iuspin); + spin_unlock_irqrestore(&desc->iuspin, flags); } static void wdm_int_callback(struct urb *urb) { + unsigned long flags; int rv = 0; int responding; int status = urb->status; @@ -284,7 +288,7 @@ static void wdm_int_callback(struct urb *urb) goto exit; } - spin_lock(&desc->iuspin); + spin_lock_irqsave(&desc->iuspin, flags); responding = test_and_set_bit(WDM_RESPONDING, &desc->flags); if (!desc->resp_count++ && !responding && !test_bit(WDM_DISCONNECTING, &desc->flags) @@ -292,7 +296,7 @@ static void wdm_int_callback(struct urb *urb) rv = usb_submit_urb(desc->response, GFP_ATOMIC); dev_dbg(&desc->intf->dev, "submit response URB %d\n", rv); } - spin_unlock(&desc->iuspin); + spin_unlock_irqrestore(&desc->iuspin, flags); if (rv < 0) { clear_bit(WDM_RESPONDING, &desc->flags); if (rv == -EPERM)