From af910e92886c35461ccc5ea234e17f448a46b876 Mon Sep 17 00:00:00 2001 From: Cosmin Tanislav Date: Tue, 21 Dec 2021 23:58:36 +0200 Subject: hwmon: (adt7x10) Add device managed action for restoring config To simplify the core driver remove function. Signed-off-by: Cosmin Tanislav Link: https://lore.kernel.org/r/20211221215841.2641417-3-demonsingur@gmail.com [groeck: Adjust to use regmap; only register restore function if needed] Tested-by: Cosmin Tanislav Reviewed-by: Cosmin Tanislav Signed-off-by: Guenter Roeck --- drivers/hwmon/adt7x10.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/hwmon/adt7x10.c b/drivers/hwmon/adt7x10.c index 05dd48b707b4..47ce1a88a03f 100644 --- a/drivers/hwmon/adt7x10.c +++ b/drivers/hwmon/adt7x10.c @@ -296,6 +296,13 @@ static const struct attribute_group adt7x10_group = { .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) { @@ -333,13 +340,16 @@ int adt7x10_probe(struct device *dev, const char *name, int irq, 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 @@ -375,8 +385,6 @@ exit_remove_name: 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); @@ -392,8 +400,6 @@ void adt7x10_remove(struct device *dev, int irq) 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); -- cgit v1.2.3