From: David Lechner <dlechner@baylibre.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Michael Hennerich <Michael.Hennerich@analog.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
David Lechner <dlechner@baylibre.com>
Subject: [PATCH 02/11] iio: dac: ad5380: drop driver remove callbacks
Date: Wed, 23 Oct 2024 18:54:06 -0500 [thread overview]
Message-ID: <20241023-iio-regulator-refactor-round-5-v1-2-d0bd396b3f50@baylibre.com> (raw)
In-Reply-To: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com>
Drop use of the driver remove callbacks in the ad5380 driver.
By making use of a few more devm_ helpers, we can avoid the need for
remove callbacks entirely.
Also make use of dev_err_probe() while at it.
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/dac/ad5380.c | 61 +++++++++++-------------------------------------
1 file changed, 13 insertions(+), 48 deletions(-)
diff --git a/drivers/iio/dac/ad5380.c b/drivers/iio/dac/ad5380.c
index 7d1d7053c29e..392a1c7aee03 100644
--- a/drivers/iio/dac/ad5380.c
+++ b/drivers/iio/dac/ad5380.c
@@ -339,14 +339,14 @@ static const struct ad5380_chip_info ad5380_chip_info_tbl[] = {
},
};
-static int ad5380_alloc_channels(struct iio_dev *indio_dev)
+static int ad5380_alloc_channels(struct device *dev, struct iio_dev *indio_dev)
{
struct ad5380_state *st = iio_priv(indio_dev);
struct iio_chan_spec *channels;
unsigned int i;
- channels = kcalloc(st->chip_info->num_channels,
- sizeof(struct iio_chan_spec), GFP_KERNEL);
+ channels = devm_kcalloc(dev, st->chip_info->num_channels,
+ sizeof(struct iio_chan_spec), GFP_KERNEL);
if (!channels)
return -ENOMEM;
@@ -377,7 +377,6 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap,
}
st = iio_priv(indio_dev);
- dev_set_drvdata(dev, indio_dev);
st->chip_info = &ad5380_chip_info_tbl[type];
st->regmap = regmap;
@@ -389,20 +388,16 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap,
mutex_init(&st->lock);
- ret = ad5380_alloc_channels(indio_dev);
- if (ret) {
- dev_err(dev, "Failed to allocate channel spec: %d\n", ret);
- return ret;
- }
+ ret = ad5380_alloc_channels(dev, indio_dev);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to allocate channel spec\n");
if (st->chip_info->int_vref == 2500)
ctrl |= AD5380_CTRL_INT_VREF_2V5;
ret = devm_regulator_get_enable_read_voltage(dev, "vref");
- if (ret < 0 && ret != -ENODEV) {
- dev_err(dev, "Failed to get vref voltage: %d\n", ret);
- goto error_free_reg;
- }
+ if (ret < 0 && ret != -ENODEV)
+ return dev_err_probe(dev, ret, "Failed to get vref voltage\n");
if (ret == -ENODEV) {
st->vref = st->chip_info->int_vref;
ctrl |= AD5380_CTRL_INT_VREF_EN;
@@ -411,32 +406,14 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap,
}
ret = regmap_write(st->regmap, AD5380_REG_SF_CTRL, ctrl);
- if (ret) {
- dev_err(dev, "Failed to write to device: %d\n", ret);
- goto error_free_reg;
- }
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to write to device\n");
- ret = iio_device_register(indio_dev);
- if (ret) {
- dev_err(dev, "Failed to register iio device: %d\n", ret);
- goto error_free_reg;
- }
+ ret = devm_iio_device_register(dev, indio_dev);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to register iio device\n");
return 0;
-
-error_free_reg:
- kfree(indio_dev->channels);
-
- return ret;
-}
-
-static void ad5380_remove(struct device *dev)
-{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
-
- iio_device_unregister(indio_dev);
-
- kfree(indio_dev->channels);
}
static bool ad5380_reg_false(struct device *dev, unsigned int reg)
@@ -470,11 +447,6 @@ static int ad5380_spi_probe(struct spi_device *spi)
return ad5380_probe(&spi->dev, regmap, id->driver_data, id->name);
}
-static void ad5380_spi_remove(struct spi_device *spi)
-{
- ad5380_remove(&spi->dev);
-}
-
static const struct spi_device_id ad5380_spi_ids[] = {
{ "ad5380-3", ID_AD5380_3 },
{ "ad5380-5", ID_AD5380_5 },
@@ -501,7 +473,6 @@ static struct spi_driver ad5380_spi_driver = {
.name = "ad5380",
},
.probe = ad5380_spi_probe,
- .remove = ad5380_spi_remove,
.id_table = ad5380_spi_ids,
};
@@ -543,11 +514,6 @@ static int ad5380_i2c_probe(struct i2c_client *i2c)
return ad5380_probe(&i2c->dev, regmap, id->driver_data, id->name);
}
-static void ad5380_i2c_remove(struct i2c_client *i2c)
-{
- ad5380_remove(&i2c->dev);
-}
-
static const struct i2c_device_id ad5380_i2c_ids[] = {
{ "ad5380-3", ID_AD5380_3 },
{ "ad5380-5", ID_AD5380_5 },
@@ -574,7 +540,6 @@ static struct i2c_driver ad5380_i2c_driver = {
.name = "ad5380",
},
.probe = ad5380_i2c_probe,
- .remove = ad5380_i2c_remove,
.id_table = ad5380_i2c_ids,
};
--
2.43.0
next prev parent reply other threads:[~2024-10-23 23:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-23 23:54 [PATCH 00/11] iio: use devm_regulator_get_enable_read_voltage round 5 David Lechner
2024-10-23 23:54 ` [PATCH 01/11] iio: dac: ad5380: use devm_regulator_get_enable_read_voltage() David Lechner
2024-10-23 23:54 ` David Lechner [this message]
2024-10-23 23:54 ` [PATCH 03/11] iio: dac: ad5446: " David Lechner
2024-10-23 23:54 ` [PATCH 04/11] iio: dac: ad5446: drop driver remove callbacks David Lechner
2024-10-23 23:54 ` [PATCH 05/11] iio: dac: ad5504: use devm_regulator_get_enable_read_voltage() David Lechner
2024-10-23 23:54 ` [PATCH 06/11] iio: dac: ad5504: drop driver remove callback David Lechner
2024-10-23 23:54 ` [PATCH 07/11] iio: dac: ad5624r: use devm_regulator_get_enable_read_voltage() David Lechner
2024-10-23 23:54 ` [PATCH 08/11] iio: dac: ad5624r: drop driver remove callback David Lechner
2024-10-23 23:54 ` [PATCH 09/11] iio: dac: ad5761: use devm_regulator_get_enable_read_voltage() David Lechner
2024-10-23 23:54 ` [PATCH 10/11] iio: dac: ad5761: drop driver remove callback David Lechner
2024-10-23 23:54 ` [PATCH 11/11] iio: dac: ad5770r: use devm_regulator_get_enable_read_voltage() David Lechner
2024-10-26 14:55 ` [PATCH 00/11] iio: use devm_regulator_get_enable_read_voltage round 5 Jonathan Cameron
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=20241023-iio-regulator-refactor-round-5-v1-2-d0bd396b3f50@baylibre.com \
--to=dlechner@baylibre.com \
--cc=Michael.Hennerich@analog.com \
--cc=broonie@kernel.org \
--cc=jic23@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®