summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorBartosz Golaszewski <bgolaszewski@baylibre.com>2014-12-04 17:45:53 +0100
committerGuenter Roeck <linux@roeck-us.net>2014-12-04 11:00:44 -0800
commit90652efeba1a05300931b3fad53540b9bca73948 (patch)
tree56808b0109321ced1c6c4142aa90eb2e5d7a4b0b /drivers/hwmon
parent06adbaec2a7a3d04741557b411e264c7f9c91c85 (diff)
downloadop-kernel-dev-90652efeba1a05300931b3fad53540b9bca73948.zip
op-kernel-dev-90652efeba1a05300931b3fad53540b9bca73948.tar.gz
hwmon: (tmp401) Bail out from tmp401_probe() in case of write errors
The return value of i2c_smbus_read_byte_data() is checked in tmp401_init_client(), but only a warning is printed and the device is registered anyway. This leads to devices being registered even if they cannot be physically detected. Bail out from probe in case of write errors and notify the user. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/tmp401.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c
index ccd9938..f2182ee 100644
--- a/drivers/hwmon/tmp401.c
+++ b/drivers/hwmon/tmp401.c
@@ -615,10 +615,10 @@ static const struct attribute_group tmp432_group = {
* Begin non sysfs callback code (aka Real code)
*/
-static void tmp401_init_client(struct tmp401_data *data,
- struct i2c_client *client)
+static int tmp401_init_client(struct tmp401_data *data,
+ struct i2c_client *client)
{
- int config, config_orig;
+ int config, config_orig, status = 0;
/* Set the conversion rate to 2 Hz */
i2c_smbus_write_byte_data(client, TMP401_CONVERSION_RATE_WRITE, 5);
@@ -626,16 +626,18 @@ static void tmp401_init_client(struct tmp401_data *data,
/* Start conversions (disable shutdown if necessary) */
config = i2c_smbus_read_byte_data(client, TMP401_CONFIG_READ);
- if (config < 0) {
- dev_warn(&client->dev, "Initialization failed!\n");
- return;
- }
+ if (config < 0)
+ return config;
config_orig = config;
config &= ~TMP401_CONFIG_SHUTDOWN;
if (config != config_orig)
- i2c_smbus_write_byte_data(client, TMP401_CONFIG_WRITE, config);
+ status = i2c_smbus_write_byte_data(client,
+ TMP401_CONFIG_WRITE,
+ config);
+
+ return status;
}
static int tmp401_detect(struct i2c_client *client,
@@ -718,7 +720,7 @@ static int tmp401_probe(struct i2c_client *client,
struct device *dev = &client->dev;
struct device *hwmon_dev;
struct tmp401_data *data;
- int groups = 0;
+ int groups = 0, status;
data = devm_kzalloc(dev, sizeof(struct tmp401_data), GFP_KERNEL);
if (!data)
@@ -729,7 +731,9 @@ static int tmp401_probe(struct i2c_client *client,
data->kind = id->driver_data;
/* Initialize the TMP401 chip */
- tmp401_init_client(data, client);
+ status = tmp401_init_client(data, client);
+ if (status < 0)
+ return status;
/* Register sysfs hooks */
data->groups[groups++] = &tmp401_group;
OpenPOWER on IntegriCloud