mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-01 02:33:57 +00:00
iio: common: scmi_iio: 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: Nuno Sá <nuno.sa@analog.com> Link: https://lore.kernel.org/r/20221004134909.1692021-12-nuno.sa@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
4e15cad8db
commit
d711a5a7ef
@ -15,6 +15,7 @@
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/kthread.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/scmi_protocol.h>
|
||||
#include <linux/time.h>
|
||||
#include <linux/types.h>
|
||||
@ -27,6 +28,8 @@ struct scmi_iio_priv {
|
||||
struct scmi_protocol_handle *ph;
|
||||
const struct scmi_sensor_info *sensor_info;
|
||||
struct iio_dev *indio_dev;
|
||||
/* lock to protect against multiple access to the device */
|
||||
struct mutex lock;
|
||||
/* adding one additional channel for timestamp */
|
||||
s64 iio_buf[SCMI_IIO_NUM_OF_AXIS + 1];
|
||||
struct notifier_block sensor_update_nb;
|
||||
@ -198,13 +201,14 @@ static int scmi_iio_write_raw(struct iio_dev *iio_dev,
|
||||
struct iio_chan_spec const *chan, int val,
|
||||
int val2, long mask)
|
||||
{
|
||||
struct scmi_iio_priv *sensor = iio_priv(iio_dev);
|
||||
int err;
|
||||
|
||||
switch (mask) {
|
||||
case IIO_CHAN_INFO_SAMP_FREQ:
|
||||
mutex_lock(&iio_dev->mlock);
|
||||
mutex_lock(&sensor->lock);
|
||||
err = scmi_iio_set_odr_val(iio_dev, val, val2);
|
||||
mutex_unlock(&iio_dev->mlock);
|
||||
mutex_unlock(&sensor->lock);
|
||||
return err;
|
||||
default:
|
||||
return -EINVAL;
|
||||
@ -586,6 +590,7 @@ scmi_alloc_iiodev(struct scmi_device *sdev,
|
||||
sensor->sensor_info = sensor_info;
|
||||
sensor->sensor_update_nb.notifier_call = scmi_iio_sensor_update_cb;
|
||||
sensor->indio_dev = iiodev;
|
||||
mutex_init(&sensor->lock);
|
||||
|
||||
/* adding one additional channel for timestamp */
|
||||
iiodev->num_channels = sensor_info->num_axis + 1;
|
||||
|
Loading…
Reference in New Issue
Block a user