From patchwork Fri Sep 8 17:43:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9944751 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 36C59604D4 for ; Fri, 8 Sep 2017 17:43:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D56E28754 for ; Fri, 8 Sep 2017 17:43:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11C1B2875A; Fri, 8 Sep 2017 17:43:44 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 7C71B28754 for ; Fri, 8 Sep 2017 17:43:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756596AbdIHRnm (ORCPT ); Fri, 8 Sep 2017 13:43:42 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:37591 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756210AbdIHRnl (ORCPT ); Fri, 8 Sep 2017 13:43:41 -0400 Received: by mail-pf0-f194.google.com with SMTP id a2so1726092pfj.4; Fri, 08 Sep 2017 10:43:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=TanncVnwF1ro4lzwhsFyNFJW+KrwF3dJZwm1URv4Psw=; b=rqwm+S4PICKfEnVzztg4h1zs+ym0Vk+tObxompsgI293/zb/pKFuXam0Bd20sbUiCU TyMeeNKo52PObe19ooVEGmQ7vy1ppYXgN87WsxeLiqdAZ9u/oVuTYGB3MTg0PbvY1UI+ O2poNRnY8DLECcS0plIdn2kicEBUJ9luUp2HCp86fjuP5wtOXLe+QvXKuEcGcAZMhqMh hZiXpigT/mGTpj2uyukjuxvJzteaWmKM5KRtzdNA1hGoXr3nr9lWuBkzw41MSL+NvbKb tDLJIaoKplZ72oHZ7CXuu9Wh069J0qWtWToEeqVfobOFsZXiz1hZXwLqJWMKwO3CrP3j ebGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=TanncVnwF1ro4lzwhsFyNFJW+KrwF3dJZwm1URv4Psw=; b=uHLli0dgujdJeRf+XkBgw+zowaLwKdSTiB022Jy4FdGtNoef4r+OFPZ6rNS0MCVUk6 oxWPp4hxPy7bxkTkGqXsjfTEuRwf6CwMTVnWCA+Mmyhf1ja+6mqrTJXqB1wEWw25ZK0Q 5t1mAH4iar6EZnSSb4F2zVXKHvBSPrGSzTlI0/kZdwfb4N9qVMHuywaeAgBh0WOuH+H2 T8cJi6q9Y/sUjqix5vAKZtYPD8epq97BSJO4qrBRMnNj4tJ+40ph7jZbgFNMy/9Dllmi ILoVc/UPLIbjoP5YMInb2QzdHShl+VEWGJa/SUi791ZBirqTU4zGw+W/Ctd6YS1lmY5T Qs/g== X-Gm-Message-State: AHPjjUgBEfrpFb5IQQxAb5rYuTfUXEhUdowL/h0IE1uj0ZRLn4USwbFG /8LAGV2ZHvX0bw== X-Google-Smtp-Source: ADKCNb4Dnbi9cYVsQ24RjxCE2uPW91YZwgasd+ttVygvaGoMkWRsqRbSoayMZPyyoWUA+dUrPZMQNQ== X-Received: by 10.84.132.129 with SMTP id e1mr28233ple.211.1504892620296; Fri, 08 Sep 2017 10:43:40 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1611:cbf:abf7:ebe4:53b3]) by smtp.gmail.com with ESMTPSA id a25sm2132507pfc.143.2017.09.08.10.43.39 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 08 Sep 2017 10:43:39 -0700 (PDT) Date: Fri, 8 Sep 2017 10:43:37 -0700 From: Dmitry Torokhov To: Jiri Kosina Cc: Benjamin Tissoires , Guenter Roeck , Benson Leung , linux-usb@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] HID: usbhid: get/put around clearing needs_remote_wakeup Message-ID: <20170908174337.GA13616@dtor-ws> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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 From: Benson Leung usbhid->intf->needs_remote_wakeup is set when a device is opened, and is cleared when a device is closed. In usbhid_open, usb_autopm_get_interface is called before setting the needs_remote_wakeup flag, and usb_autopm_put_interface is called after hid_start_in. However, when the device is closed in usbhid_close, we simply reset the flag and the device stays awake even though it could be suspended. This patch adds calls to usb_autopm_get_interface and usb_autopm_put_interface when we reset usbhid->intf->needs_remote_wakeup flag, giving the system chance to put the device to sleep. Signed-off-by: Benson Leung Signed-off-by: Dmitry Torokhov --- drivers/hid/usbhid/hid-core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index 089bad8a9a21..174d87f0e3e6 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -729,6 +729,7 @@ static int usbhid_open(struct hid_device *hid) static void usbhid_close(struct hid_device *hid) { struct usbhid_device *usbhid = hid->driver_data; + int autopm_error; /* * Make sure we don't restart data acquisition due to @@ -745,8 +746,14 @@ static void usbhid_close(struct hid_device *hid) return; hid_cancel_delayed_stuff(usbhid); + + autopm_error = usb_autopm_get_interface(usbhid->intf); + usb_kill_urb(usbhid->urbin); usbhid->intf->needs_remote_wakeup = 0; + + if (!autopm_error) + usb_autopm_put_interface(usbhid->intf); } /* @@ -1176,13 +1183,18 @@ static int usbhid_start(struct hid_device *hid) static void usbhid_stop(struct hid_device *hid) { struct usbhid_device *usbhid = hid->driver_data; + int autopm_error; if (WARN_ON(!usbhid)) return; if (hid->quirks & HID_QUIRK_ALWAYS_POLL) { clear_bit(HID_IN_POLLING, &usbhid->iofl); + + autopm_error = usb_autopm_get_interface(usbhid->intf); usbhid->intf->needs_remote_wakeup = 0; + if (!autopm_error) + usb_autopm_put_interface(usbhid->intf); } clear_bit(HID_STARTED, &usbhid->iofl);