linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Tissoires <benjamin.tissoires@redhat.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	KT Liao <kt.liao@emc.com.tw>, Adrian Alves <aalves@gmail.com>
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	[thread overview]
Message-ID: <1475073244-23068-2-git-send-email-benjamin.tissoires@redhat.com> (raw)
In-Reply-To: <1475073244-23068-1-git-send-email-benjamin.tissoires@redhat.com>

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 <benjamin.tissoires@redhat.com>
---
 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;
 	}
-- 
2.7.4


  reply	other threads:[~2016-09-28 14:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-28 14:34 [PATCH 0/4] Input: elan - add support for SMBus Host Notify and trackstick Benjamin Tissoires
2016-09-28 14:34 ` Benjamin Tissoires [this message]
2016-10-01  0:02   ` [PATCH 1/4] Input: elan_i2c - fix return tests of i2c_smbus_read_block_data() Dmitry Torokhov
2016-09-28 14:34 ` [PATCH 2/4] Input: elan_i2c - always output the device information Benjamin Tissoires
2016-09-30 23:52   ` Dmitry Torokhov
2016-09-28 14:34 ` [PATCH 3/4] Input: elan_i2c - add Host Notify support Benjamin Tissoires
2016-09-30 23:57   ` Dmitry Torokhov
2016-10-03 14:33     ` Benjamin Tissoires
2016-09-28 14:34 ` [PATCH 4/4] Input: elan_i2c - add trackstick report Benjamin Tissoires

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1475073244-23068-2-git-send-email-benjamin.tissoires@redhat.com \
    --to=benjamin.tissoires@redhat.com \
    --cc=aalves@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=kt.liao@emc.com.tw \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).