Commit d305b7f3 authored by Nuno Sa's avatar Nuno Sa Committed by Jonathan Cameron

iio: imu: adis: move to the cleanup magic

This makes locking and handling error paths simpler.
Signed-off-by: default avatarNuno Sa <nuno.sa@analog.com>
Link: https://patch.msgid.link/20240618-dev-iio-adis-cleanup-v1-2-bd93ce7845c7@analog.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent d80d4a3c
...@@ -466,17 +466,17 @@ int adis_single_conversion(struct iio_dev *indio_dev, ...@@ -466,17 +466,17 @@ int adis_single_conversion(struct iio_dev *indio_dev,
unsigned int uval; unsigned int uval;
int ret; int ret;
mutex_lock(&adis->state_lock); guard(mutex)(&adis->state_lock);
ret = __adis_read_reg(adis, chan->address, &uval, ret = __adis_read_reg(adis, chan->address, &uval,
chan->scan_type.storagebits / 8); chan->scan_type.storagebits / 8);
if (ret) if (ret)
goto err_unlock; return ret;
if (uval & error_mask) { if (uval & error_mask) {
ret = __adis_check_status(adis); ret = __adis_check_status(adis);
if (ret) if (ret)
goto err_unlock; return ret;
} }
if (chan->scan_type.sign == 's') if (chan->scan_type.sign == 's')
...@@ -484,10 +484,7 @@ int adis_single_conversion(struct iio_dev *indio_dev, ...@@ -484,10 +484,7 @@ int adis_single_conversion(struct iio_dev *indio_dev,
else else
*val = uval & ((1 << chan->scan_type.realbits) - 1); *val = uval & ((1 << chan->scan_type.realbits) - 1);
ret = IIO_VAL_INT; return IIO_VAL_INT;
err_unlock:
mutex_unlock(&adis->state_lock);
return ret;
} }
EXPORT_SYMBOL_NS_GPL(adis_single_conversion, IIO_ADISLIB); EXPORT_SYMBOL_NS_GPL(adis_single_conversion, IIO_ADISLIB);
......
...@@ -130,24 +130,20 @@ static int adis_paging_trigger_handler(struct adis *adis) ...@@ -130,24 +130,20 @@ static int adis_paging_trigger_handler(struct adis *adis)
{ {
int ret; int ret;
mutex_lock(&adis->state_lock); guard(mutex)(&adis->state_lock);
if (adis->current_page != 0) { if (adis->current_page != 0) {
adis->tx[0] = ADIS_WRITE_REG(ADIS_REG_PAGE_ID); adis->tx[0] = ADIS_WRITE_REG(ADIS_REG_PAGE_ID);
adis->tx[1] = 0; adis->tx[1] = 0;
ret = spi_write(adis->spi, adis->tx, 2); ret = spi_write(adis->spi, adis->tx, 2);
if (ret) { if (ret) {
dev_err(&adis->spi->dev, "Failed to change device page: %d\n", ret); dev_err(&adis->spi->dev, "Failed to change device page: %d\n", ret);
mutex_unlock(&adis->state_lock);
return ret; return ret;
} }
adis->current_page = 0; adis->current_page = 0;
} }
ret = spi_sync(adis->spi, &adis->msg); return spi_sync(adis->spi, &adis->msg);
mutex_unlock(&adis->state_lock);
return ret;
} }
static irqreturn_t adis_trigger_handler(int irq, void *p) static irqreturn_t adis_trigger_handler(int irq, void *p)
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#ifndef __IIO_ADIS_H__ #ifndef __IIO_ADIS_H__
#define __IIO_ADIS_H__ #define __IIO_ADIS_H__
#include <linux/cleanup.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
...@@ -150,13 +151,8 @@ int __adis_reset(struct adis *adis); ...@@ -150,13 +151,8 @@ int __adis_reset(struct adis *adis);
*/ */
static inline int adis_reset(struct adis *adis) static inline int adis_reset(struct adis *adis)
{ {
int ret; guard(mutex)(&adis->state_lock);
return __adis_reset(adis);
mutex_lock(&adis->state_lock);
ret = __adis_reset(adis);
mutex_unlock(&adis->state_lock);
return ret;
} }
int __adis_write_reg(struct adis *adis, unsigned int reg, int __adis_write_reg(struct adis *adis, unsigned int reg,
...@@ -248,13 +244,8 @@ static inline int __adis_read_reg_32(struct adis *adis, unsigned int reg, ...@@ -248,13 +244,8 @@ static inline int __adis_read_reg_32(struct adis *adis, unsigned int reg,
static inline int adis_write_reg(struct adis *adis, unsigned int reg, static inline int adis_write_reg(struct adis *adis, unsigned int reg,
unsigned int val, unsigned int size) unsigned int val, unsigned int size)
{ {
int ret; guard(mutex)(&adis->state_lock);
return __adis_write_reg(adis, reg, val, size);
mutex_lock(&adis->state_lock);
ret = __adis_write_reg(adis, reg, val, size);
mutex_unlock(&adis->state_lock);
return ret;
} }
/** /**
...@@ -267,13 +258,8 @@ static inline int adis_write_reg(struct adis *adis, unsigned int reg, ...@@ -267,13 +258,8 @@ static inline int adis_write_reg(struct adis *adis, unsigned int reg,
static int adis_read_reg(struct adis *adis, unsigned int reg, static int adis_read_reg(struct adis *adis, unsigned int reg,
unsigned int *val, unsigned int size) unsigned int *val, unsigned int size)
{ {
int ret; guard(mutex)(&adis->state_lock);
return __adis_read_reg(adis, reg, val, size);
mutex_lock(&adis->state_lock);
ret = __adis_read_reg(adis, reg, val, size);
mutex_unlock(&adis->state_lock);
return ret;
} }
/** /**
...@@ -365,12 +351,8 @@ int __adis_update_bits_base(struct adis *adis, unsigned int reg, const u32 mask, ...@@ -365,12 +351,8 @@ int __adis_update_bits_base(struct adis *adis, unsigned int reg, const u32 mask,
static inline int adis_update_bits_base(struct adis *adis, unsigned int reg, static inline int adis_update_bits_base(struct adis *adis, unsigned int reg,
const u32 mask, const u32 val, u8 size) const u32 mask, const u32 val, u8 size)
{ {
int ret; guard(mutex)(&adis->state_lock);
return __adis_update_bits_base(adis, reg, mask, val, size);
mutex_lock(&adis->state_lock);
ret = __adis_update_bits_base(adis, reg, mask, val, size);
mutex_unlock(&adis->state_lock);
return ret;
} }
/** /**
...@@ -411,24 +393,14 @@ int __adis_enable_irq(struct adis *adis, bool enable); ...@@ -411,24 +393,14 @@ int __adis_enable_irq(struct adis *adis, bool enable);
static inline int adis_enable_irq(struct adis *adis, bool enable) static inline int adis_enable_irq(struct adis *adis, bool enable)
{ {
int ret; guard(mutex)(&adis->state_lock);
return __adis_enable_irq(adis, enable);
mutex_lock(&adis->state_lock);
ret = __adis_enable_irq(adis, enable);
mutex_unlock(&adis->state_lock);
return ret;
} }
static inline int adis_check_status(struct adis *adis) static inline int adis_check_status(struct adis *adis)
{ {
int ret; guard(mutex)(&adis->state_lock);
return __adis_check_status(adis);
mutex_lock(&adis->state_lock);
ret = __adis_check_status(adis);
mutex_unlock(&adis->state_lock);
return ret;
} }
static inline void adis_dev_lock(struct adis *adis) static inline void adis_dev_lock(struct adis *adis)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment