From patchwork Thu Nov 13 20:16:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benson Leung X-Patchwork-Id: 5300621 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D318D9F2ED for ; Thu, 13 Nov 2014 20:17:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0428F2017D for ; Thu, 13 Nov 2014 20:17:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0C3932015D for ; Thu, 13 Nov 2014 20:17:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934047AbaKMURH (ORCPT ); Thu, 13 Nov 2014 15:17:07 -0500 Received: from mail-ie0-f181.google.com ([209.85.223.181]:62892 "EHLO mail-ie0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933146AbaKMURF (ORCPT ); Thu, 13 Nov 2014 15:17:05 -0500 Received: by mail-ie0-f181.google.com with SMTP id rp18so16500659iec.12 for ; Thu, 13 Nov 2014 12:17:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=Lk3u1VOhLvAcCzd/T3GBImPu9NSi3qkVQeI404IwTyA=; b=ixzZWNfL9soVRx5n7Pmb8rfGe2CPFfMG84bep5IypqlsHQsMPAAXiIN8n0MX8xeNJh olABVwlnN5csfJqIobTwK9ON7esNJgMcY9+apyV4ns7hlKmCz+eQEivdqDMq4Dikfg+I 3d0q69DHzR4Ov5RbDm+snUfAUk+708FNwdi6g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Lk3u1VOhLvAcCzd/T3GBImPu9NSi3qkVQeI404IwTyA=; b=gqnYvn2hFbrgHDLKbye1l9to/MvS9NoIpQpHobKll8tbxCrkRsGXtjFlWdsNdlXnch TSfow5xGWwQ//NrI+WMOVUz4LWPnoy3NVXG8dQXN5Rb5Vr/RPbHT2c5W1RFI3pLXeeYi AGU8HkAS73xg/sBOiWD/wUgRMTwt74huw7DqQaLnpto95wyUFyT0WMEyvC49Q+hyXL7p h74gwhd48hdHNFnb+NssCPWg+y4YoCtKsW7vuBmF2nrtvqdziouls2eFYUmIs3+1UbOR oS70eWQOobs2JRXx0czvhTTDJsHjYb4b5PUm568v/RifrdMRZb6/+3ltKeVuO1sHbOus FsJQ== X-Gm-Message-State: ALoCoQlD+/+7hKN/VZ3FupdZ9LwGC5cAPGzWuWC5KSrivIQ+RBfXVDYNRsEpH2zwVDdCvgpX3jRb X-Received: by 10.50.47.102 with SMTP id c6mr1221395ign.27.1415909824352; Thu, 13 Nov 2014 12:17:04 -0800 (PST) Received: from laughingman.mtv.corp.google.com ([172.22.65.61]) by mx.google.com with ESMTPSA id dy3sm261237igb.1.2014.11.13.12.17.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Nov 2014 12:17:03 -0800 (PST) From: Benson Leung To: johan@kernel.org, jkosina@suse.cz, linux-usb@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Cc: snanda@chromium.org, Benson Leung Subject: [PATCH] HID: usbhid: get/put around clearing needs_remote_wakeup Date: Thu, 13 Nov 2014 12:16:46 -0800 Message-Id: <1415909806-23848-1-git-send-email-bleung@chromium.org> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP usbhid->intf->needs_remote_wakeup is set when a device is opened, and is cleared when a device is closed. When a usbhid device that does not support remote wake ( i.e. !device_can_wakeup() ) is closed, we fail out of autosuspend_check() because the autosuspend check is called before the flag is cleared as a result of usb_kill_urb(usbhid->urbin); The result is that a device that may otherwise autosuspend will fail to enter suspend again after all handles to it are 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, the same protection isn't there when clearing needs_remote_wakeup. This will add that to usbhid_close as well as usbhid_stop. Signed-off-by: Benson Leung --- drivers/hid/usbhid/hid-core.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index 04e34b9..2a0b91d 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -734,8 +734,15 @@ void usbhid_close(struct hid_device *hid) spin_unlock_irq(&usbhid->lock); hid_cancel_delayed_stuff(usbhid); if (!(hid->quirks & HID_QUIRK_ALWAYS_POLL)) { + int autopm_error; + + 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); } } else { spin_unlock_irq(&usbhid->lock); @@ -1179,9 +1186,17 @@ static void usbhid_stop(struct hid_device *hid) if (WARN_ON(!usbhid)) return; - if (hid->quirks & HID_QUIRK_ALWAYS_POLL) + if (hid->quirks & HID_QUIRK_ALWAYS_POLL) { + int autopm_error; + + 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); spin_lock_irq(&usbhid->lock); /* Sync with error and led handlers */ set_bit(HID_DISCONNECTED, &usbhid->iofl);