From patchwork Wed Feb 28 13:38:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcus Folkesson X-Patchwork-Id: 10247545 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 5507F60211 for ; Wed, 28 Feb 2018 13:38:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4531E28D2A for ; Wed, 28 Feb 2018 13:38:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A24928D34; Wed, 28 Feb 2018 13:38:51 +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 E0D3328D2A for ; Wed, 28 Feb 2018 13:38:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752735AbeB1NiW (ORCPT ); Wed, 28 Feb 2018 08:38:22 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:41375 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752713AbeB1NiV (ORCPT ); Wed, 28 Feb 2018 08:38:21 -0500 Received: by mail-lf0-f67.google.com with SMTP id m69so3543979lfe.8; Wed, 28 Feb 2018 05:38:20 -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:in-reply-to:references; bh=0BnArDIbAtzrQheykUmQHqaq9S/8YmXA0XlOjw7gNTg=; b=DSOoM4Mz12Jb/0iaFz7hASwf8iG4DoDW5GcyHukuA0ftijVbKhaYbqdu4U1f9lYoRI MvRpsyD2ZdZ69W2qfIowKBO/Y6nx0wZNqQlJB+dtIUvPECAYmA6/rWa2nF/X4yzQktWY xb/2BA3tN/XKbC35u3xenUCc1X7lXXjfosecAFzMotHhzOdK2MNn+X3O7P3AbS2+Rl0x 0QPEZerL+O53MqmfVtjgtAforKZZRM1ZhqyeX6SrtXcywUppHiEtxGg1Juw9P/qTm8Dr kFhEjiUymudMx1ayxxBm64AKaXRkAH7GMHS96C7QLSM992sUQb+2zRy/RL847NPSgKQT vj4A== 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:in-reply-to :references; bh=0BnArDIbAtzrQheykUmQHqaq9S/8YmXA0XlOjw7gNTg=; b=dRwPnKLuYfzY5XsXlU6OvK1pU78HiJLZknqoA9dyZ3a5KKeGcXWcOqup2NetEmOIVC 2PsVdYWQmKm+n1lz3uENU0j4zPHgUovUJ1ht2k3Ptf9xv8JAobBtsIILgPT4KdWdHKhC G5YykOKhVuSg0BjkVqJz6bk3l1FnTw3Mj3DM8MSZzl6t3r0XKKmjvCIms2NBX6dYYaxd 5+AUwuKTWtSOGFY+HNvS0RoTKOcAp/B2EhNVe+4qtpBdhU8meOY+XXIuSApo6nptwO+5 1sfXZxEnFssL9Tuk5wQo+UCaVIcoOH2YAKR9Zhdh9t69zjagPdxBgOsIFhB+FPI7YKfF D+5g== X-Gm-Message-State: APf1xPBnvQyUGnCVz/SlIJ7X27UkmTOApUbLu4xT9V35KaMBX3UltcKf UODNKN8BBvYEWlhitrDyLSs= X-Google-Smtp-Source: AH8x225LYusQxf+YqrGKqXvKGVFJdSfHn1qUTFKHvdqdGnh6NqBARmQZ/bfbF0gIE1iAGsIgQXVbKQ== X-Received: by 10.46.25.209 with SMTP id 78mr12943984ljz.29.1519825099550; Wed, 28 Feb 2018 05:38:19 -0800 (PST) Received: from localhost.localdomain (c-2ec257a5-74736162.cust.telenor.se. [46.194.87.165]) by smtp.gmail.com with ESMTPSA id f70sm373992lfi.4.2018.02.28.05.38.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2018 05:38:18 -0800 (PST) From: Marcus Folkesson To: Dmitry Torokhov , Arvind Yadav Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Marcus Folkesson Subject: [RESEND PATCH 5/6] input: usbtouchscreen: fix deadlock in autosuspend Date: Wed, 28 Feb 2018 14:38:02 +0100 Message-Id: <20180228133803.30040-6-marcus.folkesson@gmail.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180228133803.30040-1-marcus.folkesson@gmail.com> References: <20180228133803.30040-1-marcus.folkesson@gmail.com> 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; }