.attrs = adt7x10_attributes,
};
+static void adt7x10_restore_config(void *private)
+{
+ struct adt7x10_data *data = private;
+
+ regmap_write(data->regmap, ADT7X10_CONFIG, data->oldconfig);
+}
+
int adt7x10_probe(struct device *dev, const char *name, int irq,
struct regmap *regmap)
{
ret = regmap_write(regmap, ADT7X10_CONFIG, data->config);
if (ret)
return ret;
+ ret = devm_add_action_or_reset(dev, adt7x10_restore_config, data);
+ if (ret)
+ return ret;
}
dev_dbg(dev, "Config %02x\n", data->config);
/* Register sysfs hooks */
ret = sysfs_create_group(&dev->kobj, &adt7x10_group);
if (ret)
- goto exit_restore;
+ return ret;
/*
* The I2C device will already have it's own 'name' attribute, but for
device_remove_file(dev, &dev_attr_name);
exit_remove:
sysfs_remove_group(&dev->kobj, &adt7x10_group);
-exit_restore:
- regmap_write(regmap, ADT7X10_CONFIG, data->oldconfig);
return ret;
}
EXPORT_SYMBOL_GPL(adt7x10_probe);
if (data->name)
device_remove_file(dev, &dev_attr_name);
sysfs_remove_group(&dev->kobj, &adt7x10_group);
- if (data->oldconfig != data->config)
- regmap_write(data->regmap, ADT7X10_CONFIG, data->oldconfig);
}
EXPORT_SYMBOL_GPL(adt7x10_remove);