Message ID | 20221004134909.1692021-6-nuno.sa@analog.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Make 'mlock' really private | expand |
On Tue, 4 Oct 2022 15:48:58 +0200 Nuno Sá <nuno.sa@analog.com> wrote: > 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: Nuno Sá <nuno.sa@analog.com> Applied > --- > drivers/iio/adc/ltc2497-core.c | 7 +++++-- > drivers/iio/adc/ltc2497.h | 2 ++ > 2 files changed, 7 insertions(+), 2 deletions(-) > > diff --git a/drivers/iio/adc/ltc2497-core.c b/drivers/iio/adc/ltc2497-core.c > index f52d37af4d1f..996f6cbbed3c 100644 > --- a/drivers/iio/adc/ltc2497-core.c > +++ b/drivers/iio/adc/ltc2497-core.c > @@ -10,6 +10,7 @@ > #include <linux/iio/iio.h> > #include <linux/iio/driver.h> > #include <linux/module.h> > +#include <linux/mutex.h> > #include <linux/regulator/consumer.h> > > #include "ltc2497.h" > @@ -81,9 +82,9 @@ static int ltc2497core_read_raw(struct iio_dev *indio_dev, > > switch (mask) { > case IIO_CHAN_INFO_RAW: > - mutex_lock(&indio_dev->mlock); > + mutex_lock(&ddata->lock); > ret = ltc2497core_read(ddata, chan->address, val); > - mutex_unlock(&indio_dev->mlock); > + mutex_unlock(&ddata->lock); > if (ret < 0) > return ret; > > @@ -214,6 +215,8 @@ int ltc2497core_probe(struct device *dev, struct iio_dev *indio_dev) > ddata->addr_prev = LTC2497_CONFIG_DEFAULT; > ddata->time_prev = ktime_get(); > > + mutex_init(&ddata->lock); > + > ret = iio_device_register(indio_dev); > if (ret < 0) > goto err_array_unregister; > diff --git a/drivers/iio/adc/ltc2497.h b/drivers/iio/adc/ltc2497.h > index e023de0d88c4..781519b52475 100644 > --- a/drivers/iio/adc/ltc2497.h > +++ b/drivers/iio/adc/ltc2497.h > @@ -12,6 +12,8 @@ struct ltc2497_chip_info { > struct ltc2497core_driverdata { > struct regulator *ref; > ktime_t time_prev; > + /* lock to protect against multiple access to the device */ > + struct mutex lock; > const struct ltc2497_chip_info *chip_info; > u8 addr_prev; > int (*result_and_measure)(struct ltc2497core_driverdata *ddata,
diff --git a/drivers/iio/adc/ltc2497-core.c b/drivers/iio/adc/ltc2497-core.c index f52d37af4d1f..996f6cbbed3c 100644 --- a/drivers/iio/adc/ltc2497-core.c +++ b/drivers/iio/adc/ltc2497-core.c @@ -10,6 +10,7 @@ #include <linux/iio/iio.h> #include <linux/iio/driver.h> #include <linux/module.h> +#include <linux/mutex.h> #include <linux/regulator/consumer.h> #include "ltc2497.h" @@ -81,9 +82,9 @@ static int ltc2497core_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - mutex_lock(&indio_dev->mlock); + mutex_lock(&ddata->lock); ret = ltc2497core_read(ddata, chan->address, val); - mutex_unlock(&indio_dev->mlock); + mutex_unlock(&ddata->lock); if (ret < 0) return ret; @@ -214,6 +215,8 @@ int ltc2497core_probe(struct device *dev, struct iio_dev *indio_dev) ddata->addr_prev = LTC2497_CONFIG_DEFAULT; ddata->time_prev = ktime_get(); + mutex_init(&ddata->lock); + ret = iio_device_register(indio_dev); if (ret < 0) goto err_array_unregister; diff --git a/drivers/iio/adc/ltc2497.h b/drivers/iio/adc/ltc2497.h index e023de0d88c4..781519b52475 100644 --- a/drivers/iio/adc/ltc2497.h +++ b/drivers/iio/adc/ltc2497.h @@ -12,6 +12,8 @@ struct ltc2497_chip_info { struct ltc2497core_driverdata { struct regulator *ref; ktime_t time_prev; + /* lock to protect against multiple access to the device */ + struct mutex lock; const struct ltc2497_chip_info *chip_info; u8 addr_prev; int (*result_and_measure)(struct ltc2497core_driverdata *ddata,
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: Nuno Sá <nuno.sa@analog.com> --- drivers/iio/adc/ltc2497-core.c | 7 +++++-- drivers/iio/adc/ltc2497.h | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-)