All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tokunori Ikegami <ikegami@allied-telesis.co.jp>
To: Jean Delvare <jdelvare@suse.com>
Cc: Tokunori Ikegami <ikegami@allied-telesis.co.jp>,
	Chris Packham <chris.packham@alliedtelesis.co.nz>,
	linux-hwmon@vger.kernel.org
Subject: [PATCH 2/5] hwmon: adt7475: Change read and write functions to return error
Date: Thu, 12 Jul 2018 10:04:47 +0900	[thread overview]
Message-ID: <20180712010450.10586-3-ikegami@allied-telesis.co.jp> (raw)
In-Reply-To: <20180712010450.10586-1-ikegami@allied-telesis.co.jp>

Currently adt7475_read_word and adt7475_write_word do not return error.
So change both functions to return error codes correctly.

Signed-off-by: Tokunori Ikegami <ikegami@allied-telesis.co.jp>
Cc: Chris Packham <chris.packham@alliedtelesis.co.nz>
Cc: linux-hwmon@vger.kernel.org
---
 drivers/hwmon/adt7475.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
index 234f725213f9..a40eb62ee6b1 100644
--- a/drivers/hwmon/adt7475.c
+++ b/drivers/hwmon/adt7475.c
@@ -303,20 +303,34 @@ static inline u16 volt2reg(int channel, long volt, u8 bypass_attn)
 	return clamp_val(reg, 0, 1023) & (0xff << 2);
 }
 
-static u16 adt7475_read_word(struct i2c_client *client, int reg)
+static int adt7475_read_word(struct i2c_client *client, int reg)
 {
-	u16 val;
+	int val, val2;
 
-	val = i2c_smbus_read_byte_data(client, reg);
-	val |= (i2c_smbus_read_byte_data(client, reg + 1) << 8);
+	val = adt7475_read(reg);
+	if (val < 0)
+		return val;
 
-	return val;
+	val2 = adt7475_read(reg + 1);
+	if (val2 < 0)
+		return val2;
+
+	return val | (val2 << 8);
 }
 
-static void adt7475_write_word(struct i2c_client *client, int reg, u16 val)
+static int adt7475_write_word(struct i2c_client *client, int reg, u16 val)
 {
-	i2c_smbus_write_byte_data(client, reg + 1, val >> 8);
-	i2c_smbus_write_byte_data(client, reg, val & 0xFF);
+	int ret;
+
+	ret = i2c_smbus_write_byte_data(client, reg + 1, val >> 8);
+	if (ret < 0)
+		return ret;
+
+	ret = i2c_smbus_write_byte_data(client, reg, val & 0xFF);
+	if (ret < 0)
+		return ret;
+
+	return 0;
 }
 
 static ssize_t show_voltage(struct device *dev, struct device_attribute *attr,
-- 
2.16.1


  parent reply	other threads:[~2018-07-12  1:12 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-12  1:04 [PATCH 0/5] hwmon: adt7475: Add error handling for update function Tokunori Ikegami
2018-07-12  1:04 ` [PATCH 1/5] hwmon: adt7475: Split device update function to measure and limits Tokunori Ikegami
2018-07-12  2:00   ` Guenter Roeck
2018-07-12  3:01     ` IKEGAMI Tokunori
2018-07-12  1:04 ` Tokunori Ikegami [this message]
2018-07-12  1:04 ` [PATCH 3/5] hwmon: adt7475: Change to use adt7475_read macro Tokunori Ikegami
2018-07-12  1:50   ` Guenter Roeck
2018-07-12  2:52     ` IKEGAMI Tokunori
2018-07-12  3:41       ` Guenter Roeck
2018-07-12  4:01         ` IKEGAMI Tokunori
2018-07-12  4:23           ` Guenter Roeck
2018-07-12  6:22             ` IKEGAMI Tokunori
2018-07-12 13:47             ` IKEGAMI Tokunori
2018-07-12 14:05               ` Guenter Roeck
2018-07-12 14:33                 ` IKEGAMI Tokunori
2018-07-12  1:04 ` [PATCH 4/5] hwmon: adt7475: Change to use adt7475_write macro Tokunori Ikegami
2018-07-12  1:52   ` Guenter Roeck
2018-07-12  2:56     ` IKEGAMI Tokunori
2018-07-12  1:04 ` [PATCH 5/5] hwmon: adt7475: Change update functions to add error handling Tokunori Ikegami

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=20180712010450.10586-3-ikegami@allied-telesis.co.jp \
    --to=ikegami@allied-telesis.co.jp \
    --cc=chris.packham@alliedtelesis.co.nz \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.