From patchwork Wed Feb 28 13:37:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcus Folkesson X-Patchwork-Id: 10247535 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 AED0A60211 for ; Wed, 28 Feb 2018 13:38:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F4C02869F for ; Wed, 28 Feb 2018 13:38:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93E8928778; Wed, 28 Feb 2018 13:38:19 +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 1FCFB2869F for ; Wed, 28 Feb 2018 13:38:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752655AbeB1NiR (ORCPT ); Wed, 28 Feb 2018 08:38:17 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:38912 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752556AbeB1NiP (ORCPT ); Wed, 28 Feb 2018 08:38:15 -0500 Received: by mail-lf0-f65.google.com with SMTP id f75so3541198lfg.6; Wed, 28 Feb 2018 05:38:13 -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=RIHl8zy6vRNRycfSQbH5wil8o9c57zFIm3aGCkv95SY=; b=AkUOSmYXOQl+e1izuWw2Y8ofcRb+BuQZePqXeWm++h/SkMg7rhgQ5idqmifUIE70rB V7+zBer/qMIWRjW3cFFp2+6PjDnaXd2UsLGCRkHyJOYZv4Ip+Q3HTCgIy75jCSiVEQHi Jqu64CFRbvCB4SjcBfrzE0YUFJw/ObVlFmx9PrOvNY1yxGAjvuE+rPtYngK2NUpRxHe4 PiJpUYF+fNb0iqjqSGfMkKu16gwkDr7kPLymYsB1LYPxaEcSor9DlKPTof3FRXm88e80 5Y/9NQJLRg3smKoT0wErxW+TT2JEuzLx1uIa2ZhYCROmIeKzWc3hRV6N/k8MFZkUIrmG 7D4w== 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=RIHl8zy6vRNRycfSQbH5wil8o9c57zFIm3aGCkv95SY=; b=eBVRAZgL924eYqp4kE+sTeX5qMLWw1W5UJaGepCPdNvA1gXsMLN4vhLGBliDXdhYPL W56fhcJa0ymioQOv0N3mYSLZHm5+J/Nymk68M7aVdqwxVOsMvxJE1foXCh0ub5QVvGpl By2ooWM0PqiL+o33yogv33h5Pf8/DPlXrwYx3rgORJ+PWVHPK3dTcLe1TWzUJ2IzHS/a OsoyZsaDiAtFwzzrUHbPlJFQnTNamA3ON0n5ZWRCGb7EXgwPNT0/yUHt9p1ajYaI1jar j7PxQ0hNzNRWziS4zeD39bq21MSfvGnseU8ZfKWqsVaROV8wad1FOh8FSvi0+Qdb+Jde NZ5g== X-Gm-Message-State: APf1xPA++qtI725yHKoIgB/yj/Ph8Qxe8/6RWiePhChHd8yU7Cuza6Vi JuHzvdImp3kpl6rKtC49cqsHHA== X-Google-Smtp-Source: AG47ELtcFJOUAIb3FZni9OG9Tk5vnAxqSbBs9z+2MYlIRNQj6FRANoWnOWT3QBqCmySw2gY1OjSLKw== X-Received: by 10.46.50.3 with SMTP id y3mr12460138ljy.90.1519825093188; Wed, 28 Feb 2018 05:38:13 -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.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2018 05:38:12 -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 1/6] input: synaptics_usb: fix deadlock in autosuspend Date: Wed, 28 Feb 2018 14:37:58 +0100 Message-Id: <20180228133803.30040-2-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 synusb_open() does an autoresume if the device is suspended. input_dev->mutex used in synusb_resume() is in this case already taken by the input subsystem and will cause a deadlock. Signed-off-by: Marcus Folkesson --- drivers/input/mouse/synaptics_usb.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/input/mouse/synaptics_usb.c b/drivers/input/mouse/synaptics_usb.c index cb7d15d826d0..2c66913cf5a2 100644 --- a/drivers/input/mouse/synaptics_usb.c +++ b/drivers/input/mouse/synaptics_usb.c @@ -82,6 +82,9 @@ struct synusb { struct urb *urb; unsigned char *data; + /* serialize access to open/suspend */ + struct mutex pm_mutex; + /* input device related data structures */ struct input_dev *input; char name[128]; @@ -252,6 +255,7 @@ static int synusb_open(struct input_dev *dev) return retval; } + mutex_lock(&synusb->pm_mutex); retval = usb_submit_urb(synusb->urb, GFP_KERNEL); if (retval) { dev_err(&synusb->intf->dev, @@ -264,6 +268,7 @@ static int synusb_open(struct input_dev *dev) synusb->intf->needs_remote_wakeup = 1; out: + mutex_unlock(&synusb->pm_mutex); usb_autopm_put_interface(synusb->intf); return retval; } @@ -275,8 +280,10 @@ static void synusb_close(struct input_dev *dev) autopm_error = usb_autopm_get_interface(synusb->intf); + mutex_lock(&synusb->pm_mutex); usb_kill_urb(synusb->urb); synusb->intf->needs_remote_wakeup = 0; + mutex_unlock(&synusb->pm_mutex); if (!autopm_error) usb_autopm_put_interface(synusb->intf); @@ -315,6 +322,7 @@ static int synusb_probe(struct usb_interface *intf, synusb->udev = udev; synusb->intf = intf; synusb->input = input_dev; + mutex_init(&synusb->pm_mutex); synusb->flags = id->driver_info; if (synusb->flags & SYNUSB_COMBO) { @@ -466,11 +474,10 @@ static void synusb_disconnect(struct usb_interface *intf) static int synusb_suspend(struct usb_interface *intf, pm_message_t message) { struct synusb *synusb = usb_get_intfdata(intf); - struct input_dev *input_dev = synusb->input; - mutex_lock(&input_dev->mutex); + mutex_lock(&synusb->pm_mutex); usb_kill_urb(synusb->urb); - mutex_unlock(&input_dev->mutex); + mutex_unlock(&synusb->pm_mutex); return 0; } @@ -481,14 +488,14 @@ static int synusb_resume(struct usb_interface *intf) struct input_dev *input_dev = synusb->input; int retval = 0; - mutex_lock(&input_dev->mutex); + mutex_lock(&synusb->pm_mutex); if ((input_dev->users || (synusb->flags & SYNUSB_IO_ALWAYS)) && usb_submit_urb(synusb->urb, GFP_NOIO) < 0) { retval = -EIO; } - mutex_unlock(&input_dev->mutex); + mutex_unlock(&synusb->pm_mutex); return retval; } @@ -496,9 +503,8 @@ static int synusb_resume(struct usb_interface *intf) static int synusb_pre_reset(struct usb_interface *intf) { struct synusb *synusb = usb_get_intfdata(intf); - struct input_dev *input_dev = synusb->input; - mutex_lock(&input_dev->mutex); + mutex_lock(&synusb->pm_mutex); usb_kill_urb(synusb->urb); return 0; @@ -515,7 +521,7 @@ static int synusb_post_reset(struct usb_interface *intf) retval = -EIO; } - mutex_unlock(&input_dev->mutex); + mutex_unlock(&synusb->pm_mutex); return retval; }