]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
hwmon: (lm90) Restore original configuration if probe function fails
authorGuenter Roeck <linux@roeck-us.net>
Fri, 23 Mar 2012 09:02:18 +0000 (10:02 +0100)
committerJean Delvare <khali@endymion.delvare>
Fri, 23 Mar 2012 09:02:18 +0000 (10:02 +0100)
The lm90 driver restores the original chip configuration in its exit function.
However, the chip configuration is not restored if the probe function fails.
Restore it there as well.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
drivers/hwmon/lm90.c

index 3309a511e8e1ebc09784141a5e38796ac3620d8d..22b14a68e35e7659a48a88c76b98ffda29fb65a7 100644 (file)
@@ -1336,6 +1336,15 @@ static void lm90_remove_files(struct i2c_client *client, struct lm90_data *data)
        sysfs_remove_group(&dev->kobj, &lm90_group);
 }
 
+static void lm90_restore_conf(struct i2c_client *client, struct lm90_data *data)
+{
+       /* Restore initial configuration */
+       i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE,
+                                 data->convrate_orig);
+       i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
+                                 data->config_orig);
+}
+
 static void lm90_init_client(struct i2c_client *client)
 {
        u8 config, convrate;
@@ -1424,7 +1433,7 @@ static int lm90_probe(struct i2c_client *client,
        /* Register sysfs hooks */
        err = sysfs_create_group(&dev->kobj, &lm90_group);
        if (err)
-               goto exit_free;
+               goto exit_restore;
        if (client->flags & I2C_CLIENT_PEC) {
                err = device_create_file(dev, &dev_attr_pec);
                if (err)
@@ -1463,7 +1472,8 @@ static int lm90_probe(struct i2c_client *client,
 
 exit_remove_files:
        lm90_remove_files(client, data);
-exit_free:
+exit_restore:
+       lm90_restore_conf(client, data);
        kfree(data);
 exit:
        return err;
@@ -1475,12 +1485,7 @@ static int lm90_remove(struct i2c_client *client)
 
        hwmon_device_unregister(data->hwmon_dev);
        lm90_remove_files(client, data);
-
-       /* Restore initial configuration */
-       i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE,
-                                 data->convrate_orig);
-       i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
-                                 data->config_orig);
+       lm90_restore_conf(client, data);
 
        kfree(data);
        return 0;