From patchwork Sat Jan 20 21:47:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcus Folkesson X-Patchwork-Id: 10176757 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 B1E736056F for ; Sat, 20 Jan 2018 21:47:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91D6320453 for ; Sat, 20 Jan 2018 21:47:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 859272074F; Sat, 20 Jan 2018 21:47: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 1DA0420453 for ; Sat, 20 Jan 2018 21:47:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756698AbeATVro (ORCPT ); Sat, 20 Jan 2018 16:47:44 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:34931 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756652AbeATVro (ORCPT ); Sat, 20 Jan 2018 16:47:44 -0500 Received: by mail-lf0-f67.google.com with SMTP id a204so6183372lfa.2; Sat, 20 Jan 2018 13:47:42 -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=BWjJWgJcAuwAVT0hB/vbbqVTeKlhDoZgm4onUHcI2ws=; b=SLMJGKmak56tIK40WvrRNl/t8IKXUodRvzNpXIwKLZiDTBiEKarQiPCa7vBgNEYmrg ewjqiu7c8kYrIPCWrlOAz50GXmsX4qUZlxmWi6FGc/Pc1fvpiSRkQp1t5Yg1uhzLvTcu lmuWWg633a7VcNkEEm7PBt5Si15vVPFx6Usz7a6vlNdQsfFm4sUpZ860lshGRxok+nMs ujrC/WcjQVeucAOMFLN7mneMu9FsStq8PEVIdolicvx7Bcjtu2CKbYFs/LUMuNj1i0AM bgAv+gf9YaIPhhlmJut5arqs/VaEKUVbJ/eMKdyi4tzdPm/rLb4huXvLL9Da9O1uDmSa WlMA== 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=BWjJWgJcAuwAVT0hB/vbbqVTeKlhDoZgm4onUHcI2ws=; b=PtJzhEezeI94VNOfh6vWGOLBemn3W4Si4rC6Yvx3woji+OTLW8fddioKuw9Fjg0L21 XHwQnAIjt7eXFHxxeZagZzPcyncq7lRFDIE4qnPmK1wmQ0tv5P8JUbtf8GdBxgSHcGcC Z5azuUWWY5j+hTOsUXatGdlhcrBsSJxetz17YlwErCF0YeufBBpCPa/S9tUrq7/2u06Y k2wMUEC9LLdJy+lKvfNS4qlk3wCpgi4p8GzRRMyS1dl2g7pnD6GE8Mk3wdJn+VIvIl81 raD2aczXlFlABjDjv2BGslAQy9aQo5shLO//AjDmzcE2Yv1psTQakVGkRjQdeBqv/iPO gihg== X-Gm-Message-State: AKwxytdyZJHcNg1Mrzj58pb0VUs+vpuw5HRDVoR/rF7fq2YJ73O/5Odc Zo9OS5zRigz6twaOUOg5pRw= X-Google-Smtp-Source: AH8x225MbnlDr89XUsCD44BoKkXmOwpSlIZNFmyjJWSZ8ZvUuuOmxjAsU1LMi8Ab2kKhoEylic/USg== X-Received: by 10.25.145.94 with SMTP id y30mr1102314lfj.1.1516484862126; Sat, 20 Jan 2018 13:47:42 -0800 (PST) Received: from localhost.localdomain (c-2ec2e669-74736162.cust.telenor.se. [46.194.230.105]) by smtp.gmail.com with ESMTPSA id m25sm2127185lfc.38.2018.01.20.13.47.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 Jan 2018 13:47:40 -0800 (PST) From: Marcus Folkesson To: Dmitry Torokhov , Marcus Folkesson , Arvind Yadav Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] input: synaptics_usb: fix deadlock in autosuspend Date: Sat, 20 Jan 2018 22:47:26 +0100 Message-Id: <20180120214727.9067-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 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; }