mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Benoit Cousson <bcousson@baylibre.com>,
	Patrick Titiano <ptitiano@baylibre.com>,
	LM Sensors <lm-sensors@lm-sensors.org>,
	Jean Delvare <jdelvare@suse.de>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: [PATCH v2 1/5] hwmon: ina2xx: bail-out from ina2xx_probe() in case of configuration errors
Date: Thu, 27 Nov 2014 10:59:06 +0100	[thread overview]
Message-ID: <1417082350-23470-2-git-send-email-bgolaszewski@baylibre.com> (raw)
In-Reply-To: <1417082350-23470-1-git-send-email-bgolaszewski@baylibre.com>

The return value of i2c_smbus_write_word_swapped() isn't checked in
ina2xx_probe(). This leads to devices being registered even if they cannot
be physically detected (e.g. device is not powered-up at boot-time).

Even after restoring power to such device, it is left unconfigured as the
configuration has never been actually written to the register.

Error out in case of write errors in probe and notify the user.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/hwmon/ina2xx.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
index bfd3f3e..0a6b60f 100644
--- a/drivers/hwmon/ina2xx.c
+++ b/drivers/hwmon/ina2xx.c
@@ -223,6 +223,7 @@ static int ina2xx_probe(struct i2c_client *client,
 	struct device *hwmon_dev;
 	long shunt = 10000; /* default shunt value 10mOhms */
 	u32 val;
+	int ret;
 
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
 		return -ENODEV;
@@ -247,12 +248,24 @@ static int ina2xx_probe(struct i2c_client *client,
 	data->config = &ina2xx_config[data->kind];
 
 	/* device configuration */
-	i2c_smbus_write_word_swapped(client, INA2XX_CONFIG,
-				     data->config->config_default);
-	/* set current LSB to 1mA, shunt is in uOhms */
-	/* (equation 13 in datasheet) */
-	i2c_smbus_write_word_swapped(client, INA2XX_CALIBRATION,
-				     data->config->calibration_factor / shunt);
+	ret = i2c_smbus_write_word_swapped(client, INA2XX_CONFIG,
+					   data->config->config_default);
+	if (ret < 0) {
+		dev_err(dev,
+			"error writing to the config register: %d", ret);
+		return -ENODEV;
+	}
+
+	/* Set current LSB to 1mA, shunt is in uOhms
+	 * (equation 13 in datasheet).
+	 */
+	ret = i2c_smbus_write_word_swapped(client, INA2XX_CALIBRATION,
+				data->config->calibration_factor / shunt);
+	if (ret < 0) {
+		dev_err(dev,
+			"error writing to the calibration register: %d", ret);
+		return -ENODEV;
+	}
 
 	data->client = client;
 	mutex_init(&data->update_lock);
-- 
2.1.3


  reply	other threads:[~2014-11-27 10:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-27  9:59 [PATCH v2 0/5] hwmon: ina2xx: fixes & extensions Bartosz Golaszewski
2014-11-27  9:59 ` Bartosz Golaszewski [this message]
2014-11-30 19:44   ` [PATCH v2 1/5] hwmon: ina2xx: bail-out from ina2xx_probe() in case of configuration errors Guenter Roeck
2014-11-27  9:59 ` [PATCH v2 2/5] hwmon: ina2xx: make shunt resistance configurable at run-time Bartosz Golaszewski
2014-11-30 19:44   ` Guenter Roeck
2014-11-30 20:01   ` Guenter Roeck
2014-11-27  9:59 ` [PATCH v2 3/5] hwmon: ina2xx: allow to change the averaging rate " Bartosz Golaszewski
2014-11-30 19:59   ` Guenter Roeck
2014-11-27  9:59 ` [PATCH v2 4/5] hwmon: ina2xx: change hex constants to lower-case Bartosz Golaszewski
2014-11-30 20:05   ` Guenter Roeck
2014-11-27  9:59 ` [PATCH v2 5/5] hwmon: ina2xx: documentation update for new sysfs attributes Bartosz Golaszewski

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=1417082350-23470-2-git-send-email-bgolaszewski@baylibre.com \
    --to=bgolaszewski@baylibre.com \
    --cc=bcousson@baylibre.com \
    --cc=jdelvare@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=lm-sensors@lm-sensors.org \
    --cc=ptitiano@baylibre.com \
    /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