From: Jonathan Cameron <jic23@kernel.org>
To: "Frank Li" <Frank.Li@nxp.com>,
"Marek Vasut" <marek.vasut+renesas@gmail.com>,
linux-iio@vger.kernel.org, "Nuno Sá" <noname.nuno@gmail.com>
Cc: "Marek Vasut" <marex@denx.de>,
"Mike Looijmans" <mike.looijmans@topic.nl>,
"Nuno Sá" <nuno.sa@analog.com>,
"David Lechner" <dlechner@baylibre.com>,
"Jonathan Cameron" <Jonathan.Cameron@huawei.com>
Subject: [PATCH v2 3/8] iio: adc: ti-ads1100: Use guard(mutex) to allow direct returns
Date: Sun, 9 Mar 2025 16:58:14 +0000 [thread overview]
Message-ID: <20250309165819.1346684-4-jic23@kernel.org> (raw)
In-Reply-To: <20250309165819.1346684-1-jic23@kernel.org>
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Use of automated lock release simplifies the code.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Mike Looijmans <mike.looijmans@topic.nl>
---
drivers/iio/adc/ti-ads1100.c | 39 +++++++++++++-----------------------
1 file changed, 14 insertions(+), 25 deletions(-)
diff --git a/drivers/iio/adc/ti-ads1100.c b/drivers/iio/adc/ti-ads1100.c
index 1e46f07a9ca6..0519f8afb033 100644
--- a/drivers/iio/adc/ti-ads1100.c
+++ b/drivers/iio/adc/ti-ads1100.c
@@ -10,6 +10,7 @@
#include <linux/bitfield.h>
#include <linux/bits.h>
+#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/module.h>
#include <linux/init.h>
@@ -219,36 +220,31 @@ static int ads1100_read_raw(struct iio_dev *indio_dev,
int ret;
struct ads1100_data *data = iio_priv(indio_dev);
- mutex_lock(&data->lock);
+ guard(mutex)(&data->lock);
switch (mask) {
case IIO_CHAN_INFO_RAW:
ret = iio_device_claim_direct_mode(indio_dev);
if (ret)
- break;
+ return ret;
ret = ads1100_get_adc_result(data, chan->address, val);
- if (ret >= 0)
- ret = IIO_VAL_INT;
iio_device_release_direct_mode(indio_dev);
- break;
+ if (ret < 0)
+ return ret;
+
+ return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
/* full-scale is the supply voltage in millivolts */
*val = ads1100_get_vdd_millivolts(data);
*val2 = 15 + FIELD_GET(ADS1100_PGA_MASK, data->config);
- ret = IIO_VAL_FRACTIONAL_LOG2;
- break;
+ return IIO_VAL_FRACTIONAL_LOG2;
case IIO_CHAN_INFO_SAMP_FREQ:
*val = ads1100_data_rate[FIELD_GET(ADS1100_DR_MASK,
data->config)];
- ret = IIO_VAL_INT;
- break;
+ return IIO_VAL_INT;
default:
- ret = -EINVAL;
- break;
+ return -EINVAL;
}
- mutex_unlock(&data->lock);
-
- return ret;
}
static int ads1100_write_raw(struct iio_dev *indio_dev,
@@ -256,23 +252,16 @@ static int ads1100_write_raw(struct iio_dev *indio_dev,
int val2, long mask)
{
struct ads1100_data *data = iio_priv(indio_dev);
- int ret;
- mutex_lock(&data->lock);
+ guard(mutex)(&data->lock);
switch (mask) {
case IIO_CHAN_INFO_SCALE:
- ret = ads1100_set_scale(data, val, val2);
- break;
+ return ads1100_set_scale(data, val, val2);
case IIO_CHAN_INFO_SAMP_FREQ:
- ret = ads1100_set_data_rate(data, chan->address, val);
- break;
+ return ads1100_set_data_rate(data, chan->address, val);
default:
- ret = -EINVAL;
- break;
+ return -EINVAL;
}
- mutex_unlock(&data->lock);
-
- return ret;
}
static const struct iio_info ads1100_info = {
--
2.48.1
next prev parent reply other threads:[~2025-03-09 16:58 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-09 16:58 [PATCH v2 0/8] IIO: ADCs: Sparse friendly claim of direct mode Jonathan Cameron
2025-03-09 16:58 ` [PATCH v2 1/8] iio: adc: vf610: Move claim of direct mode to caller of vf610_read_sample and use guard(mutex) Jonathan Cameron
2025-03-09 16:58 ` [PATCH v2 2/8] iio: adc: vf610: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
2025-03-09 16:58 ` Jonathan Cameron [this message]
2025-03-09 16:58 ` [PATCH v2 4/8] iio: adc: ti-ads1100: " Jonathan Cameron
2025-03-09 16:58 ` [PATCH v2 5/8] iio: adc: ti-ads1015: Use guard(mutex) and factor out code for INFO_RAW Jonathan Cameron
2025-03-10 23:18 ` David Lechner
2025-03-31 11:32 ` Jonathan Cameron
2025-03-09 16:58 ` [PATCH v2 6/8] iio: adc: ti-ads1015: Switch to sparse friendly iio_device_claim/release_direct() Jonathan Cameron
2025-03-09 16:58 ` [PATCH v2 7/8] iio: adc: mxs-lradc: " Jonathan Cameron
2025-03-09 16:58 ` [PATCH v2 8/8] iio: adc: rcar: " Jonathan Cameron
2025-03-10 23:21 ` [PATCH v2 0/8] IIO: ADCs: Sparse friendly claim of direct mode David Lechner
2025-03-31 11:33 ` 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=20250309165819.1346684-4-jic23@kernel.org \
--to=jic23@kernel.org \
--cc=Frank.Li@nxp.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=dlechner@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=marek.vasut+renesas@gmail.com \
--cc=marex@denx.de \
--cc=mike.looijmans@topic.nl \
--cc=noname.nuno@gmail.com \
--cc=nuno.sa@analog.com \
/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