Commit f975b339 authored by Bartosz Golaszewski's avatar Bartosz Golaszewski Committed by Guenter Roeck

hwmon: (ina2xx) bail-out from ina2xx_probe() in case of configuration errors

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: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
[Guenter Roeck: Fixed multi-line comment style]
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 9cd892bc
......@@ -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,25 @@ 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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment