misc: hmc6352: fix wrong return value checking for i2c_master_recv
PATCH 1/1 misc: hmc6352: 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.
--- drivers/misc/hmc6352.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/misc/hmc6352.c +1 -1
@@ -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 */ ret =i2c_master_recv (client, i2c_data,2 );mutex_unlock (&compass_mutex); -if (ret !=1 ) { +if (ret <0 ) {dev_warn (dev,"i2c read data cmd failed\n" );return ret; }
Signature · 1 line
1.7.2
Quoted 13 lines · On Wed, 09 Mar 2011 16:41:56 +0800 Axel Lin <[email protected]> wrote:
i2c_master_recv()returns negative errno, or else the number of bytes read. Thusi2c_master_recv(client, i2c_data, 2)returns 2 instead of 1 in success case.Signed-off-by Axel Lin <[email protected]>--- drivers/misc/hmc6352.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/misc/hmc6352.c +0
-0
drivers/misc/hmc6352.c static ssize_t compass_heading_data_show(struct device *dev, · line 92
Quoted 8 lines
drivers/misc/hmc6352.c +1
-1@@ -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 */ ret =i2c_master_recv (client, i2c_data,2 );mutex_unlock (&compass_mutex); -if (ret !=1 ) { +if (ret <0 ) {dev_warn (dev,"i2c read data cmd failed\n" );return ret; }
The problem seems real but the fix won't work:
drivers/misc/hmc6352.c renamed from drivers/misc/hmc6352.c~drivers-misc-hmc6352c-fix-wrong-return-value-checking-for-i2c_master_recv-fix +1 -1
@@ -75,7 +75,7 @@ static ssize_t compass_heading_data_show {struct i2c_client *client =to_i2c_client (dev);unsigned char i2c_data[2 ]; -unsigned int ret; +int ret;mutex_lock (&compass_mutex); ret =compass_command (client,'A' );
I also wonder if this bit is correct:
: static ssize_t compass_heading_data_show(struct device *dev,
: struct device_attribute *attr, char *buf)
: {
: struct i2c_client *client = to_i2c_client(dev);
: unsigned char i2c_data[2];
: int ret;
:
: mutex_lock(&compass_mutex);
: ret = compass_command(client, 'A');
: if (ret != 1) {
: mutex_unlock(&compass_mutex);
: return ret;
: }
If compass_command() returns zero (short write on i2c?!?!?) then did we do the right thing?