Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Matti Vaittinen and committed by
Jonathan Cameron
944de7fc 804757a2

+7 -5
+7 -5
drivers/iio/adc/ti-adc128s052.c
··· 9 9 * https://www.ti.com/lit/ds/symlink/adc124s021.pdf 10 10 */ 11 11 12 + #include <linux/cleanup.h> 12 13 #include <linux/err.h> 13 14 #include <linux/iio/iio.h> 14 15 #include <linux/mod_devicetable.h> ··· 27 26 struct spi_device *spi; 28 27 29 28 struct regulator *reg; 29 + /* 30 + * Serialize the SPI 'write-channel + read data' accesses and protect 31 + * the shared buffer. 32 + */ 30 33 struct mutex lock; 31 34 32 35 union { ··· 43 38 { 44 39 int ret; 45 40 46 - mutex_lock(&adc->lock); 41 + guard(mutex)(&adc->lock); 47 42 48 43 adc->buffer[0] = channel << 3; 49 44 adc->buffer[1] = 0; 50 45 51 46 ret = spi_write(adc->spi, &adc->buffer, sizeof(adc->buffer)); 52 - if (ret < 0) { 53 - mutex_unlock(&adc->lock); 47 + if (ret < 0) 54 48 return ret; 55 - } 56 49 57 50 ret = spi_read(adc->spi, &adc->buffer16, sizeof(adc->buffer16)); 58 - mutex_unlock(&adc->lock); 59 51 if (ret < 0) 60 52 return ret; 61 53