Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1511024 > unrolled thread
| Started by | Brian Masney <masneyb@onstation.org> |
|---|---|
| First post | 2016-10-28 12:10 +0200 |
| Last post | 2016-10-30 19:50 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 10/10] staging: iio: tsl2583: add locking to sysfs attributes Brian Masney <masneyb@onstation.org> - 2016-10-28 12:10 +0200
Re: [PATCH 10/10] staging: iio: tsl2583: add locking to sysfs attributes Jonathan Cameron <jic23@kernel.org> - 2016-10-30 19:50 +0100
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-10-28 12:10 +0200 |
| Subject | [PATCH 10/10] staging: iio: tsl2583: add locking to sysfs attributes |
| Message-ID | <sxcgO-6SN-17@gated-at.bofh.it> |
in_illuminance_input_target_show(), in_illuminance_input_target_store(),
in_illuminance_calibrate_store(), and in_illuminance_lux_table_store()
accesses data from the tsl2583_chip struct. Some of these fields can be
modified by other parts of the driver concurrently. This patch adds the
mutex locking to these sysfs attributes.
Signed-off-by: Brian Masney <masneyb@onstation.org>
---
drivers/staging/iio/light/tsl2583.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 98afa5b..49b19f5 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -513,8 +513,13 @@ static ssize_t in_illuminance_input_target_show(struct device *dev,
{
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct tsl2583_chip *chip = iio_priv(indio_dev);
+ int ret;
+
+ mutex_lock(&chip->als_mutex);
+ ret = sprintf(buf, "%d\n", chip->taos_settings.als_cal_target);
+ mutex_unlock(&chip->als_mutex);
- return sprintf(buf, "%d\n", chip->taos_settings.als_cal_target);
+ return ret;
}
static ssize_t in_illuminance_input_target_store(struct device *dev,
@@ -528,7 +533,9 @@ static ssize_t in_illuminance_input_target_store(struct device *dev,
if (kstrtoint(buf, 0, &value) || !value)
return -EINVAL;
+ mutex_lock(&chip->als_mutex);
chip->taos_settings.als_cal_target = value;
+ mutex_unlock(&chip->als_mutex);
return len;
}
@@ -538,12 +545,15 @@ static ssize_t in_illuminance_calibrate_store(struct device *dev,
const char *buf, size_t len)
{
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+ struct tsl2583_chip *chip = iio_priv(indio_dev);
int value;
if (kstrtoint(buf, 0, &value) || value != 1)
return -EINVAL;
+ mutex_lock(&chip->als_mutex);
taos_als_calibrate(indio_dev);
+ mutex_unlock(&chip->als_mutex);
return len;
}
@@ -583,6 +593,8 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
int value[ARRAY_SIZE(taos_device_lux) * 3 + 1];
int n, ret = -EINVAL;
+ mutex_lock(&chip->als_mutex);
+
get_options(buf, ARRAY_SIZE(value), value);
/* We now have an array of ints starting at value[1], and
@@ -617,6 +629,8 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
ret = len;
done:
+ mutex_unlock(&chip->als_mutex);
+
return ret;
}
--
2.7.4
[toc] | [next] | [standalone]
| From | Jonathan Cameron <jic23@kernel.org> |
|---|---|
| Date | 2016-10-30 19:50 +0100 |
| Subject | Re: [PATCH 10/10] staging: iio: tsl2583: add locking to sysfs attributes |
| Message-ID | <sy3l8-8lp-15@gated-at.bofh.it> |
| In reply to | #1511024 |
On 28/10/16 11:00, Brian Masney wrote:
> in_illuminance_input_target_show(), in_illuminance_input_target_store(),
> in_illuminance_calibrate_store(), and in_illuminance_lux_table_store()
> accesses data from the tsl2583_chip struct. Some of these fields can be
> modified by other parts of the driver concurrently. This patch adds the
> mutex locking to these sysfs attributes.
>
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied to the togreg branch of iio.git and pushed out as testing for the
autobuilders to play with it.
Some elements of this were probably a little over paranoid but in theory
you might get a wrong reading (compared to what the hardware is set to) so
fair enough.
Good patch set.
Thanks,
Jonathan
> ---
> drivers/staging/iio/light/tsl2583.c | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> index 98afa5b..49b19f5 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -513,8 +513,13 @@ static ssize_t in_illuminance_input_target_show(struct device *dev,
> {
> struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> struct tsl2583_chip *chip = iio_priv(indio_dev);
> + int ret;
> +
> + mutex_lock(&chip->als_mutex);
> + ret = sprintf(buf, "%d\n", chip->taos_settings.als_cal_target);
> + mutex_unlock(&chip->als_mutex);
>
> - return sprintf(buf, "%d\n", chip->taos_settings.als_cal_target);
> + return ret;
> }
>
> static ssize_t in_illuminance_input_target_store(struct device *dev,
> @@ -528,7 +533,9 @@ static ssize_t in_illuminance_input_target_store(struct device *dev,
> if (kstrtoint(buf, 0, &value) || !value)
> return -EINVAL;
>
> + mutex_lock(&chip->als_mutex);
> chip->taos_settings.als_cal_target = value;
> + mutex_unlock(&chip->als_mutex);
>
> return len;
> }
> @@ -538,12 +545,15 @@ static ssize_t in_illuminance_calibrate_store(struct device *dev,
> const char *buf, size_t len)
> {
> struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> + struct tsl2583_chip *chip = iio_priv(indio_dev);
> int value;
>
> if (kstrtoint(buf, 0, &value) || value != 1)
> return -EINVAL;
>
> + mutex_lock(&chip->als_mutex);
> taos_als_calibrate(indio_dev);
> + mutex_unlock(&chip->als_mutex);
>
> return len;
> }
> @@ -583,6 +593,8 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
> int value[ARRAY_SIZE(taos_device_lux) * 3 + 1];
> int n, ret = -EINVAL;
>
> + mutex_lock(&chip->als_mutex);
> +
> get_options(buf, ARRAY_SIZE(value), value);
>
> /* We now have an array of ints starting at value[1], and
> @@ -617,6 +629,8 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
> ret = len;
>
> done:
> + mutex_unlock(&chip->als_mutex);
> +
> return ret;
> }
>
>
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web