From patchwork Thu Jun 23 17:18:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9195631 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 E84E86075F for ; Thu, 23 Jun 2016 17:18:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D15BB283FB for ; Thu, 23 Jun 2016 17:18:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C604A28463; Thu, 23 Jun 2016 17:18:57 +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=unavailable 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 34FBB283FB for ; Thu, 23 Jun 2016 17:18:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751431AbcFWRSk (ORCPT ); Thu, 23 Jun 2016 13:18:40 -0400 Received: from mail-pa0-f67.google.com ([209.85.220.67]:33307 "EHLO mail-pa0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750809AbcFWRSi (ORCPT ); Thu, 23 Jun 2016 13:18:38 -0400 Received: by mail-pa0-f67.google.com with SMTP id ts6so7006486pac.0; Thu, 23 Jun 2016 10:18:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=kRTHtsAPA8LJ9thAr0cVlGNlXrIWQhwVO8EZheDX+X0=; b=riJNrVmxCfKEEM6N7FU0d3jYYmtrsr4FfUf2XjO6Sax3PBQeu1k7vqCH1bwsBnjWjg IeYBEoAxXagxP4U2shmFIm+L6KcNyDkV71QAE1vK2XwB2OvDbBSBA9nMYKDt3YOHrj8E kvU/THydZLAM3MUcZFIRzvFvWFugrTGCJDNYO8Y+AmBuwCj0dbaINJSTk4cWajHvWztB fNS48xGB110jqoyFQYREOXy7G80FsofTnD+k9LPtnCzme1PLeOHJzMh8S7ckip7GktYL eH2Es+r+gxitSsxpeIZx0sdq0L6awLIvs7ze54+6WnZcDG/DLtnT11NK9PCotviAwFYY Qnlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=kRTHtsAPA8LJ9thAr0cVlGNlXrIWQhwVO8EZheDX+X0=; b=B92lc2O/D+f8bMUUmE+JB5mz32tAVGr/Y9dicqKzjjhW6CtyCdKhQU26fNbdgxfNTA UARKJrp0r2B+1irXr/mfOyTv3g5FshD0IS7MS5Ayj8a6l+fzcoM8zyWyKLpdq7n7SCkj NdL7w1mQlojCsHjLaRr7ceqvgMNyfhI+EhMXvBRWuXJ64c3tXEOLJBMaAU5IoOeF95fO M00ZZz92Bb1Tv0Rh+EVRd+XDV/gVKgCEms7X7Qgu5IAebtF5MVgjcD4zP3wRweE1kQlV LvlKe03gUVa1Y4TU4Hf64innO9isBV1XwHTvaysl/MZcxLtgXjNQIXU2URDhQC5/OJRz FrUg== X-Gm-Message-State: ALyK8tLFFPK2nJjL3r9Yyv+bKQ35V1E/m12wVZ8ODCBu4Ugb/BiPNgF6G5NNXTHPCIPfGg== X-Received: by 10.66.138.110 with SMTP id qp14mr45263010pab.135.1466702317993; Thu, 23 Jun 2016 10:18:37 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1311:c447:2c2:fbe9:ede6]) by smtp.gmail.com with ESMTPSA id d69sm1478338pfj.31.2016.06.23.10.18.37 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 23 Jun 2016 10:18:37 -0700 (PDT) Date: Thu, 23 Jun 2016 10:18:35 -0700 From: Dmitry Torokhov To: Martin Kepplinger Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, kernel-testers@vger.kernel.org, linux-usb@vger.kernel.org Subject: Re: [PATCH v2] input: tablet: pegasus_notetaker: USB PM fixes Message-ID: <20160623171835.GE32561@dtor-ws> References: <1465903215-2351-1-git-send-email-martink@posteo.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1465903215-2351-1-git-send-email-martink@posteo.de> 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 Hi Martin, On Tue, Jun 14, 2016 at 01:20:15PM +0200, Martin Kepplinger wrote: > static int pegasus_reset_resume(struct usb_interface *intf) > { > + struct pegasus *pegasus = usb_get_intfdata(intf); > + > + if (pegasus->dev->users) > + pegasus_set_mode(pegasus, PEN_MODE_XY, NOTETAKER_LED_MOUSE); > + > return pegasus_resume(intf); Hmm, we need to take input mutex when using pegasus->dev->users, how about the version below instead? Thanks. diff --git a/drivers/input/tablet/pegasus_notetaker.c b/drivers/input/tablet/pegasus_notetaker.c index 805afe3..d20ea06 100644 --- a/drivers/input/tablet/pegasus_notetaker.c +++ b/drivers/input/tablet/pegasus_notetaker.c @@ -80,7 +80,7 @@ struct pegasus { struct work_struct init; }; -static void pegasus_control_msg(struct pegasus *pegasus, u8 *data, int len) +static int pegasus_control_msg(struct pegasus *pegasus, u8 *data, int len) { const int sizeof_buf = len + 2; int result; @@ -88,7 +88,7 @@ static void pegasus_control_msg(struct pegasus *pegasus, u8 *data, int len) cmd_buf = kmalloc(sizeof_buf, GFP_KERNEL); if (!cmd_buf) - return; + return -ENOMEM; cmd_buf[0] = NOTETAKER_REPORT_ID; cmd_buf[1] = len; @@ -101,17 +101,23 @@ static void pegasus_control_msg(struct pegasus *pegasus, u8 *data, int len) 0, 0, cmd_buf, sizeof_buf, USB_CTRL_SET_TIMEOUT); - if (result != sizeof_buf) - dev_err(&pegasus->usbdev->dev, "control msg error\n"); + if (result != sizeof_buf) { + if (result >= 0) + result = -EIO; + dev_err(&pegasus->usbdev->dev, "control msg error: %d\n", + result); + } kfree(cmd_buf); + + return result; } -static void pegasus_set_mode(struct pegasus *pegasus, u8 mode, u8 led) +static int pegasus_set_mode(struct pegasus *pegasus, u8 mode, u8 led) { u8 cmd[] = { NOTETAKER_SET_CMD, NOTETAKER_SET_MODE, led, mode }; - pegasus_control_msg(pegasus, cmd, sizeof(cmd)); + return pegasus_control_msg(pegasus, cmd, sizeof(cmd)); } static void pegasus_parse_packet(struct pegasus *pegasus) @@ -205,27 +211,24 @@ static int pegasus_open(struct input_dev *dev) return retval; pegasus->irq->dev = pegasus->usbdev; - if (usb_submit_urb(pegasus->irq, GFP_KERNEL)) + if (usb_submit_urb(pegasus->irq, GFP_KERNEL)) { retval = -EIO; + goto out; + } - pegasus_set_mode(pegasus, PEN_MODE_XY, NOTETAKER_LED_MOUSE); + retval = pegasus_set_mode(pegasus, PEN_MODE_XY, NOTETAKER_LED_MOUSE); +out: usb_autopm_put_interface(pegasus->intf); - return retval; } static void pegasus_close(struct input_dev *dev) { struct pegasus *pegasus = input_get_drvdata(dev); - int autopm_error; - autopm_error = usb_autopm_get_interface(pegasus->intf); usb_kill_urb(pegasus->irq); cancel_work_sync(&pegasus->init); - - if (!autopm_error) - usb_autopm_put_interface(pegasus->intf); } static int pegasus_probe(struct usb_interface *intf, @@ -373,6 +376,7 @@ static int pegasus_suspend(struct usb_interface *intf, pm_message_t message) mutex_lock(&pegasus->dev->mutex); usb_kill_urb(pegasus->irq); + cancel_work_sync(&pegasus->init); mutex_unlock(&pegasus->dev->mutex); return 0; @@ -393,7 +397,19 @@ static int pegasus_resume(struct usb_interface *intf) static int pegasus_reset_resume(struct usb_interface *intf) { - return pegasus_resume(intf); + struct pegasus *pegasus = usb_get_intfdata(intf); + int retval = 0; + + mutex_lock(&pegasus->dev->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); + + return retval; } static const struct usb_device_id pegasus_ids[] = {