From: Cosmin Tanislav <demonsingur@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: cosmin.tanislav@analog.com, demonsingur@gmail.com,
Jean Delvare <jdelvare@suse.com>,
Guenter Roeck <linux@roeck-us.net>,
linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v1 3/8] hwmon: (adt7x10) Add device managed action for restoring config
Date: Tue, 21 Dec 2021 22:11:08 +0200 [thread overview]
Message-ID: <20211221201113.752827-3-demonsingur@gmail.com> (raw)
In-Reply-To: <20211221201113.752827-1-demonsingur@gmail.com>
From: Cosmin Tanislav <cosmin.tanislav@analog.com>
To simplify the core driver remove function.
Signed-off-by: Cosmin Tanislav <cosmin.tanislav@analog.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
next prev parent reply other threads:[~2021-12-21 20:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-21 20:11 [PATCH v1 1/8] hwmon: (adt7410) Pass name to core driver Cosmin Tanislav
2021-12-21 20:11 ` [PATCH v1 2/8] hwmon: (adt7x10) Store bus_dev in private data Cosmin Tanislav
2021-12-21 20:11 ` Cosmin Tanislav [this message]
2021-12-21 20:11 ` [PATCH v1 4/8] hwmon: (adt7x10) Use devm_hwmon_device_register_with_info Cosmin Tanislav
2021-12-21 20:11 ` [PATCH v1 5/8] hwmon: (adt7x10) Use devm_request_threaded_irq Cosmin Tanislav
2021-12-21 20:11 ` [PATCH v1 6/8] hwmon: (adt7x10) Remove empty driver removal callback Cosmin Tanislav
2021-12-21 20:11 ` [PATCH v1 7/8] hwmon: (adt7x10) Pass hwinfo dev to irq handler Cosmin Tanislav
2021-12-21 20:11 ` [PATCH v1 8/8] hwmon: (adt7x10) Use hwmon_notify_event Cosmin Tanislav
2021-12-21 20:47 ` [PATCH v1 1/8] hwmon: (adt7410) Pass name to core driver Guenter Roeck
2021-12-21 20:58 ` Cosmin Tanislav
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211221201113.752827-3-demonsingur@gmail.com \
--to=demonsingur@gmail.com \
--cc=cosmin.tanislav@analog.com \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox