linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: iio: ad7152: Fix deadlock in ad7152_write_raw_samp_freq()
@ 2017-05-26 22:53 Alexey Khoroshilov
  2017-05-28  9:47 ` Lars-Peter Clausen
  0 siblings, 1 reply; 3+ messages in thread
From: Alexey Khoroshilov @ 2017-05-26 22:53 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Hartmut Knaack, Peter Meerwald-Stadler, Greg Kroah-Hartman
  Cc: Alexey Khoroshilov, linux-iio, devel, linux-kernel, ldv-project

ad7152_write_raw_samp_freq() is called by ad7152_write_raw() with
chip->state_lock held. So, there is unavoidable deadlock when
ad7152_write_raw_samp_freq() locks the mutex itself.

The patch removes unneeded locking.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 drivers/staging/iio/cdc/ad7152.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/staging/iio/cdc/ad7152.c b/drivers/staging/iio/cdc/ad7152.c
index dc6ecd824365..ff10d1f0a7e4 100644
--- a/drivers/staging/iio/cdc/ad7152.c
+++ b/drivers/staging/iio/cdc/ad7152.c
@@ -231,16 +231,12 @@ static int ad7152_write_raw_samp_freq(struct device *dev, int val)
 	if (i >= ARRAY_SIZE(ad7152_filter_rate_table))
 		i = ARRAY_SIZE(ad7152_filter_rate_table) - 1;
 
-	mutex_lock(&chip->state_lock);
 	ret = i2c_smbus_write_byte_data(chip->client,
 					AD7152_REG_CFG2, AD7152_CFG2_OSR(i));
-	if (ret < 0) {
-		mutex_unlock(&chip->state_lock);
+	if (ret < 0)
 		return ret;
-	}
 
 	chip->filter_rate_setup = i;
-	mutex_unlock(&chip->state_lock);
 
 	return ret;
 }
-- 
2.7.4

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

* Re: [PATCH] staging: iio: ad7152: Fix deadlock in ad7152_write_raw_samp_freq()
  2017-05-26 22:53 [PATCH] staging: iio: ad7152: Fix deadlock in ad7152_write_raw_samp_freq() Alexey Khoroshilov
@ 2017-05-28  9:47 ` Lars-Peter Clausen
  2017-05-28 14:46   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Lars-Peter Clausen @ 2017-05-28  9:47 UTC (permalink / raw)
  To: Alexey Khoroshilov, Michael Hennerich, Jonathan Cameron,
	Hartmut Knaack, Peter Meerwald-Stadler, Greg Kroah-Hartman
  Cc: linux-iio, devel, linux-kernel, ldv-project

On 05/27/2017 12:53 AM, Alexey Khoroshilov wrote:
> ad7152_write_raw_samp_freq() is called by ad7152_write_raw() with
> chip->state_lock held. So, there is unavoidable deadlock when
> ad7152_write_raw_samp_freq() locks the mutex itself.
> 
> The patch removes unneeded locking.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>

Looks good, thanks.

Fixes: 6572389bcc11 ("staging: iio: cdc: ad7152: Implement
IIO_CHAN_INFO_SAMP_FREQ attribute")
Acked-by: Lars-Peter Clausen <lars@metafoo.de>


> ---
>  drivers/staging/iio/cdc/ad7152.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/drivers/staging/iio/cdc/ad7152.c b/drivers/staging/iio/cdc/ad7152.c
> index dc6ecd824365..ff10d1f0a7e4 100644
> --- a/drivers/staging/iio/cdc/ad7152.c
> +++ b/drivers/staging/iio/cdc/ad7152.c
> @@ -231,16 +231,12 @@ static int ad7152_write_raw_samp_freq(struct device *dev, int val)
>  	if (i >= ARRAY_SIZE(ad7152_filter_rate_table))
>  		i = ARRAY_SIZE(ad7152_filter_rate_table) - 1;
>  
> -	mutex_lock(&chip->state_lock);
>  	ret = i2c_smbus_write_byte_data(chip->client,
>  					AD7152_REG_CFG2, AD7152_CFG2_OSR(i));
> -	if (ret < 0) {
> -		mutex_unlock(&chip->state_lock);
> +	if (ret < 0)
>  		return ret;
> -	}
>  
>  	chip->filter_rate_setup = i;
> -	mutex_unlock(&chip->state_lock);
>  
>  	return ret;
>  }
> 

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

* Re: [PATCH] staging: iio: ad7152: Fix deadlock in ad7152_write_raw_samp_freq()
  2017-05-28  9:47 ` Lars-Peter Clausen
@ 2017-05-28 14:46   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2017-05-28 14:46 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Alexey Khoroshilov, Michael Hennerich, Hartmut Knaack,
	Peter Meerwald-Stadler, Greg Kroah-Hartman, linux-iio, devel,
	linux-kernel, ldv-project

On Sun, 28 May 2017 11:47:04 +0200
Lars-Peter Clausen <lars@metafoo.de> wrote:

> On 05/27/2017 12:53 AM, Alexey Khoroshilov wrote:
> > ad7152_write_raw_samp_freq() is called by ad7152_write_raw() with
> > chip->state_lock held. So, there is unavoidable deadlock when
> > ad7152_write_raw_samp_freq() locks the mutex itself.
> > 
> > The patch removes unneeded locking.
> > 
> > Found by Linux Driver Verification project (linuxtesting.org).
> > 
> > Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>  
> 
> Looks good, thanks.
> 
> Fixes: 6572389bcc11 ("staging: iio: cdc: ad7152: Implement
> IIO_CHAN_INFO_SAMP_FREQ attribute")
> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Applied to the fixes-togreg branch of iio.git.

Thanks,

Jonathan
> 
> 
> > ---
> >  drivers/staging/iio/cdc/ad7152.c | 6 +-----
> >  1 file changed, 1 insertion(+), 5 deletions(-)
> > 
> > diff --git a/drivers/staging/iio/cdc/ad7152.c b/drivers/staging/iio/cdc/ad7152.c
> > index dc6ecd824365..ff10d1f0a7e4 100644
> > --- a/drivers/staging/iio/cdc/ad7152.c
> > +++ b/drivers/staging/iio/cdc/ad7152.c
> > @@ -231,16 +231,12 @@ static int ad7152_write_raw_samp_freq(struct device *dev, int val)
> >  	if (i >= ARRAY_SIZE(ad7152_filter_rate_table))
> >  		i = ARRAY_SIZE(ad7152_filter_rate_table) - 1;
> >  
> > -	mutex_lock(&chip->state_lock);
> >  	ret = i2c_smbus_write_byte_data(chip->client,
> >  					AD7152_REG_CFG2, AD7152_CFG2_OSR(i));
> > -	if (ret < 0) {
> > -		mutex_unlock(&chip->state_lock);
> > +	if (ret < 0)
> >  		return ret;
> > -	}
> >  
> >  	chip->filter_rate_setup = i;
> > -	mutex_unlock(&chip->state_lock);
> >  
> >  	return ret;
> >  }
> >   
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2017-05-28 14:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-26 22:53 [PATCH] staging: iio: ad7152: Fix deadlock in ad7152_write_raw_samp_freq() Alexey Khoroshilov
2017-05-28  9:47 ` Lars-Peter Clausen
2017-05-28 14:46   ` Jonathan Cameron

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).