Skip to content

Commit 81c6e2e

Browse files
committed
iio: amplifiers: ad8366: use cleanup.h mutex guard
use guard() from cleanup for mutex locking. replace mutex_init() for devm_mutex_init(). Signed-off-by: Rodrigo Alencar <[email protected]>
1 parent ffd1517 commit 81c6e2e

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

drivers/iio/amplifiers/ad8366.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* Copyright 2012-2025 Analog Devices Inc.
1818
*/
1919

20+
#include <linux/cleanup.h>
2021
#include <linux/device.h>
2122
#include <linux/kernel.h>
2223
#include <linux/slab.h>
@@ -53,7 +54,7 @@ struct ad8366_info {
5354
struct ad8366_state {
5455
struct spi_device *spi;
5556
struct regulator *reg;
56-
struct mutex lock; /* protect sensor state */
57+
struct mutex lock; /* protect sensor state */
5758
struct gpio_desc *reset_gpio;
5859
struct gpio_desc *enable_gpio;
5960
unsigned char ch[2];
@@ -164,7 +165,8 @@ static int ad8366_read_raw(struct iio_dev *indio_dev,
164165
int ret;
165166
int code, gain = 0;
166167

167-
mutex_lock(&st->lock);
168+
guard(mutex)(&st->lock);
169+
168170
switch (m) {
169171
case IIO_CHAN_INFO_HARDWAREGAIN:
170172
code = st->ch[chan->channel];
@@ -210,7 +212,6 @@ static int ad8366_read_raw(struct iio_dev *indio_dev,
210212
default:
211213
ret = -EINVAL;
212214
}
213-
mutex_unlock(&st->lock);
214215

215216
return ret;
216217
};
@@ -267,7 +268,8 @@ static int ad8366_write_raw(struct iio_dev *indio_dev,
267268
break;
268269
}
269270

270-
mutex_lock(&st->lock);
271+
guard(mutex)(&st->lock);
272+
271273
switch (mask) {
272274
case IIO_CHAN_INFO_HARDWAREGAIN:
273275
st->ch[chan->channel] = code;
@@ -276,7 +278,6 @@ static int ad8366_write_raw(struct iio_dev *indio_dev,
276278
default:
277279
ret = -EINVAL;
278280
}
279-
mutex_unlock(&st->lock);
280281

281282
return ret;
282283
}
@@ -323,7 +324,7 @@ static int ad8366_probe(struct spi_device *spi)
323324
int ret;
324325

325326
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
326-
if (indio_dev == NULL)
327+
if (!indio_dev)
327328
return -ENOMEM;
328329

329330
st = iio_priv(indio_dev);
@@ -336,10 +337,13 @@ static int ad8366_probe(struct spi_device *spi)
336337
}
337338

338339
spi_set_drvdata(spi, indio_dev);
339-
mutex_init(&st->lock);
340340
st->spi = spi;
341341
st->type = spi_get_device_id(spi)->driver_data;
342342

343+
ret = devm_mutex_init(&spi->dev, &st->lock);
344+
if (ret)
345+
return ret;
346+
343347
switch (st->type) {
344348
case ID_AD8366:
345349
indio_dev->channels = ad8366_channels;

0 commit comments

Comments
 (0)