diff options
author | Cosmin Tanislav <cosmin.tanislav@analog.com> | 2021-12-21 22:58:36 +0100 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2022-02-28 02:03:18 +0100 |
commit | af910e92886c35461ccc5ea234e17f448a46b876 (patch) | |
tree | a8d0ed1bf64ee5aa0299c07c1d6380c2d6a90036 /drivers | |
parent | hwmon: (adt7x10) Convert to use regmap (diff) | |
download | linux-af910e92886c35461ccc5ea234e17f448a46b876.tar.xz linux-af910e92886c35461ccc5ea234e17f448a46b876.zip |
hwmon: (adt7x10) Add device managed action for restoring config
To simplify the core driver remove function.
Signed-off-by: Cosmin Tanislav <cosmin.tanislav@analog.com>
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 <cosmin.tanislav@analog.com>
Reviewed-by: Cosmin Tanislav <cosmin.tanislav@analog.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/hwmon/adt7x10.c | 16 |
1 files changed, 11 insertions, 5 deletions
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); |