From patchwork Wed Jan 24 15:47:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcus Folkesson X-Patchwork-Id: 10182771 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 D6BB3602B7 for ; Wed, 24 Jan 2018 15:49:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3EC7288B2 for ; Wed, 24 Jan 2018 15:49:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B7B6D28902; Wed, 24 Jan 2018 15:49:10 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 6822B288B2 for ; Wed, 24 Jan 2018 15:49:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934292AbeAXPr1 (ORCPT ); Wed, 24 Jan 2018 10:47:27 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:37475 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934225AbeAXPrX (ORCPT ); Wed, 24 Jan 2018 10:47:23 -0500 Received: by mail-lf0-f67.google.com with SMTP id f3so5831072lfe.4; Wed, 24 Jan 2018 07:47:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=s90Asmq4wiEgEv529IM0xqKSmUABhKN2XcF68WaoYTA=; b=EPBkwLrb0Mhob26aLtv0IowPQRL2oUqe7fN68/EkrT1biBNQ0lfclx0kh4c4PimR66 ZIjbsCzrPhZbUABRoVKvg2cIm18Zzhi2q9JX0NzY50D0m4GL0a8jYgJWQpPcG+E0UOX+ h5VhsXaBaOqGzhVPNMuBu96RgoULrPzYvvaIZtGREYIf1c1HDstrRdBd/XVRrAAKO8l3 4oHN2FSxAxYZw8L6GLJKcBsTRl0eiBj6r+HOkeFsRW19/PsOAXwqeKH5AC0nF1N/gaey OZNPnD5csPCiMwI9Lo3fkZ/UV/Pje/zp6wN465/5vm9W6ZK/CNB9oLbB4rqy4NnFP0Rq 5j7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=s90Asmq4wiEgEv529IM0xqKSmUABhKN2XcF68WaoYTA=; b=mFiJReUvItUrJc40MlHWDqLC1O/N+siXFJmDrPIwBr/BM5NsBiiNdN+zqExUZsOao6 PZ0BagqDd+0/K31BrDcE2tXH/6hpEEwQBu0x6Ly+zSElrj34ignejDvZqa1Dz7PyFcTq hWX1YZJPaC7HHtRwhIqCXYvIRNBMoD6qzoL92F43CPQL/uFMviM7yf6aMlm0bomdUDKK 3+B6NtcKirnKPaoIkdWo9Dnl0VeVkLexr5DVk064Cf10wl3+kZtJz/psm51PnEIDO2/+ lcYk15elFIYXWoRFs9ndzAL/ohCmqGUM+Iw5OvTayadDWWhYdTKOHYL6J/XDp5R/l6di l3Hw== X-Gm-Message-State: AKwxytd366Q4M3c+cYYreZAmIoHX6JBIgng77w/XTKU8AQts/HDkAry9 Y/nnepdnqD5FXang4TuErOf6ugGJ X-Google-Smtp-Source: AH8x224by+0ksQ7/t1wym5o5f5XQLXAP2H7IqFlEW/27nOgzy7h9Xwr5UpnqAQzAghtn+9Xrn43zVw== X-Received: by 10.25.223.83 with SMTP id q19mr3102050lfj.45.1516808841502; Wed, 24 Jan 2018 07:47:21 -0800 (PST) Received: from localhost.localdomain ([81.236.84.183]) by smtp.gmail.com with ESMTPSA id t6sm121711ljb.7.2018.01.24.07.47.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jan 2018 07:47:20 -0800 (PST) From: Marcus Folkesson To: Dmitry Torokhov Cc: Marcus Folkesson , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] input: usbtouchscreen: fix deadlock in autosuspend Date: Wed, 24 Jan 2018 16:47:12 +0100 Message-Id: <20180124154713.28962-1-marcus.folkesson@gmail.com> X-Mailer: git-send-email 2.15.1 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP usb_autopm_get_interface() that is called in usbtouch_open() does an autoresume if the device is suspended. input_dev->mutex used in usbtouch_resume() is in this case already taken by the input subsystem and will cause a deadlock. Signed-off-by: Marcus Folkesson --- drivers/input/touchscreen/usbtouchscreen.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c index 2c41107240de..e964658203d8 100644 --- a/drivers/input/touchscreen/usbtouchscreen.c +++ b/drivers/input/touchscreen/usbtouchscreen.c @@ -54,6 +54,7 @@ #include #include #include +#include #define DRIVER_VERSION "v0.6" @@ -112,6 +113,7 @@ struct usbtouch_usb { struct usb_interface *interface; struct input_dev *input; struct usbtouch_device_info *type; + struct mutex pm_mutex; /* serialize access to open/suspend */ char name[128]; char phys[64]; void *priv; @@ -1455,6 +1457,7 @@ static int usbtouch_open(struct input_dev *input) if (r < 0) goto out; + mutex_lock(&usbtouch->pm_mutex); if (!usbtouch->type->irq_always) { if (usb_submit_urb(usbtouch->irq, GFP_KERNEL)) { r = -EIO; @@ -1464,6 +1467,7 @@ static int usbtouch_open(struct input_dev *input) usbtouch->interface->needs_remote_wakeup = 1; out_put: + mutex_unlock(&usbtouch->pm_mutex); usb_autopm_put_interface(usbtouch->interface); out: return r; @@ -1474,8 +1478,11 @@ static void usbtouch_close(struct input_dev *input) struct usbtouch_usb *usbtouch = input_get_drvdata(input); int r; + mutex_lock(&usbtouch->pm_mutex); if (!usbtouch->type->irq_always) usb_kill_urb(usbtouch->irq); + mutex_lock(&usbtouch->pm_mutex); + r = usb_autopm_get_interface(usbtouch->interface); usbtouch->interface->needs_remote_wakeup = 0; if (!r) @@ -1498,10 +1505,10 @@ static int usbtouch_resume(struct usb_interface *intf) struct input_dev *input = usbtouch->input; int result = 0; - mutex_lock(&input->mutex); + mutex_lock(&usbtouch->pm_mutex); if (input->users || usbtouch->type->irq_always) result = usb_submit_urb(usbtouch->irq, GFP_NOIO); - mutex_unlock(&input->mutex); + mutex_unlock(&usbtouch->pm_mutex); return result; } @@ -1524,10 +1531,10 @@ static int usbtouch_reset_resume(struct usb_interface *intf) } /* restart IO if needed */ - mutex_lock(&input->mutex); + mutex_lock(&usbtouch->pm_mutex); if (input->users) err = usb_submit_urb(usbtouch->irq, GFP_NOIO); - mutex_unlock(&input->mutex); + mutex_unlock(&usbtouch->pm_mutex); return err; }