Commit 3cc36cab authored by Nuno Sá's avatar Nuno Sá Committed by Jonathan Cameron

iio: gyro: itg3200_core: do not use internal iio_dev lock

The iio_device lock is only meant for internal use. Hence define a
device local lock to protect against concurrent accesses.

While at it, properly include "mutex.h" for mutex related APIs.
Signed-off-by: default avatarNuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20221004134909.1692021-13-nuno.sa@analog.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent d711a5a7
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/stat.h> #include <linux/stat.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/mutex.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
...@@ -131,6 +132,7 @@ static int itg3200_write_raw(struct iio_dev *indio_dev, ...@@ -131,6 +132,7 @@ static int itg3200_write_raw(struct iio_dev *indio_dev,
int val2, int val2,
long mask) long mask)
{ {
struct itg3200 *st = iio_priv(indio_dev);
int ret; int ret;
u8 t; u8 t;
...@@ -139,11 +141,11 @@ static int itg3200_write_raw(struct iio_dev *indio_dev, ...@@ -139,11 +141,11 @@ static int itg3200_write_raw(struct iio_dev *indio_dev,
if (val == 0 || val2 != 0) if (val == 0 || val2 != 0)
return -EINVAL; return -EINVAL;
mutex_lock(&indio_dev->mlock); mutex_lock(&st->lock);
ret = itg3200_read_reg_8(indio_dev, ITG3200_REG_DLPF, &t); ret = itg3200_read_reg_8(indio_dev, ITG3200_REG_DLPF, &t);
if (ret) { if (ret) {
mutex_unlock(&indio_dev->mlock); mutex_unlock(&st->lock);
return ret; return ret;
} }
t = ((t & ITG3200_DLPF_CFG_MASK) ? 1000u : 8000u) / val - 1; t = ((t & ITG3200_DLPF_CFG_MASK) ? 1000u : 8000u) / val - 1;
...@@ -152,7 +154,7 @@ static int itg3200_write_raw(struct iio_dev *indio_dev, ...@@ -152,7 +154,7 @@ static int itg3200_write_raw(struct iio_dev *indio_dev,
ITG3200_REG_SAMPLE_RATE_DIV, ITG3200_REG_SAMPLE_RATE_DIV,
t); t);
mutex_unlock(&indio_dev->mlock); mutex_unlock(&st->lock);
return ret; return ret;
default: default:
...@@ -336,6 +338,8 @@ static int itg3200_probe(struct i2c_client *client, ...@@ -336,6 +338,8 @@ static int itg3200_probe(struct i2c_client *client,
if (ret) if (ret)
goto error_remove_trigger; goto error_remove_trigger;
mutex_init(&st->lock);
ret = iio_device_register(indio_dev); ret = iio_device_register(indio_dev);
if (ret) if (ret)
goto error_remove_trigger; goto error_remove_trigger;
......
...@@ -102,6 +102,8 @@ struct itg3200 { ...@@ -102,6 +102,8 @@ struct itg3200 {
struct i2c_client *i2c; struct i2c_client *i2c;
struct iio_trigger *trig; struct iio_trigger *trig;
struct iio_mount_matrix orientation; struct iio_mount_matrix orientation;
/* lock to protect against multiple access to the device */
struct mutex lock;
}; };
enum ITG3200_SCAN_INDEX { enum ITG3200_SCAN_INDEX {
......
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