Skip to content

Commit 265d426

Browse files
bentissdtor
authored andcommitted
Input: elan_i2c - fix return tests of i2c_smbus_read_block_data()
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> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 979987d commit 265d426

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

drivers/input/mouse/elan_i2c_smbus.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,13 @@ static int elan_smbus_get_checksum(struct i2c_client *client,
222222
static int elan_smbus_get_max(struct i2c_client *client,
223223
unsigned int *max_x, unsigned int *max_y)
224224
{
225+
int ret;
225226
int error;
226227
u8 val[3];
227228

228-
error = i2c_smbus_read_block_data(client, ETP_SMBUS_RANGE_CMD, val);
229-
if (error) {
229+
ret = i2c_smbus_read_block_data(client, ETP_SMBUS_RANGE_CMD, val);
230+
if (ret != 3) {
231+
error = ret < 0 ? ret : -EIO;
230232
dev_err(&client->dev, "failed to get dimensions: %d\n", error);
231233
return error;
232234
}
@@ -240,12 +242,13 @@ static int elan_smbus_get_max(struct i2c_client *client,
240242
static int elan_smbus_get_resolution(struct i2c_client *client,
241243
u8 *hw_res_x, u8 *hw_res_y)
242244
{
245+
int ret;
243246
int error;
244247
u8 val[3];
245248

246-
error = i2c_smbus_read_block_data(client,
247-
ETP_SMBUS_RESOLUTION_CMD, val);
248-
if (error) {
249+
ret = i2c_smbus_read_block_data(client, ETP_SMBUS_RESOLUTION_CMD, val);
250+
if (ret != 3) {
251+
error = ret < 0 ? ret : -EIO;
249252
dev_err(&client->dev, "failed to get resolution: %d\n", error);
250253
return error;
251254
}
@@ -260,12 +263,13 @@ static int elan_smbus_get_num_traces(struct i2c_client *client,
260263
unsigned int *x_traces,
261264
unsigned int *y_traces)
262265
{
266+
int ret;
263267
int error;
264268
u8 val[3];
265269

266-
error = i2c_smbus_read_block_data(client,
267-
ETP_SMBUS_XY_TRACENUM_CMD, val);
268-
if (error) {
270+
ret = i2c_smbus_read_block_data(client, ETP_SMBUS_XY_TRACENUM_CMD, val);
271+
if (ret != 3) {
272+
error = ret < 0 ? ret : -EIO;
269273
dev_err(&client->dev, "failed to get trace info: %d\n", error);
270274
return error;
271275
}

0 commit comments

Comments
 (0)