LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] iio: dac: max5821: convert device register to device managed function
@ 2021-07-18 20:37 Théo Borém Fabris
  2021-07-19  7:32 ` Alexandru Ardelean
  0 siblings, 1 reply; 8+ messages in thread
From: Théo Borém Fabris @ 2021-07-18 20:37 UTC (permalink / raw)
  To: jic23, lars; +Cc: linux-iio, linux-kernel, Théo Borém Fabris

Add a device managed hook, via devm_add_action_or_reset() and
max5821_regulator_disable(), to disable voltage regulator on device
detach.
Replace iio_device_register() by devm_iio_device_register() and remove
the max5821_remove() function used to unregister the device and disable the
voltage regulator.
Remove i2c_set_clientdata() from the probe function, since
i2c_get_clientdata() is not used anymore.

Signed-off-by: Théo Borém Fabris <theobf@usp.br>
---
 drivers/iio/dac/max5821.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/drivers/iio/dac/max5821.c b/drivers/iio/dac/max5821.c
index bd6e75699a63..44c04ae70b32 100644
--- a/drivers/iio/dac/max5821.c
+++ b/drivers/iio/dac/max5821.c
@@ -294,6 +294,13 @@ static const struct iio_info max5821_info = {
 	.write_raw = max5821_write_raw,
 };
 
+static void max5821_regulator_disable(void *data)
+{
+	struct regulator *rdata = data;
+
+	regulator_disable(rdata);
+}
+
 static int max5821_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
@@ -306,7 +313,6 @@ static int max5821_probe(struct i2c_client *client,
 	if (!indio_dev)
 		return -ENOMEM;
 	data = iio_priv(indio_dev);
-	i2c_set_clientdata(client, indio_dev);
 	data->client = client;
 	mutex_init(&data->lock);
 
@@ -331,6 +337,14 @@ static int max5821_probe(struct i2c_client *client,
 		goto error_free_reg;
 	}
 
+	ret = devm_add_action_or_reset(&client->dev, max5821_regulator_disable,
+				       data->vref_reg);
+	if (ret) {
+		dev_err(&client->dev,
+			"Failed to add action to managed regulator: %d\n", ret);
+		goto error_disable_reg;
+	}
+
 	ret = regulator_get_voltage(data->vref_reg);
 	if (ret < 0) {
 		dev_err(&client->dev,
@@ -346,7 +360,7 @@ static int max5821_probe(struct i2c_client *client,
 	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->info = &max5821_info;
 
-	return iio_device_register(indio_dev);
+	return devm_iio_device_register(&client->dev, indio_dev);
 
 error_disable_reg:
 	regulator_disable(data->vref_reg);
@@ -356,17 +370,6 @@ static int max5821_probe(struct i2c_client *client,
 	return ret;
 }
 
-static int max5821_remove(struct i2c_client *client)
-{
-	struct iio_dev *indio_dev = i2c_get_clientdata(client);
-	struct max5821_data *data = iio_priv(indio_dev);
-
-	iio_device_unregister(indio_dev);
-	regulator_disable(data->vref_reg);
-
-	return 0;
-}
-
 static const struct i2c_device_id max5821_id[] = {
 	{ "max5821", ID_MAX5821 },
 	{ }
@@ -386,7 +389,6 @@ static struct i2c_driver max5821_driver = {
 		.pm     = &max5821_pm_ops,
 	},
 	.probe		= max5821_probe,
-	.remove		= max5821_remove,
 	.id_table	= max5821_id,
 };
 module_i2c_driver(max5821_driver);
-- 
2.20.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-07-24 22:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-18 20:37 [PATCH] iio: dac: max5821: convert device register to device managed function Théo Borém Fabris
2021-07-19  7:32 ` Alexandru Ardelean
2021-07-19 15:24   ` Théo Borém Fabris
2021-07-20  7:22     ` Alexandru Ardelean
2021-07-20  7:33       ` Sa, Nuno
2021-07-21  0:11       ` Théo Borém Fabris
2021-07-21  7:23         ` Alexandru Ardelean
2021-07-24 22:48           ` Théo Borém Fabris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).