Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] iio: gyro: adis16080: replace mlock with own lock
@ 2019-09-19 13:23 Alexandru Ardelean
  2019-10-05 14:55 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandru Ardelean @ 2019-09-19 13:23 UTC (permalink / raw)
  To: linux-iio; +Cc: Alexandru Ardelean

The lock is used to protect the buffer during reads. Though the spi
routines have their own locks, it may be the case that the buffer needs to
be protected before it's stored and passed to the IIO read hooks.

indio_dev's mlock was used before.
This change replaces it with the driver's own lock.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/gyro/adis16080.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/gyro/adis16080.c b/drivers/iio/gyro/adis16080.c
index 236220d6de02..1b84b8e112fe 100644
--- a/drivers/iio/gyro/adis16080.c
+++ b/drivers/iio/gyro/adis16080.c
@@ -38,10 +38,12 @@ struct adis16080_chip_info {
  * @us:			actual spi_device to write data
  * @info:		chip specific parameters
  * @buf:		transmit or receive buffer
+ * @lock		lock to protect buffer during reads
  **/
 struct adis16080_state {
 	struct spi_device		*us;
 	const struct adis16080_chip_info *info;
+	struct mutex			lock;
 
 	__be16 buf ____cacheline_aligned;
 };
@@ -82,9 +84,9 @@ static int adis16080_read_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		mutex_lock(&indio_dev->mlock);
+		mutex_lock(&st->lock);
 		ret = adis16080_read_sample(indio_dev, chan->address, val);
-		mutex_unlock(&indio_dev->mlock);
+		mutex_unlock(&st->lock);
 		return ret ? ret : IIO_VAL_INT;
 	case IIO_CHAN_INFO_SCALE:
 		switch (chan->type) {
@@ -196,6 +198,8 @@ static int adis16080_probe(struct spi_device *spi)
 	/* this is only used for removal purposes */
 	spi_set_drvdata(spi, indio_dev);
 
+	mutex_init(&st->lock);
+
 	/* Allocate the comms buffers */
 	st->us = spi;
 	st->info = &adis16080_chip_info[id->driver_data];
-- 
2.20.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] iio: gyro: adis16080: replace mlock with own lock
  2019-09-19 13:23 [PATCH] iio: gyro: adis16080: replace mlock with own lock Alexandru Ardelean
@ 2019-10-05 14:55 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2019-10-05 14:55 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-iio

On Thu, 19 Sep 2019 16:23:03 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> The lock is used to protect the buffer during reads. Though the spi
> routines have their own locks, it may be the case that the buffer needs to
> be protected before it's stored and passed to the IIO read hooks.
> 
> indio_dev's mlock was used before.
> This change replaces it with the driver's own lock.
> 
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to poke holes in it.

Thanks,

Jonathan

> ---
>  drivers/iio/gyro/adis16080.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/gyro/adis16080.c b/drivers/iio/gyro/adis16080.c
> index 236220d6de02..1b84b8e112fe 100644
> --- a/drivers/iio/gyro/adis16080.c
> +++ b/drivers/iio/gyro/adis16080.c
> @@ -38,10 +38,12 @@ struct adis16080_chip_info {
>   * @us:			actual spi_device to write data
>   * @info:		chip specific parameters
>   * @buf:		transmit or receive buffer
> + * @lock		lock to protect buffer during reads
>   **/
>  struct adis16080_state {
>  	struct spi_device		*us;
>  	const struct adis16080_chip_info *info;
> +	struct mutex			lock;
>  
>  	__be16 buf ____cacheline_aligned;
>  };
> @@ -82,9 +84,9 @@ static int adis16080_read_raw(struct iio_dev *indio_dev,
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_RAW:
> -		mutex_lock(&indio_dev->mlock);
> +		mutex_lock(&st->lock);
>  		ret = adis16080_read_sample(indio_dev, chan->address, val);
> -		mutex_unlock(&indio_dev->mlock);
> +		mutex_unlock(&st->lock);
>  		return ret ? ret : IIO_VAL_INT;
>  	case IIO_CHAN_INFO_SCALE:
>  		switch (chan->type) {
> @@ -196,6 +198,8 @@ static int adis16080_probe(struct spi_device *spi)
>  	/* this is only used for removal purposes */
>  	spi_set_drvdata(spi, indio_dev);
>  
> +	mutex_init(&st->lock);
> +
>  	/* Allocate the comms buffers */
>  	st->us = spi;
>  	st->info = &adis16080_chip_info[id->driver_data];


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-19 13:23 [PATCH] iio: gyro: adis16080: replace mlock with own lock Alexandru Ardelean
2019-10-05 14:55 ` Jonathan Cameron

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org linux-iio@archiver.kernel.org
	public-inbox-index linux-iio

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/ public-inbox