Linux-Hwmon Archive on lore.kernel.org
 help / color / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Hardware Monitoring <linux-hwmon@vger.kernel.org>
Cc: Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>,
	Jean-Francois Dagenais <jeff.dagenais@gmail.com>
Subject: [PATCH 09/11] hwmon: (max6650) Improve error handling in max6650_update_device
Date: Tue, 23 Apr 2019 06:33:09 -0700
Message-ID: <1556026391-15360-9-git-send-email-linux@roeck-us.net> (raw)
In-Reply-To: <1556026391-15360-1-git-send-email-linux@roeck-us.net>

Pass errors from i2c_smbus_read_byte_data() back to the caller of
max6650_update_device().

Cc: Jean-Francois Dagenais <jeff.dagenais@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/max6650.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c
index 7c8b1b8ededc..3c79949a741c 100644
--- a/drivers/hwmon/max6650.c
+++ b/drivers/hwmon/max6650.c
@@ -171,14 +171,19 @@ static struct max6650_data *max6650_update_device(struct device *dev)
 {
 	struct max6650_data *data = dev_get_drvdata(dev);
 	struct i2c_client *client = data->client;
+	int reg, err = 0;
 	int i;
 
 	mutex_lock(&data->update_lock);
 
 	if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
 		for (i = 0; i < data->nr_fans; i++) {
-			data->tach[i] = i2c_smbus_read_byte_data(client,
-								 tach_reg[i]);
+			reg = i2c_smbus_read_byte_data(client, tach_reg[i]);
+			if (reg < 0) {
+				err = reg;
+				goto error;
+			}
+			data->tach[i] = reg;
 		}
 
 		/*
@@ -186,15 +191,20 @@ static struct max6650_data *max6650_update_device(struct device *dev)
 		 * caused the alarm is removed. Keep the value latched here
 		 * for providing the register through different alarm files.
 		 */
-		data->alarm |= i2c_smbus_read_byte_data(client,
-							MAX6650_REG_ALARM);
-
+		reg = i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM);
+		if (reg < 0) {
+			err = reg;
+			goto error;
+		}
+		data->alarm |= reg;
 		data->last_updated = jiffies;
 		data->valid = true;
 	}
 
+error:
 	mutex_unlock(&data->update_lock);
-
+	if (err)
+		data = ERR_PTR(err);
 	return data;
 }
 
@@ -303,8 +313,12 @@ static ssize_t alarm_show(struct device *dev,
 {
 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
 	struct max6650_data *data = max6650_update_device(dev);
-	bool alarm = data->alarm & attr->index;
+	bool alarm;
 
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
+	alarm = data->alarm & attr->index;
 	if (alarm) {
 		mutex_lock(&data->update_lock);
 		data->alarm &= ~attr->index;
@@ -531,6 +545,9 @@ static int max6650_read(struct device *dev, enum hwmon_sensor_types type,
 	struct max6650_data *data = max6650_update_device(dev);
 	int mode;
 
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
 	switch (type) {
 	case hwmon_pwm:
 		switch (attr) {
-- 
2.7.4


  parent reply index

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-23 13:33 [PATCH 01/11] hwmon: (max6650) Use devm_add_action to unregister thermal device Guenter Roeck
2019-04-23 13:33 ` [PATCH 02/11] hwmon: (max6650) Introduce pwm_to_dac and dac_to_pwm Guenter Roeck
2019-04-23 15:23   ` Jean-Francois Dagenais
2019-04-23 17:02     ` Guenter Roeck
2019-04-23 13:33 ` [PATCH 03/11] hwmon: (max6650) Improve error handling in max6650_init_client Guenter Roeck
2019-04-23 13:33 ` [PATCH 04/11] hwmon: (max6650) Declare valid as boolean Guenter Roeck
2019-04-23 13:33 ` [PATCH 05/11] hwmon: (max6650) Cache alarm_en register Guenter Roeck
2019-04-23 13:33 ` [PATCH 06/11] hwmon: (max6650) Simplify alarm handling Guenter Roeck
2019-04-23 13:33 ` [PATCH 07/11] hwmon: (max6650) Convert to use devm_hwmon_device_register_with_info Guenter Roeck
2019-04-24 13:42   ` Guenter Roeck
2019-04-23 13:33 ` [PATCH 08/11] hwmon: (max6650) Read non-volatile registers only once Guenter Roeck
2019-04-23 13:33 ` Guenter Roeck [this message]
2019-04-23 13:33 ` [PATCH 10/11] hwmon: (max6650) Use SPDX license identifier Guenter Roeck
2019-04-23 13:33 ` [PATCH 11/11] hwmon: (max6650) Fix minor formatting issues Guenter Roeck
2019-04-23 14:38   ` Jean-Francois Dagenais
2019-04-23 15:18     ` Guenter Roeck

Reply instructions:

You may reply publically 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=1556026391-15360-9-git-send-email-linux@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=jdelvare@suse.com \
    --cc=jeff.dagenais@gmail.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

Linux-Hwmon Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-hwmon/0 linux-hwmon/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-hwmon linux-hwmon/ https://lore.kernel.org/linux-hwmon \
		linux-hwmon@vger.kernel.org linux-hwmon@archiver.kernel.org
	public-inbox-index linux-hwmon

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-hwmon


AGPL code for this site: git clone https://public-inbox.org/ public-inbox