From patchwork Tue May 23 21:13:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9743909 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 13708601C2 for ; Tue, 23 May 2017 21:14:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08DDE28836 for ; Tue, 23 May 2017 21:14:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1C442883A; Tue, 23 May 2017 21:14:16 +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=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 A1DED28836 for ; Tue, 23 May 2017 21:14:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1162552AbdEWVOE (ORCPT ); Tue, 23 May 2017 17:14:04 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:34323 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161990AbdEWVN6 (ORCPT ); Tue, 23 May 2017 17:13:58 -0400 Received: by mail-pf0-f193.google.com with SMTP id w69so29987409pfk.1; Tue, 23 May 2017 14:13:57 -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:references:mime-version :content-disposition:in-reply-to:user-agent; bh=hC8Wfm4AFiF/DvpYhCdNC81TzY4gCDCevo8VSzVVv4g=; b=MMsTjKtCt87Tj+OGjX9E0BzZVn83twtekUHNn0eZR1KAT+YTuqhH0LGov0qSiQr+k5 3TOcg65sn2Ix2mBSfMEwUMtFusunFWOm6wFzRv+aIzt/0m3zzlnccQQDj7hxC6FcDs/D IujGGqVfwF1DRGtz5T5PX84KtVbNuKF/MAaZlClNRoEF+xW4MzAf8WOiRM0gTztRO1t4 9cOXWKEIN11GOzIch0UcNB6JNbf1yBAhljo1mM6TWVIvfylrUu4+wQZ8FccEwJsUsmDR LFNZh3TBSozkjMkhqtSIq/XfB5P8c9DwF2qmwtgnBVWVgA+v5kFK70SFVTknYIrBXjdv 48RA== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=hC8Wfm4AFiF/DvpYhCdNC81TzY4gCDCevo8VSzVVv4g=; b=G7ME52CtFugGj/3wMbg7FVCcd3ZTe2dgfoh9rezH09W9V250IlmaND+0KQ8gKA7zNn Z+VVBvLzVFaXn1a+p/VEIXTnKYo2qjTgHFFzzel8os0XwCbNQOlAFpJiaXN17BmaRDCG BXK6WWLgFHUBW0kTkedZA35FCThnJlD9yPCsMf4l2cTVJsXwbhzG+lyRNJRp3vAg3UQB BMXN6BVTFm8de2AaBQ48C8gtxQ8X23YkNSJutEeZHq4qYLBtJPIhMDYs4fJmsRWgKjiN E4lEQhcac5X7mzLuMnjRPmxwM1yab614NWgza4dTKnNIweOjZYnWW/J7G7r8ah99qmCl YvNw== X-Gm-Message-State: AODbwcB75O3hTgVXbR1FQdkNtbVQbiqstevEVKpT0Fsu54O5tCYKCfu+ RA6XcUTnLm5T1w== X-Received: by 10.84.194.37 with SMTP id g34mr39187902pld.182.1495574037006; Tue, 23 May 2017 14:13:57 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1311:8c64:ac88:fa98:560a]) by smtp.gmail.com with ESMTPSA id f27sm4080187pga.41.2017.05.23.14.13.56 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 23 May 2017 14:13:56 -0700 (PDT) Date: Tue, 23 May 2017 14:13:54 -0700 From: Dmitry Torokhov To: KT Liao Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, phoenix@emc.com.tw Subject: Re: [PATCH] Input: elan_i2c - Prevent breaking of FW updating from unexpected signal Message-ID: <20170523211354.GA34299@dtor-ws> References: <1495549922-4589-1-git-send-email-kt.liao@emc.com.tw> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1495549922-4589-1-git-send-email-kt.liao@emc.com.tw> 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 KT, On Tue, May 23, 2017 at 10:32:02PM +0800, KT Liao wrote: > Use wait_for_completion_timeout to prevent breaking of FW updating from unexpected signal > > Signed-off-by: KT Liao > --- > drivers/input/mouse/elan_i2c_i2c.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/input/mouse/elan_i2c_i2c.c b/drivers/input/mouse/elan_i2c_i2c.c > index 3be75c6e..34356c7 100644 > --- a/drivers/input/mouse/elan_i2c_i2c.c > +++ b/drivers/input/mouse/elan_i2c_i2c.c > @@ -619,7 +619,7 @@ static int elan_i2c_finish_fw_update(struct i2c_client *client, > > error = elan_i2c_write_cmd(client, ETP_I2C_STAND_CMD, ETP_I2C_RESET); > if (!error) > - ret = wait_for_completion_interruptible_timeout(completion, > + ret = wait_for_completion_timeout(completion, > msecs_to_jiffies(300)); > disable_irq(client->irq); > > -- > 2.7.4 > wait_for_completion_timeout(), unlike wait_for_completion_interruptible_timeout() returns unsigned long, so the code below checking if 'ret' is negative, is no longer needed. How about the version of the patch below? diff --git a/drivers/input/mouse/elan_i2c_i2c.c b/drivers/input/mouse/elan_i2c_i2c.c index 3be75c6e8090..278832047075 100644 --- a/drivers/input/mouse/elan_i2c_i2c.c +++ b/drivers/input/mouse/elan_i2c_i2c.c @@ -609,7 +609,6 @@ static int elan_i2c_finish_fw_update(struct i2c_client *client, struct completion *completion) { struct device *dev = &client->dev; - long ret; int error; int len; u8 buffer[ETP_I2C_INF_LENGTH]; @@ -618,23 +617,19 @@ static int elan_i2c_finish_fw_update(struct i2c_client *client, enable_irq(client->irq); error = elan_i2c_write_cmd(client, ETP_I2C_STAND_CMD, ETP_I2C_RESET); - if (!error) - ret = wait_for_completion_interruptible_timeout(completion, - msecs_to_jiffies(300)); - disable_irq(client->irq); - if (error) { dev_err(dev, "device reset failed: %d\n", error); - return error; - } else if (ret == 0) { + } else if (!wait_for_completion_timeout(completion, + msecs_to_jiffies(300))) { dev_err(dev, "timeout waiting for device reset\n"); - return -ETIMEDOUT; - } else if (ret < 0) { - error = ret; - dev_err(dev, "error waiting for device reset: %d\n", error); - return error; + error = -ETIMEDOUT; } + disable_irq(client->irq); + + if (error) + return error; + len = i2c_master_recv(client, buffer, ETP_I2C_INF_LENGTH); if (len != ETP_I2C_INF_LENGTH) { error = len < 0 ? len : -EIO;