From: Vincent Whitchurch <vincent.whitchurch@axis.com>
To: <jic23@kernel.org>
Cc: <kernel@axis.com>,
Vincent Whitchurch <vincent.whitchurch@axis.com>,
<andy.shevchenko@gmail.com>, <lars@metafoo.de>,
<linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH v2 4/5] iio: adc: mcp320x: use device managed functions
Date: Wed, 31 Aug 2022 12:05:05 +0200 [thread overview]
Message-ID: <20220831100506.3368103-5-vincent.whitchurch@axis.com> (raw)
In-Reply-To: <20220831100506.3368103-1-vincent.whitchurch@axis.com>
Use devm_* functions in probe to remove some code and to make it easier
to add further calls to the probe function.
Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
drivers/iio/adc/mcp320x.c | 30 ++++++++++--------------------
1 file changed, 10 insertions(+), 20 deletions(-)
diff --git a/drivers/iio/adc/mcp320x.c b/drivers/iio/adc/mcp320x.c
index 8ed27df9a0bb..b1c1bf4b8047 100644
--- a/drivers/iio/adc/mcp320x.c
+++ b/drivers/iio/adc/mcp320x.c
@@ -390,6 +390,11 @@ static const struct mcp320x_chip_info mcp320x_chip_infos[] = {
},
};
+static void mcp320x_reg_disable(void *reg)
+{
+ regulator_disable(reg);
+}
+
static int mcp320x_probe(struct spi_device *spi)
{
struct iio_dev *indio_dev;
@@ -460,27 +465,13 @@ static int mcp320x_probe(struct spi_device *spi)
if (ret < 0)
return ret;
- mutex_init(&adc->lock);
-
- ret = iio_device_register(indio_dev);
- if (ret < 0)
- goto reg_disable;
-
- return 0;
-
-reg_disable:
- regulator_disable(adc->reg);
-
- return ret;
-}
+ ret = devm_add_action_or_reset(&spi->dev, mcp320x_reg_disable, adc->reg);
+ if (ret)
+ return ret;
-static void mcp320x_remove(struct spi_device *spi)
-{
- struct iio_dev *indio_dev = spi_get_drvdata(spi);
- struct mcp320x *adc = iio_priv(indio_dev);
+ mutex_init(&adc->lock);
- iio_device_unregister(indio_dev);
- regulator_disable(adc->reg);
+ return devm_iio_device_register(&spi->dev, indio_dev);
}
static const struct of_device_id mcp320x_dt_ids[] = {
@@ -535,7 +526,6 @@ static struct spi_driver mcp320x_driver = {
.of_match_table = mcp320x_dt_ids,
},
.probe = mcp320x_probe,
- .remove = mcp320x_remove,
.id_table = mcp320x_id,
};
module_spi_driver(mcp320x_driver);
--
2.34.1
next prev parent reply other threads:[~2022-08-31 10:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-31 10:05 [PATCH v2 0/5] iio: adc: mcp320x: Add triggered buffer support Vincent Whitchurch
2022-08-31 10:05 ` [PATCH v2 1/5] iio: adc: mcp320x: use callbacks for RX conversion Vincent Whitchurch
2022-08-31 12:40 ` Andy Shevchenko
2022-08-31 14:19 ` Vincent Whitchurch
2022-08-31 20:21 ` Andy Shevchenko
2022-09-04 16:15 ` Jonathan Cameron
2022-09-05 8:27 ` Vincent Whitchurch
2022-09-05 8:38 ` Andy Shevchenko
2022-08-31 10:05 ` [PATCH v2 2/5] iio: adc: mcp320x: remove device_index check for TX Vincent Whitchurch
2022-08-31 12:42 ` Andy Shevchenko
2022-08-31 10:05 ` [PATCH v2 3/5] iio: adc: mcp320x: use conv_time instead of device_index switch Vincent Whitchurch
2022-08-31 12:43 ` Andy Shevchenko
2022-08-31 10:05 ` Vincent Whitchurch [this message]
2022-08-31 12:50 ` [PATCH v2 4/5] iio: adc: mcp320x: use device managed functions Andy Shevchenko
2022-09-04 16:08 ` Jonathan Cameron
2022-08-31 10:05 ` [PATCH v2 5/5] iio: adc: mcp320x: add triggered buffer support Vincent Whitchurch
2022-09-04 16:26 ` 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=20220831100506.3368103-5-vincent.whitchurch@axis.com \
--to=vincent.whitchurch@axis.com \
--cc=andy.shevchenko@gmail.com \
--cc=jic23@kernel.org \
--cc=kernel@axis.com \
--cc=lars@metafoo.de \
--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