From patchwork Wed Sep 28 14:34:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 9353965 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 7668360757 for ; Wed, 28 Sep 2016 14:34:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6731529620 for ; Wed, 28 Sep 2016 14:34:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C35B29625; Wed, 28 Sep 2016 14:34:14 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 067D829620 for ; Wed, 28 Sep 2016 14:34:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932684AbcI1OeN (ORCPT ); Wed, 28 Sep 2016 10:34:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35910 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932670AbcI1OeL (ORCPT ); Wed, 28 Sep 2016 10:34:11 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 532D17EAA9; Wed, 28 Sep 2016 14:34:10 +0000 (UTC) Received: from plouf.banquise.eu.com (ovpn-116-65.ams2.redhat.com [10.36.116.65]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8SEY6bS015067; Wed, 28 Sep 2016 10:34:09 -0400 From: Benjamin Tissoires To: Dmitry Torokhov , KT Liao , Adrian Alves Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] Input: elan_i2c - fix return tests of i2c_smbus_read_block_data() Date: Wed, 28 Sep 2016 16:34:01 +0200 Message-Id: <1475073244-23068-2-git-send-email-benjamin.tissoires@redhat.com> In-Reply-To: <1475073244-23068-1-git-send-email-benjamin.tissoires@redhat.com> References: <1475073244-23068-1-git-send-email-benjamin.tissoires@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 28 Sep 2016 14:34:10 +0000 (UTC) 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 i2c_smbus_read_block_data() returns negative errno else the number of data bytes in the slave's response. Checking for error not null means the function always fails if the device answers properly. So given that we read 3 bytes and access those, better check that we actually read those 3 bytes. Signed-off-by: Benjamin Tissoires --- drivers/input/mouse/elan_i2c_smbus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/input/mouse/elan_i2c_smbus.c b/drivers/input/mouse/elan_i2c_smbus.c index cb6aecb..9b43b55 100644 --- a/drivers/input/mouse/elan_i2c_smbus.c +++ b/drivers/input/mouse/elan_i2c_smbus.c @@ -226,7 +226,7 @@ static int elan_smbus_get_max(struct i2c_client *client, u8 val[3]; error = i2c_smbus_read_block_data(client, ETP_SMBUS_RANGE_CMD, val); - if (error) { + if (error != 3) { dev_err(&client->dev, "failed to get dimensions: %d\n", error); return error; } @@ -245,7 +245,7 @@ static int elan_smbus_get_resolution(struct i2c_client *client, error = i2c_smbus_read_block_data(client, ETP_SMBUS_RESOLUTION_CMD, val); - if (error) { + if (error != 3) { dev_err(&client->dev, "failed to get resolution: %d\n", error); return error; } @@ -265,7 +265,7 @@ static int elan_smbus_get_num_traces(struct i2c_client *client, error = i2c_smbus_read_block_data(client, ETP_SMBUS_XY_TRACENUM_CMD, val); - if (error) { + if (error != 3) { dev_err(&client->dev, "failed to get trace info: %d\n", error); return error; }