diff options
| author | Matti Vaittinen <mazziesaccount@gmail.com> | 2025-04-07 14:36:35 +0300 |
|---|---|---|
| committer | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2025-04-22 19:10:03 +0100 |
| commit | 944de7fce763f6233a03fdc496630ae0e259015f (patch) | |
| tree | fbde6dcb4ae4ccc385996394bd7e5282a710f05e | |
| parent | 804757a221a9258eca90129aff4b136abe335446 (diff) | |
iio: adc: ti-adc128s052: Simplify using guard(mutex)
Error path in ADC reading function can be slighly simplified using the
guard(mutex).
Use guard(mutex) and document the mutex purpose.
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Link: https://patch.msgid.link/c4262cbf55748d505a74249d2bf46d7c3594d838.1744022065.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
| -rw-r--r-- | drivers/iio/adc/ti-adc128s052.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/drivers/iio/adc/ti-adc128s052.c b/drivers/iio/adc/ti-adc128s052.c index d90a5caa028f..fa0099356be7 100644 --- a/drivers/iio/adc/ti-adc128s052.c +++ b/drivers/iio/adc/ti-adc128s052.c @@ -9,6 +9,7 @@ * https://www.ti.com/lit/ds/symlink/adc124s021.pdf */ +#include <linux/cleanup.h> #include <linux/err.h> #include <linux/iio/iio.h> #include <linux/mod_devicetable.h> @@ -26,6 +27,10 @@ struct adc128 { struct spi_device *spi; struct regulator *reg; + /* + * Serialize the SPI 'write-channel + read data' accesses and protect + * the shared buffer. + */ struct mutex lock; union { @@ -38,19 +43,16 @@ static int adc128_adc_conversion(struct adc128 *adc, u8 channel) { int ret; - mutex_lock(&adc->lock); + guard(mutex)(&adc->lock); adc->buffer[0] = channel << 3; adc->buffer[1] = 0; ret = spi_write(adc->spi, &adc->buffer, sizeof(adc->buffer)); - if (ret < 0) { - mutex_unlock(&adc->lock); + if (ret < 0) return ret; - } ret = spi_read(adc->spi, &adc->buffer16, sizeof(adc->buffer16)); - mutex_unlock(&adc->lock); if (ret < 0) return ret; |
