linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: hi8435: fix race between event enable and event generation
@ 2017-05-23  8:07 Nikita Yushchenko
  2017-05-24 19:30 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Nikita Yushchenko @ 2017-05-23  8:07 UTC (permalink / raw)
  To: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Sanchayan Maity, Gregor Boirie,
	Matt Ranostay
  Cc: linux-iio, linux-kernel, Chris Healy, Jeff White,
	Vladimir Barinov, Nikita Yushchenko

Add locking to avoid interference between reading/processing current
sence in event enable and event generation paths.

Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
---
 drivers/iio/adc/hi8435.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/iio/adc/hi8435.c b/drivers/iio/adc/hi8435.c
index ab59969b7c49..28fc699f00f6 100644
--- a/drivers/iio/adc/hi8435.c
+++ b/drivers/iio/adc/hi8435.c
@@ -144,6 +144,8 @@ static int hi8435_write_event_config(struct iio_dev *idev,
 	int ret;
 	u32 tmp;
 
+	mutex_lock(&priv->lock);
+
 	if (state) {
 		ret = hi8435_readl(priv, HI8435_SO31_0_REG, &tmp);
 		if (ret < 0)
@@ -157,6 +159,8 @@ static int hi8435_write_event_config(struct iio_dev *idev,
 	} else
 		priv->event_scan_mask &= ~BIT(chan->channel);
 
+	mutex_unlock(&priv->lock);
+
 	return 0;
 }
 
@@ -449,12 +453,16 @@ static irqreturn_t hi8435_trigger_handler(int irq, void *private)
 	u32 val;
 	int ret;
 
+	mutex_lock(&priv->lock);
+
 	ret = hi8435_readl(priv, HI8435_SO31_0_REG, &val);
 	if (ret < 0)
 		goto err_read;
 
 	hi8435_iio_push_event(idev, val);
 
+	mutex_unlock(&priv->lock);
+
 err_read:
 	iio_trigger_notify_done(idev->trig);
 
-- 
2.11.0

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

* Re: [PATCH] iio: hi8435: fix race between event enable and event generation
  2017-05-23  8:07 [PATCH] iio: hi8435: fix race between event enable and event generation Nikita Yushchenko
@ 2017-05-24 19:30 ` Jonathan Cameron
  2017-05-24 19:56   ` Nikita Yushchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2017-05-24 19:30 UTC (permalink / raw)
  To: Nikita Yushchenko
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	Sanchayan Maity, Gregor Boirie, Matt Ranostay, linux-iio,
	linux-kernel, Chris Healy, Jeff White, Vladimir Barinov

On Tue, 23 May 2017 11:07:29 +0300
Nikita Yushchenko <nikita.yoush@cogentembedded.com> wrote:

> Add locking to avoid interference between reading/processing current
> sence in event enable and event generation paths.
> 
> Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
Make sense.  Could you give a little more detail on the seriousness
of this bug?  I need to assess whether we just queue it up for the
next merge window or push it forward quicker as a bug fix and
whether to mark it for stable or not.

You probably have a better idea of how much it matters than I do!

Thanks,

Jonathan
> ---
>  drivers/iio/adc/hi8435.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/iio/adc/hi8435.c b/drivers/iio/adc/hi8435.c
> index ab59969b7c49..28fc699f00f6 100644
> --- a/drivers/iio/adc/hi8435.c
> +++ b/drivers/iio/adc/hi8435.c
> @@ -144,6 +144,8 @@ static int hi8435_write_event_config(struct iio_dev *idev,
>  	int ret;
>  	u32 tmp;
>  
> +	mutex_lock(&priv->lock);
> +
>  	if (state) {
>  		ret = hi8435_readl(priv, HI8435_SO31_0_REG, &tmp);
>  		if (ret < 0)
> @@ -157,6 +159,8 @@ static int hi8435_write_event_config(struct iio_dev *idev,
>  	} else
>  		priv->event_scan_mask &= ~BIT(chan->channel);
>  
> +	mutex_unlock(&priv->lock);
> +
>  	return 0;
>  }
>  
> @@ -449,12 +453,16 @@ static irqreturn_t hi8435_trigger_handler(int irq, void *private)
>  	u32 val;
>  	int ret;
>  
> +	mutex_lock(&priv->lock);
> +
>  	ret = hi8435_readl(priv, HI8435_SO31_0_REG, &val);
>  	if (ret < 0)
>  		goto err_read;
>  
>  	hi8435_iio_push_event(idev, val);
>  
> +	mutex_unlock(&priv->lock);
> +
>  err_read:
>  	iio_trigger_notify_done(idev->trig);
>  

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

* Re: [PATCH] iio: hi8435: fix race between event enable and event generation
  2017-05-24 19:30 ` Jonathan Cameron
@ 2017-05-24 19:56   ` Nikita Yushchenko
  0 siblings, 0 replies; 3+ messages in thread
From: Nikita Yushchenko @ 2017-05-24 19:56 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	Sanchayan Maity, Gregor Boirie, Matt Ranostay, linux-iio,
	linux-kernel, Chris Healy, Jeff White, Vladimir Barinov

>> Add locking to avoid interference between reading/processing current
>> sence in event enable and event generation paths.
>>
>> Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
> Make sense.  Could you give a little more detail on the seriousness
> of this bug?  I need to assess whether we just queue it up for the
> next merge window or push it forward quicker as a bug fix and
> whether to mark it for stable or not.
> 
> You probably have a better idea of how much it matters than I do!

Race was introduced by my previous patch, and noticed by Vladimir.
It is not in any released tree.

Possible race impact is loss of event or duplicate event.

Nikita

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

end of thread, other threads:[~2017-05-24 19:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-23  8:07 [PATCH] iio: hi8435: fix race between event enable and event generation Nikita Yushchenko
2017-05-24 19:30 ` Jonathan Cameron
2017-05-24 19:56   ` Nikita Yushchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).