summaryrefslogtreecommitdiff
path: root/drivers/iio
diff options
context:
space:
mode:
authorGabriel Schwartz <gschwartz@usp.br>2024-04-26 17:01:14 -0300
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2024-04-29 20:53:10 +0100
commit427298c632952709a33f3205d489ac496ae5b003 (patch)
treee68e643bd650797bad3cf3505e2991d909112e72 /drivers/iio
parent0d8d62640763edfc11cc8568fe2115ad5af4e67e (diff)
iio: adc: rtq6056: Use automated cleanup for mode handling in write_raw
Using iio_device_claim_direct_scoped() to automate mode claim and release simplifies code flow and allows for straight-forward error handling with direct returns on errors. Signed-off-by: Gabriel Schwartz <gschwartz@usp.br> Reviewed-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com> Reviewed-by: ChiYuan Huang <cy_huang@richtek.com> Link: https://lore.kernel.org/r/20240426200118.20900-1-gschwartz@usp.br Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/adc/rtq6056.c34
1 files changed, 11 insertions, 23 deletions
diff --git a/drivers/iio/adc/rtq6056.c b/drivers/iio/adc/rtq6056.c
index a5464737e527..bcb129840908 100644
--- a/drivers/iio/adc/rtq6056.c
+++ b/drivers/iio/adc/rtq6056.c
@@ -520,32 +520,20 @@ static int rtq6056_adc_write_raw(struct iio_dev *indio_dev,
{
struct rtq6056_priv *priv = iio_priv(indio_dev);
const struct richtek_dev_data *devdata = priv->devdata;
- int ret;
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
-
- switch (mask) {
- case IIO_CHAN_INFO_SAMP_FREQ:
- if (devdata->fixed_samp_freq) {
- ret = -EINVAL;
- break;
+ iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
+ switch (mask) {
+ case IIO_CHAN_INFO_SAMP_FREQ:
+ if (devdata->fixed_samp_freq)
+ return -EINVAL;
+ return rtq6056_adc_set_samp_freq(priv, chan, val);
+ case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
+ return devdata->set_average(priv, val);
+ default:
+ return -EINVAL;
}
-
- ret = rtq6056_adc_set_samp_freq(priv, chan, val);
- break;
- case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
- ret = devdata->set_average(priv, val);
- break;
- default:
- ret = -EINVAL;
- break;
}
-
- iio_device_release_direct_mode(indio_dev);
-
- return ret;
+ unreachable();
}
static const char *rtq6056_channel_labels[RTQ6056_MAX_CHANNEL] = {