All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guoqing Chi <chi962464zy@163.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Tom Rix <trix@redhat.com>,
	martin.blumenstingl@googlemail.com, linux-kernel@vger.kernel.org,
	chiguoqing@yulong.com, huyue2@yulong.com, zhangwen@yulong.com,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH v2] iio: imu: bmi160: add mutex_lock for avoiding race
Date: Tue, 26 Jan 2021 10:58:54 +0800	[thread overview]
Message-ID: <20210126105854.0000192d@163.com> (raw)
In-Reply-To: <20210123152659.563cddeb@archlinux>

On Sat, 23 Jan 2021 15:26:59 +0000
Jonathan Cameron <jic23@kernel.org> wrote:

> On Wed, 20 Jan 2021 07:06:23 -0800
> Tom Rix <trix@redhat.com> wrote:
> 
> > On 1/19/21 5:48 PM, Guoqing Chi wrote:  
> > > On Tue, 19 Jan 2021 06:54:45 -0800
> > > Tom Rix <trix@redhat.com> wrote:
> > >    
> > >> On 1/19/21 3:22 AM, Guoqing Chi wrote:    
> > >>> From: chiguoqing <chi962464zy@163.com>
> > >>>
> > >>> Adding mutex_lock, when read and write reg need to use this
> > >>> lock to avoid race.
> > >>>
> > >>> Signed-off-by: Guoqing Chi <chiguoqing@yulong.com>
> > >>> ---
> > >>> v2:Follow write function to fix read function.
> > >>> Adding mutex init in core probe function.
> > >>> Adding break in switch case at read and write function.
> > >>>
> > >>>  drivers/iio/imu/bmi160/bmi160.h      |  2 ++
> > >>>  drivers/iio/imu/bmi160/bmi160_core.c | 34
> > >>> +++++++++++++++++++--------- 2 files changed, 25 insertions(+),
> > >>> 11 deletions(-)
> > >>>
> > >>> diff --git a/drivers/iio/imu/bmi160/bmi160.h
> > >>> b/drivers/iio/imu/bmi160/bmi160.h index
> > >>> 32c2ea2d7112..0c189a8b5b53 100644 ---
> > >>> a/drivers/iio/imu/bmi160/bmi160.h +++
> > >>> b/drivers/iio/imu/bmi160/bmi160.h @@ -3,9 +3,11 @@
> > >>>  #define BMI160_H_
> > >>>  
> > >>>  #include <linux/iio/iio.h>
> > >>> +#include <linux/mutex.h>
> > >>>  #include <linux/regulator/consumer.h>
> > >>>  
> > >>>  struct bmi160_data {
> > >>> +	struct mutex lock;
> > >>>  	struct regmap *regmap;
> > >>>  	struct iio_trigger *trig;
> > >>>  	struct regulator_bulk_data supplies[2];
> > >>> diff --git a/drivers/iio/imu/bmi160/bmi160_core.c
> > >>> b/drivers/iio/imu/bmi160/bmi160_core.c index
> > >>> 290b5ef83f77..e303378f4841 100644 ---
> > >>> a/drivers/iio/imu/bmi160/bmi160_core.c +++
> > >>> b/drivers/iio/imu/bmi160/bmi160_core.c @@ -452,26 +452,32 @@
> > >>> static int bmi160_read_raw(struct iio_dev *indio_dev, int ret;
> > >>>  	struct bmi160_data *data = iio_priv(indio_dev);
> > >>>  
> > >>> +	mutex_lock(&data->lock);
> > >>>  	switch (mask) {
> > >>>  	case IIO_CHAN_INFO_RAW:
> > >>>  		ret = bmi160_get_data(data, chan->type,
> > >>> chan->channel2, val);
> > >>> -		if (ret)
> > >>> -			return ret;
> > >>> -		return IIO_VAL_INT;
> > >>> +		if (!ret)
> > >>> +			ret = IIO_VAL_INT;
> > >>> +		break;
> > >>>  	case IIO_CHAN_INFO_SCALE:
> > >>>  		*val = 0;
> > >>>  		ret = bmi160_get_scale(data,
> > >>>  				       bmi160_to_sensor(chan->type),
> > >>> val2);
> > >>> -		return ret ? ret : IIO_VAL_INT_PLUS_MICRO;
> > >>> +		if (!ret)
> > >>> +			ret = IIO_VAL_INT_PLUS_MICRO;      
> > >> Looking better, another question..
> > >>
> > >> Why does the write() function return the results directly while
> > >> the read() function
> > >>
> > >> translates them to other values ?
> > >>
> > >> Tom    
> > > It is original design in this driver. In order to
> > > differentiate raw to scale and SAMP_FREQ, while the scale and
> > > SAMP_FREQ are needless. I think log information can be added for
> > > this purpose, and return results directly.
> > > It is not change the return values for my modify.It's best to
> > > keep the original design.Is that all right?    
> > 
> > Ok.
> > 
> > Reviewed-by: Tom Rix <trix@redhat.com>  
> 
> Hi Guoqing Chi,
> 
> For some reason the original patch email (start of this thread) never
> made it to my inbox or indeed the archive at lore.kernel.org.
> 
> Please resend (picking up Tom's reviewed by) and make sure to cc
> linux-iio@vger.kernel.org + jic23@kernel.org
> 
> Then check if they make it to lore.kernel.org as that should highlight
> any issues where it is getting blocked etc.
> 
> Thanks,
> 
> Jonathan

Hi Jonathan,

I have resend patch V2(picking up Tom's reviewed by) for add
linux-iio@vger.kernel.org + jic23@kernel.org.

Thanks.

> 
> >   
> > > Guoqing Chi    
> > >>> +		break;
> > >>>  	case IIO_CHAN_INFO_SAMP_FREQ:
> > >>>  		ret = bmi160_get_odr(data,
> > >>> bmi160_to_sensor(chan->type), val, val2);
> > >>> -		return ret ? ret : IIO_VAL_INT_PLUS_MICRO;
> > >>> +		if (!ret)
> > >>> +			ret = IIO_VAL_INT_PLUS_MICRO;
> > >>> +		break;
> > >>>  	default:
> > >>> -		return -EINVAL;
> > >>> +		ret = -EINVAL;
> > >>>  	}
> > >>> +	mutex_unlock(&data->lock);
> > >>>  
> > >>> -	return 0;
> > >>> +	return ret;
> > >>>  }
> > >>>  
> > >>>  static int bmi160_write_raw(struct iio_dev *indio_dev,
> > >>> @@ -479,19 +485,24 @@ static int bmi160_write_raw(struct iio_dev
> > >>> *indio_dev, int val, int val2, long mask)
> > >>>  {
> > >>>  	struct bmi160_data *data = iio_priv(indio_dev);
> > >>> +	int result;
> > >>>  
> > >>> +	mutex_lock(&data->lock);
> > >>>  	switch (mask) {
> > >>>  	case IIO_CHAN_INFO_SCALE:
> > >>> -		return bmi160_set_scale(data,
> > >>> +		result = bmi160_set_scale(data,
> > >>>  					bmi160_to_sensor(chan->type),
> > >>> val2);
> > >>> +		break;
> > >>>  	case IIO_CHAN_INFO_SAMP_FREQ:
> > >>> -		return bmi160_set_odr(data,
> > >>> bmi160_to_sensor(chan->type),
> > >>> +		result = bmi160_set_odr(data,
> > >>> bmi160_to_sensor(chan->type), val, val2);
> > >>> +		break;
> > >>>  	default:
> > >>> -		return -EINVAL;
> > >>> +		result = -EINVAL;
> > >>>  	}
> > >>> +	mutex_unlock(&data->lock);
> > >>>  
> > >>> -	return 0;
> > >>> +	return result;
> > >>>  }
> > >>>  
> > >>>  static
> > >>> @@ -838,6 +849,7 @@ int bmi160_core_probe(struct device *dev,
> > >>> struct regmap *regmap, return -ENOMEM;
> > >>>  
> > >>>  	data = iio_priv(indio_dev);
> > >>> +	mutex_init(&data->lock);
> > >>>  	dev_set_drvdata(dev, indio_dev);
> > >>>  	data->regmap = regmap;
> > >>>        
> >   


      reply	other threads:[~2021-01-26  5:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210119112211.26404-1-chi962464zy@163.com>
2021-01-19 14:54 ` [PATCH v2] iio: imu: bmi160: add mutex_lock for avoiding race Tom Rix
2021-01-20  1:48   ` Guoqing Chi
2021-01-20 15:06     ` Tom Rix
2021-01-23 15:26       ` Jonathan Cameron
2021-01-26  2:58         ` Guoqing Chi [this message]

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=20210126105854.0000192d@163.com \
    --to=chi962464zy@163.com \
    --cc=chiguoqing@yulong.com \
    --cc=huyue2@yulong.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=trix@redhat.com \
    --cc=zhangwen@yulong.com \
    /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: link
Be 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.