From patchwork Wed Jan 24 15:46:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcus Folkesson X-Patchwork-Id: 10182761 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 42075602B7 for ; Wed, 24 Jan 2018 15:46:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3037B28475 for ; Wed, 24 Jan 2018 15:46:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24DDE28900; Wed, 24 Jan 2018 15:46:53 +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=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 AC6F028475 for ; Wed, 24 Jan 2018 15:46:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934143AbeAXPqv (ORCPT ); Wed, 24 Jan 2018 10:46:51 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:37386 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934092AbeAXPqu (ORCPT ); Wed, 24 Jan 2018 10:46:50 -0500 Received: by mail-lf0-f67.google.com with SMTP id f3so5828633lfe.4; Wed, 24 Jan 2018 07:46:49 -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=LPdxrJqlx1pE+eYy0gu8omddxUe/Qy8FoTMMyowsSoI=; b=WgBvWpdyKKEaMh0gnn2NJUWxh4to5C6PQfIs1KxoNCE/1d2AHxiLJBy0alvxQNHJv4 R/chfLZ97zh6nILRFiaMwhiYtvkojotamIt/XvkkrR8KRyMapzT2dVMRg3m0hjLnaGBk BnGqCOHdVQCRlc3qu50WxQwotVODcmqNpzLh6yS02/nPbiUGvV4C9JDdrwfQr/v/0pnr bfvbnmosvqJUawFWDlxwORAxw80o7aaNBwUAaGhFwHuX8oJ+PKdQALEgQhkjgRzunNkQ xW9AE/1nisWiA166OezR9SHi+8onp/rP5RTcNmwZbGhv4gUbunZ4P52PA3cmHiF6ZYEB EozQ== 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=LPdxrJqlx1pE+eYy0gu8omddxUe/Qy8FoTMMyowsSoI=; b=hrtdm8bSO+jXhEC788UtGPKyVK1of39VS8svcMPA1oouskCNHQI5f6PpWSH3mi082+ JAe8o9+mV0+NszHm6U43MRrn1yuSCFaLAtZpRKamSSKYUOJADJVJUKylnju/OF3x4WNI XDqUgyRBF964nPug9Pq/GYDCjexRALM6pG7/XhQsd2or+Q3T9FS5DndwSCSe/YBRB5CM o7B++Wp8W8QDYS1iFGGnWF4H3CvvOzpsZ/+wqUKk675rA7JhvlgGtNZhQMpTBIZtUhw9 +feDqfMgpd/CutCn+sVGG7wD+TT1oggh3wdjtccJTAndH3+sFmtFuTLCEJjy7JsAWNjv 6JOg== X-Gm-Message-State: AKwxytcH9kjaws4In7DNxhYxnwmCAM6LaqEdbCvp3C7RXVCPjUcD/eQR cxSVxCTitPtXN/lejyJYM68= X-Google-Smtp-Source: AH8x225EqophOxOI3I54MS9XPBxLUVBLoGiNdHIiBgz2+eD/GllrgJDCBkw+KzjNyxhMVL3lwrVc4A== X-Received: by 10.25.221.29 with SMTP id u29mr3806828lfg.140.1516808808854; Wed, 24 Jan 2018 07:46:48 -0800 (PST) Received: from localhost.localdomain ([81.236.84.183]) by smtp.gmail.com with ESMTPSA id w26sm109782lje.75.2018.01.24.07.46.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jan 2018 07:46:47 -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: pagasus_notetaker: fix deadlock in autosuspend Date: Wed, 24 Jan 2018 16:46:41 +0100 Message-Id: <20180124154642.28824-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 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; }