Commit 6f7d485e authored by Axel Lin's avatar Axel Lin Committed by Linus Torvalds

drivers/misc/hmc6352.c: fix wrong return value checking for i2c_master_recv()

i2c_master_recv() returns negative errno, or else the number of bytes
read.  Thus i2c_master_recv(client, i2c_data, 2) returns 2 instead of 1 in
success case.

[akpm@linux-foundation.org: make `ret' signed]
Signed-off-by: default avatarAxel Lin <axel.lin@gmail.com>
Cc: Kalhan Trisal <kalhan.trisal@intel.com>
Cc: Alan Cox <alan@linux.intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4e673599
...@@ -75,7 +75,7 @@ static ssize_t compass_heading_data_show(struct device *dev, ...@@ -75,7 +75,7 @@ static ssize_t compass_heading_data_show(struct device *dev,
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
unsigned char i2c_data[2]; unsigned char i2c_data[2];
unsigned int ret; int ret;
mutex_lock(&compass_mutex); mutex_lock(&compass_mutex);
ret = compass_command(client, 'A'); ret = compass_command(client, 'A');
...@@ -86,7 +86,7 @@ static ssize_t compass_heading_data_show(struct device *dev, ...@@ -86,7 +86,7 @@ static ssize_t compass_heading_data_show(struct device *dev,
msleep(10); /* sending 'A' cmd we need to wait for 7-10 millisecs */ msleep(10); /* sending 'A' cmd we need to wait for 7-10 millisecs */
ret = i2c_master_recv(client, i2c_data, 2); ret = i2c_master_recv(client, i2c_data, 2);
mutex_unlock(&compass_mutex); mutex_unlock(&compass_mutex);
if (ret != 1) { if (ret < 0) {
dev_warn(dev, "i2c read data cmd failed\n"); dev_warn(dev, "i2c read data cmd failed\n");
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment