[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211221215841.2641417-3-demonsingur@gmail.com>
Date: Tue, 21 Dec 2021 23:58:36 +0200
From: Cosmin Tanislav <demonsingur@...il.com>
To: unlisted-recipients:; (no To-header on input)
Cc: cosmin.tanislav@...log.com, demonsingur@...il.com,
Jean Delvare <jdelvare@...e.com>,
Guenter Roeck <linux@...ck-us.net>,
linux-hwmon@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH v3 2/7] hwmon: (adt7x10) Add device managed action for restoring config
From: Cosmin Tanislav <cosmin.tanislav@...log.com>
To simplify the core driver remove function.
Signed-off-by: Cosmin Tanislav <cosmin.tanislav@...log.com>
---
drivers/hwmon/adt7x10.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/drivers/hwmon/adt7x10.c b/drivers/hwmon/adt7x10.c
index 2439da9b64e6..e8a6c541a590 100644
--- a/drivers/hwmon/adt7x10.c
+++ b/drivers/hwmon/adt7x10.c
@@ -357,6 +357,17 @@ static const struct attribute_group adt7x10_group = {
.attrs = adt7x10_attributes,
};
+static void adt7x10_restore_config(void *private)
+{
+ struct adt7x10_data *data = private;
+ struct device *dev = data->bus_dev;
+
+ if (data->oldconfig == data->config)
+ return;
+
+ adt7x10_write_byte(dev, ADT7X10_CONFIG, data->oldconfig);
+}
+
int adt7x10_probe(struct device *dev, const char *name, int irq,
const struct adt7x10_ops *ops)
{
@@ -397,14 +408,18 @@ int adt7x10_probe(struct device *dev, const char *name, int irq,
}
dev_dbg(dev, "Config %02x\n", data->config);
+ ret = devm_add_action_or_reset(dev, adt7x10_restore_config, data);
+ if (ret)
+ return ret;
+
ret = adt7x10_fill_cache(dev);
if (ret)
- goto exit_restore;
+ return ret;
/* 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
@@ -440,8 +455,6 @@ int adt7x10_probe(struct device *dev, const char *name, int irq,
device_remove_file(dev, &dev_attr_name);
exit_remove:
sysfs_remove_group(&dev->kobj, &adt7x10_group);
-exit_restore:
- adt7x10_write_byte(dev, ADT7X10_CONFIG, data->oldconfig);
return ret;
}
EXPORT_SYMBOL_GPL(adt7x10_probe);
@@ -457,8 +470,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)
- adt7x10_write_byte(dev, ADT7X10_CONFIG, data->oldconfig);
}
EXPORT_SYMBOL_GPL(adt7x10_remove);
--
2.34.1
Powered by blists - more mailing lists