From: Jonathan Cameron <jic23@kernel.org> To: Brian Masney <masneyb@onstation.org>, linux-iio@vger.kernel.org Cc: devel@driverdev.osuosl.org, gregkh@linuxfoundation.org, lars@metafoo.de, pmeerw@pmeerw.net, knaack.h@gmx.de, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org, Mark.Rutland@arm.com Subject: Re: [PATCH 10/10] staging: iio: tsl2583: add locking to sysfs attributes Date: Sun, 30 Oct 2016 18:43:23 +0000 [thread overview] Message-ID: <8c1d39df-d9ff-95ca-570f-8b3a80375796@kernel.org> (raw) In-Reply-To: <1477648821-3786-11-git-send-email-masneyb@onstation.org> 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; > } > >
WARNING: multiple messages have this Message-ID (diff)
From: Jonathan Cameron <jic23@kernel.org> To: Brian Masney <masneyb@onstation.org>, linux-iio@vger.kernel.org Cc: devel@driverdev.osuosl.org, devicetree@vger.kernel.org, lars@metafoo.de, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, robh+dt@kernel.org, pmeerw@pmeerw.net, knaack.h@gmx.de, Mark.Rutland@arm.com Subject: Re: [PATCH 10/10] staging: iio: tsl2583: add locking to sysfs attributes Date: Sun, 30 Oct 2016 18:43:23 +0000 [thread overview] Message-ID: <8c1d39df-d9ff-95ca-570f-8b3a80375796@kernel.org> (raw) In-Reply-To: <1477648821-3786-11-git-send-email-masneyb@onstation.org> 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; > } > >
next prev parent reply other threads:[~2016-10-30 18:43 UTC|newest] Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-10-28 10:00 [PATCH 00/10] staging: iio: tsl2583: staging cleanups Brian Masney 2016-10-28 10:00 ` Brian Masney 2016-10-28 10:00 ` [PATCH 01/10] staging: iio: tsl2583: add of_match table for device tree support Brian Masney 2016-10-28 10:00 ` Brian Masney 2016-10-30 17:43 ` Jonathan Cameron 2016-10-30 17:43 ` Jonathan Cameron 2016-10-30 17:44 ` Jonathan Cameron 2016-10-30 17:44 ` Jonathan Cameron 2016-10-31 6:06 ` Rob Herring 2016-10-28 10:00 ` [PATCH 02/10] staging: iio: tsl2583: check for error code from i2c_smbus_read_byte() Brian Masney 2016-10-28 10:00 ` Brian Masney 2016-10-30 17:49 ` Jonathan Cameron 2016-10-30 17:49 ` Jonathan Cameron 2016-10-28 10:00 ` [PATCH 03/10] staging: iio: tsl2583: return proper error code instead of -1 Brian Masney 2016-10-28 10:00 ` Brian Masney 2016-10-30 17:50 ` Jonathan Cameron 2016-10-30 17:50 ` Jonathan Cameron 2016-10-28 10:00 ` [PATCH 04/10] staging: iio: tsl2583: remove redundant power_state sysfs attribute Brian Masney 2016-10-28 10:00 ` Brian Masney 2016-10-30 17:51 ` Jonathan Cameron 2016-10-30 17:51 ` Jonathan Cameron 2016-10-28 10:00 ` [PATCH 05/10] staging: iio: tsl2583: check return values from taos_chip_{on,off} Brian Masney 2016-10-28 10:00 ` [PATCH 05/10] staging: iio: tsl2583: check return values from taos_chip_{on, off} Brian Masney 2016-10-30 17:54 ` [PATCH 05/10] staging: iio: tsl2583: check return values from taos_chip_{on,off} Jonathan Cameron 2016-10-30 17:54 ` Jonathan Cameron 2016-10-28 10:00 ` [PATCH 06/10] staging: iio: tsl2583: convert to use iio_chan_spec and {read,write}_raw Brian Masney 2016-10-28 10:00 ` [PATCH 06/10] staging: iio: tsl2583: convert to use iio_chan_spec and {read, write}_raw Brian Masney 2016-10-30 18:04 ` [PATCH 06/10] staging: iio: tsl2583: convert to use iio_chan_spec and {read,write}_raw Jonathan Cameron 2016-10-30 18:04 ` Jonathan Cameron 2016-10-28 10:00 ` [PATCH 07/10] staging: iio: tsl2583: convert illuminance0_calibscale sysfs attr to use iio_chan_spec Brian Masney 2016-10-28 10:00 ` Brian Masney 2016-10-30 18:37 ` Jonathan Cameron 2016-10-30 18:37 ` Jonathan Cameron 2016-10-30 20:04 ` Brian Masney 2016-10-30 20:04 ` Brian Masney 2016-10-30 20:29 ` Jonathan Cameron 2016-10-30 20:29 ` Jonathan Cameron 2016-10-28 10:00 ` [PATCH 08/10] staging: iio: tsl2583: use IIO_*_ATTR* macros to create sysfs entries Brian Masney 2016-10-28 10:00 ` Brian Masney 2016-10-30 18:38 ` Jonathan Cameron 2016-10-30 18:38 ` Jonathan Cameron 2016-10-28 10:00 ` [PATCH 09/10] staging: iio: tsl2583: add error code to sysfs store functions Brian Masney 2016-10-28 10:00 ` Brian Masney 2016-10-30 18:39 ` Jonathan Cameron 2016-10-30 18:39 ` Jonathan Cameron 2016-10-28 10:00 ` [PATCH 10/10] staging: iio: tsl2583: add locking to sysfs attributes Brian Masney 2016-10-28 10:00 ` Brian Masney 2016-10-30 18:43 ` Jonathan Cameron [this message] 2016-10-30 18:43 ` Jonathan Cameron
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=8c1d39df-d9ff-95ca-570f-8b3a80375796@kernel.org \ --to=jic23@kernel.org \ --cc=Mark.Rutland@arm.com \ --cc=devel@driverdev.osuosl.org \ --cc=devicetree@vger.kernel.org \ --cc=gregkh@linuxfoundation.org \ --cc=knaack.h@gmx.de \ --cc=lars@metafoo.de \ --cc=linux-iio@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=masneyb@onstation.org \ --cc=pmeerw@pmeerw.net \ --cc=robh+dt@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.