Linux IIO development
 help / color / mirror / Atom feed
From: Jean-Francois Dagenais <jeff.dagenais@gmail.com>
To: linux-iio@vger.kernel.org
Cc: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de,
	pmeerw@pmeerw.net, Michael.Hennerich@analog.com,
	Jean-Francois Dagenais <jeff.dagenais@gmail.com>
Subject: [PATCH] iio:dac: fix i2c_master_send return code misuse
Date: Tue, 27 Oct 2015 12:25:39 -0400	[thread overview]
Message-ID: <1445963139-2158-2-git-send-email-jeff.dagenais@gmail.com> (raw)
In-Reply-To: <1445963139-2158-1-git-send-email-jeff.dagenais@gmail.com>

Contrary to most kernel functions, successful call to
i2c_master_send returns the number or written bytes,not 0.

However, these callers return the value as is without converting
the return style to conform to the expected standard.

Signed-off-by: Jean-Francois Dagenais <jeff.dagenais@gmail.com>
---
 drivers/iio/dac/ad5064.c  |  5 ++++-
 drivers/iio/dac/ad5446.c  |  4 +++-
 drivers/iio/dac/max517.c  |  6 ++++--
 drivers/iio/dac/max5821.c |  8 ++++++--
 drivers/iio/dac/mcp4725.c | 10 ++++++++--
 5 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/drivers/iio/dac/ad5064.c b/drivers/iio/dac/ad5064.c
index c067e68..0ff1107 100644
--- a/drivers/iio/dac/ad5064.c
+++ b/drivers/iio/dac/ad5064.c
@@ -598,10 +598,13 @@ static int ad5064_i2c_write(struct ad5064_state *st, unsigned int cmd,
 	unsigned int addr, unsigned int val)
 {
 	struct i2c_client *i2c = to_i2c_client(st->dev);
+	int res;
 
 	st->data.i2c[0] = (cmd << 4) | addr;
 	put_unaligned_be16(val, &st->data.i2c[1]);
-	return i2c_master_send(i2c, st->data.i2c, 3);
+	res = i2c_master_send(i2c, st->data.i2c, 3);
+
+	return res == 3 ? 0 : res;
 }
 
 static int ad5064_i2c_probe(struct i2c_client *i2c,
diff --git a/drivers/iio/dac/ad5446.c b/drivers/iio/dac/ad5446.c
index 07e17d7..9a49941 100644
--- a/drivers/iio/dac/ad5446.c
+++ b/drivers/iio/dac/ad5446.c
@@ -512,7 +512,9 @@ static int ad5622_write(struct ad5446_state *st, unsigned val)
 	struct i2c_client *client = to_i2c_client(st->dev);
 	__be16 data = cpu_to_be16(val);
 
-	return i2c_master_send(client, (char *)&data, sizeof(data));
+	int res = i2c_master_send(client, (char *)&data, sizeof(data));
+
+	return res == sizeof(data)? 0 : res;
 }
 
 /**
diff --git a/drivers/iio/dac/max517.c b/drivers/iio/dac/max517.c
index 5507b39..0f3d81fc 100644
--- a/drivers/iio/dac/max517.c
+++ b/drivers/iio/dac/max517.c
@@ -117,15 +117,17 @@ static int max517_write_raw(struct iio_dev *indio_dev,
 static int max517_suspend(struct device *dev)
 {
 	u8 outbuf = COMMAND_PD;
+	int res = i2c_master_send(to_i2c_client(dev), &outbuf, 1);
 
-	return i2c_master_send(to_i2c_client(dev), &outbuf, 1);
+	return res == 1 ? 0 : res;
 }
 
 static int max517_resume(struct device *dev)
 {
 	u8 outbuf = 0;
+	int res = i2c_master_send(to_i2c_client(dev), &outbuf, 1);
 
-	return i2c_master_send(to_i2c_client(dev), &outbuf, 1);
+	return res == 1 ? 0 : res;
 }
 
 static SIMPLE_DEV_PM_OPS(max517_pm_ops, max517_suspend, max517_resume);
diff --git a/drivers/iio/dac/max5821.c b/drivers/iio/dac/max5821.c
index 28b8748..56f9252 100644
--- a/drivers/iio/dac/max5821.c
+++ b/drivers/iio/dac/max5821.c
@@ -278,7 +278,9 @@ static int max5821_suspend(struct device *dev)
 			 MAX5821_EXTENDED_DAC_B |
 			 MAX5821_EXTENDED_POWER_DOWN_MODE2 };
 
-	return i2c_master_send(to_i2c_client(dev), outbuf, 2);
+	int res = i2c_master_send(to_i2c_client(dev), outbuf, 2);
+
+	return res == 2 ? 0 : res;
 }
 
 static int max5821_resume(struct device *dev)
@@ -288,7 +290,9 @@ static int max5821_resume(struct device *dev)
 			 MAX5821_EXTENDED_DAC_B |
 			 MAX5821_EXTENDED_POWER_UP };
 
-	return i2c_master_send(to_i2c_client(dev), outbuf, 2);
+	int res = i2c_master_send(to_i2c_client(dev), outbuf, 2);
+
+	return res == 2 ? 0 : res;
 }
 
 static SIMPLE_DEV_PM_OPS(max5821_pm_ops, max5821_suspend, max5821_resume);
diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c
index 43d1458..166b607 100644
--- a/drivers/iio/dac/mcp4725.c
+++ b/drivers/iio/dac/mcp4725.c
@@ -39,12 +39,15 @@ static int mcp4725_suspend(struct device *dev)
 	struct mcp4725_data *data = iio_priv(i2c_get_clientdata(
 		to_i2c_client(dev)));
 	u8 outbuf[2];
+	int res;
 
 	outbuf[0] = (data->powerdown_mode + 1) << 4;
 	outbuf[1] = 0;
 	data->powerdown = true;
 
-	return i2c_master_send(data->client, outbuf, 2);
+	res = i2c_master_send(data->client, outbuf, 2);
+
+	return res == 2 ? 0 : res;
 }
 
 static int mcp4725_resume(struct device *dev)
@@ -52,13 +55,16 @@ static int mcp4725_resume(struct device *dev)
 	struct mcp4725_data *data = iio_priv(i2c_get_clientdata(
 		to_i2c_client(dev)));
 	u8 outbuf[2];
+	int res;
 
 	/* restore previous DAC value */
 	outbuf[0] = (data->dac_value >> 8) & 0xf;
 	outbuf[1] = data->dac_value & 0xff;
 	data->powerdown = false;
 
-	return i2c_master_send(data->client, outbuf, 2);
+	res = i2c_master_send(data->client, outbuf, 2);
+
+	return res == 2 ? 0 : res;
 }
 
 #ifdef CONFIG_PM_SLEEP
-- 
2.1.4

  reply	other threads:[~2015-10-27 16:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-27 16:25 iio:dac: fix i2c_master_send return code misuse Jean-Francois Dagenais
2015-10-27 16:25 ` Jean-Francois Dagenais [this message]
2015-10-27 16:34   ` [PATCH] " Jean-François Dagenais
2015-10-31 11:00   ` Jonathan Cameron
2015-11-03 14:27   ` Lars-Peter Clausen
2015-11-04  1:10     ` Dmitry Torokhov
2015-11-08 13:28       ` Jonathan Cameron
2015-11-08 14:10         ` Jean-Francois Dagenais
2015-11-08 15:10           ` Jonathan Cameron

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=1445963139-2158-2-git-send-email-jeff.dagenais@gmail.com \
    --to=jeff.dagenais@gmail.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /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