From patchwork Wed Feb 28 13:38:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcus Folkesson X-Patchwork-Id: 10247547 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 7E4D360211 for ; Wed, 28 Feb 2018 13:38:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F33228D2A for ; Wed, 28 Feb 2018 13:38:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63DB128D34; Wed, 28 Feb 2018 13:38:59 +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 104CA28D2A for ; Wed, 28 Feb 2018 13:38:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752699AbeB1NiU (ORCPT ); Wed, 28 Feb 2018 08:38:20 -0500 Received: from mail-lf0-f66.google.com ([209.85.215.66]:45858 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752478AbeB1NiS (ORCPT ); Wed, 28 Feb 2018 08:38:18 -0500 Received: by mail-lf0-f66.google.com with SMTP id h127so2496483lfg.12; Wed, 28 Feb 2018 05:38:17 -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=UXVuNMbhj2ZOrNumEc5thQ4Oco5hzpkasIwLQp2D/SI=; b=G4vJydNFE2Abn7ypQCdkEmocwOgd/99fTb3O4QT56pQLSKMyDsjS6vSvuE91hoy16r l/pWRGzOfLQgE7AqKFfIT17Ln4BM253YOF8pzrqUgTrALUd/PjNkksogMrPP/wHJwxsy lOJfUDiPR3OG8kJhSwpe8qZ9uEytGH0I1zBQy2rS3w/q2FNk++JK2E7k5ojw+AIb0reG ca79LT4rCyX84JxbUK0yof9suuMIm1XRqSknu0P0b50UTXkkDfirbLYVaY37dULsgPgu eSR4gDhlgGySH3ta5dAeHJrC8Y8zbS3jr/Q1ny7H1Ziyk+vFdJue0hMYZxFCXH6D4kyV qjgA== 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=UXVuNMbhj2ZOrNumEc5thQ4Oco5hzpkasIwLQp2D/SI=; b=ikKR61rrNn4d35s9vdiSQsC6QyA1BVdh0Dd+zNPkDfoao2yhR9tlvcTJlpYsQw6iU7 nuOpkwNiY018qtWW6MkxNohFMI8f6EcGXNS3Pj4Fp6pmoRrFnaZvEu8v62ohyunbOet0 mVh6Irj1qXfaZPbI9dOqKudqF28jQnVZYtXfYxt+90+96ttXrvhxxWckEb7y5EnYh5Ii rI7wLrH6OxvdPCjOuVBNgo6l9wlh+uZA9mv6ILhzMKCZySUnvLzlzkUVnhvu42jl1YVw bLNLb7fG8DPdydE1Qep5c+D2UhPwmcfiSHX+2u2OKYo7QG2PTWx/3C194EpNpr9v1VBl 0/xQ== X-Gm-Message-State: APf1xPCGbkx1QydEWp01viravCF0/OQrk7Ip8pzxqfHL6XVKGfUoD7yZ 9J6YLeJtBZpvqpXjEaf2IKXCNg== X-Google-Smtp-Source: AG47ELtjQyR4GC/APiiD+BEIQw+fv5KkcjiCg85pAUkeQ0eYXjWjuQBiJe6jxgnLIdePYDFSNPWE0Q== X-Received: by 10.46.88.27 with SMTP id m27mr12754904ljb.132.1519825096384; Wed, 28 Feb 2018 05:38:16 -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.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2018 05:38:15 -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 3/6] input: pagasus_notetaker: fix deadlock in autosuspend Date: Wed, 28 Feb 2018 14:38:00 +0100 Message-Id: <20180228133803.30040-4-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 pegasus_open() does an autoresume if the device is suspended. input_dev->mutex used in pegasus_resume() is in this case already taken by the input subsystem and will cause a deadlock. Signed-off-by: Marcus Folkesson --- drivers/input/tablet/pegasus_notetaker.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/input/tablet/pegasus_notetaker.c b/drivers/input/tablet/pegasus_notetaker.c index 47de5a81172f..9ab1ed5e20e7 100644 --- a/drivers/input/tablet/pegasus_notetaker.c +++ b/drivers/input/tablet/pegasus_notetaker.c @@ -41,6 +41,7 @@ #include #include #include +#include /* USB HID defines */ #define USB_REQ_GET_REPORT 0x01 @@ -76,6 +77,10 @@ struct pegasus { struct usb_device *usbdev; struct usb_interface *intf; struct urb *irq; + + /* serialize access to open/suspend */ + struct mutex pm_mutex; + char name[128]; char phys[64]; struct work_struct init; @@ -216,6 +221,7 @@ static int pegasus_open(struct input_dev *dev) if (error) return error; + mutex_lock(&pegasus->pm_mutex); pegasus->irq->dev = pegasus->usbdev; if (usb_submit_urb(pegasus->irq, GFP_KERNEL)) { error = -EIO; @@ -226,12 +232,14 @@ static int pegasus_open(struct input_dev *dev) if (error) goto err_kill_urb; + mutex_unlock(&pegasus->pm_mutex); return 0; err_kill_urb: usb_kill_urb(pegasus->irq); cancel_work_sync(&pegasus->init); err_autopm_put: + mutex_unlock(&pegasus->pm_mutex); usb_autopm_put_interface(pegasus->intf); return error; } @@ -240,8 +248,11 @@ static void pegasus_close(struct input_dev *dev) { struct pegasus *pegasus = input_get_drvdata(dev); + mutex_lock(&pegasus->pm_mutex); usb_kill_urb(pegasus->irq); cancel_work_sync(&pegasus->init); + mutex_unlock(&pegasus->pm_mutex); + usb_autopm_put_interface(pegasus->intf); } @@ -274,6 +285,8 @@ static int pegasus_probe(struct usb_interface *intf, goto err_free_mem; } + mutex_init(&pegasus->pm_mutex); + pegasus->usbdev = dev; pegasus->dev = input_dev; pegasus->intf = intf; @@ -388,10 +401,10 @@ static int pegasus_suspend(struct usb_interface *intf, pm_message_t message) { struct pegasus *pegasus = usb_get_intfdata(intf); - mutex_lock(&pegasus->dev->mutex); + mutex_lock(&pegasus->pm_mutex); usb_kill_urb(pegasus->irq); cancel_work_sync(&pegasus->init); - mutex_unlock(&pegasus->dev->mutex); + mutex_unlock(&pegasus->pm_mutex); return 0; } @@ -401,10 +414,10 @@ static int pegasus_resume(struct usb_interface *intf) struct pegasus *pegasus = usb_get_intfdata(intf); int retval = 0; - mutex_lock(&pegasus->dev->mutex); + mutex_lock(&pegasus->pm_mutex); if (pegasus->dev->users && usb_submit_urb(pegasus->irq, GFP_NOIO) < 0) retval = -EIO; - mutex_unlock(&pegasus->dev->mutex); + mutex_unlock(&pegasus->pm_mutex); return retval; } @@ -414,14 +427,14 @@ static int pegasus_reset_resume(struct usb_interface *intf) struct pegasus *pegasus = usb_get_intfdata(intf); int retval = 0; - mutex_lock(&pegasus->dev->mutex); + mutex_lock(&pegasus->pm_mutex); if (pegasus->dev->users) { retval = pegasus_set_mode(pegasus, PEN_MODE_XY, NOTETAKER_LED_MOUSE); if (!retval && usb_submit_urb(pegasus->irq, GFP_NOIO) < 0) retval = -EIO; } - mutex_unlock(&pegasus->dev->mutex); + mutex_unlock(&pegasus->pm_mutex); return retval; }