mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Axel Lin <axel.lin@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	Kalhan Trisal <kalhan.trisal@intel.com>,
	Alan Cox <alan@linux.intel.com>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>
Subject: Re: [PATCH] misc: hmc6352: fix wrong return value checking for i2c_master_recv
Date: Wed, 9 Mar 2011 15:58:41 -0800	[thread overview]
Message-ID: <20110309155841.52847f15.akpm@linux-foundation.org> (raw)
In-Reply-To: <1299660116.8255.1.camel@mola>

On Wed, 09 Mar 2011 16:41:56 +0800
Axel Lin <axel.lin@gmail.com> wrote:

> 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.
> 
> Signed-off-by: Axel Lin <axel.lin@gmail.com>
> ---
>  drivers/misc/hmc6352.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/misc/hmc6352.c b/drivers/misc/hmc6352.c
> index 234bfca..3afc11e 100644
> --- a/drivers/misc/hmc6352.c
> +++ b/drivers/misc/hmc6352.c
> @@ -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:

--- a/drivers/misc/hmc6352.c~drivers-misc-hmc6352c-fix-wrong-return-value-checking-for-i2c_master_recv-fix
+++ a/drivers/misc/hmc6352.c
@@ -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?


      reply	other threads:[~2011-03-09 23:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-09  8:41 Axel Lin
2011-03-09 23:58 ` Andrew Morton [this message]

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=20110309155841.52847f15.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=alan@linux.intel.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=axel.lin@gmail.com \
    --cc=kalhan.trisal@intel.com \
    --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

Powered by JetHome