All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: adc: mcp3422: fix locking on error path
@ 2020-09-01  9:32 Angelo Compagnucci
  2020-09-01 10:01 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Angelo Compagnucci @ 2020-09-01  9:32 UTC (permalink / raw)
  To: linux-iio; +Cc: gregkh, jic23, Angelo Compagnucci

Reading from the chip should be unlocked on error path else the lock
could never being released.

Fixes: 07914c84ba30 ("iio: adc: Add driver for Microchip MCP3422/3/4 high resolution ADC")
Signed-off-by: Angelo Compagnucci <angelo.compagnucci@gmail.com>
---
 drivers/iio/adc/mcp3422.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/mcp3422.c b/drivers/iio/adc/mcp3422.c
index 219adac2384b..da353dcb1e9d 100644
--- a/drivers/iio/adc/mcp3422.c
+++ b/drivers/iio/adc/mcp3422.c
@@ -143,8 +143,10 @@ static int mcp3422_read_channel(struct mcp3422 *adc,
 		config &= ~MCP3422_PGA_MASK;
 		config |= MCP3422_PGA_VALUE(adc->pga[req_channel]);
 		ret = mcp3422_update_config(adc, config);
-		if (ret < 0)
+		if (ret < 0) {
+			mutex_unlock(&adc->lock);
 			return ret;
+		}
 		msleep(mcp3422_read_times[MCP3422_SAMPLE_RATE(adc->config)]);
 	}
 
-- 
2.25.1


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

* Re: [PATCH] iio: adc: mcp3422: fix locking on error path
  2020-09-01  9:32 [PATCH] iio: adc: mcp3422: fix locking on error path Angelo Compagnucci
@ 2020-09-01 10:01 ` Jonathan Cameron
  2020-09-01 14:08   ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2020-09-01 10:01 UTC (permalink / raw)
  To: Angelo Compagnucci; +Cc: linux-iio, gregkh, jic23, Julia Lawall

On Tue, 1 Sep 2020 11:32:18 +0200
Angelo Compagnucci <angelo.compagnucci@gmail.com> wrote:

> Reading from the chip should be unlocked on error path else the lock
> could never being released.

We should also reference the fix that we are fixing so I've added
an additional fixes tag below and a reported by tag for Julia.

> 
> Fixes: 07914c84ba30 ("iio: adc: Add driver for Microchip MCP3422/3/4 high resolution ADC")
Fixes: 3f1093d83d71 ("iio: adc: mcp3422: fix locking scope")
> Signed-off-by: Angelo Compagnucci <angelo.compagnucci@gmail.com>
Reported-by: Julia Lawall <julia.lawall@inria.fr>
Acked-by: Jonathan Cameron <jonathan.cameron@huawei.com>

Greg, this is the fix for the issue Julia reported.

Sorry for the hassle (and messing this up in the first palce), but
could you pick this one up directly into your staging-linus branch.

If you'd prefer a different resolution to the problem let us know.

Thanks,

Jonathan


> ---
>  drivers/iio/adc/mcp3422.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/mcp3422.c b/drivers/iio/adc/mcp3422.c
> index 219adac2384b..da353dcb1e9d 100644
> --- a/drivers/iio/adc/mcp3422.c
> +++ b/drivers/iio/adc/mcp3422.c
> @@ -143,8 +143,10 @@ static int mcp3422_read_channel(struct mcp3422 *adc,
>  		config &= ~MCP3422_PGA_MASK;
>  		config |= MCP3422_PGA_VALUE(adc->pga[req_channel]);
>  		ret = mcp3422_update_config(adc, config);
> -		if (ret < 0)
> +		if (ret < 0) {
> +			mutex_unlock(&adc->lock);
>  			return ret;
> +		}
>  		msleep(mcp3422_read_times[MCP3422_SAMPLE_RATE(adc->config)]);
>  	}
>  



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

* Re: [PATCH] iio: adc: mcp3422: fix locking on error path
  2020-09-01 10:01 ` Jonathan Cameron
@ 2020-09-01 14:08   ` Greg KH
  0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2020-09-01 14:08 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Angelo Compagnucci, linux-iio, jic23, Julia Lawall

On Tue, Sep 01, 2020 at 11:01:25AM +0100, Jonathan Cameron wrote:
> On Tue, 1 Sep 2020 11:32:18 +0200
> Angelo Compagnucci <angelo.compagnucci@gmail.com> wrote:
> 
> > Reading from the chip should be unlocked on error path else the lock
> > could never being released.
> 
> We should also reference the fix that we are fixing so I've added
> an additional fixes tag below and a reported by tag for Julia.
> 
> > 
> > Fixes: 07914c84ba30 ("iio: adc: Add driver for Microchip MCP3422/3/4 high resolution ADC")
> Fixes: 3f1093d83d71 ("iio: adc: mcp3422: fix locking scope")
> > Signed-off-by: Angelo Compagnucci <angelo.compagnucci@gmail.com>
> Reported-by: Julia Lawall <julia.lawall@inria.fr>
> Acked-by: Jonathan Cameron <jonathan.cameron@huawei.com>
> 
> Greg, this is the fix for the issue Julia reported.
> 
> Sorry for the hassle (and messing this up in the first palce), but
> could you pick this one up directly into your staging-linus branch.

No worries, now queued up, thanks.

greg k-h

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

end of thread, other threads:[~2020-09-01 14:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-01  9:32 [PATCH] iio: adc: mcp3422: fix locking on error path Angelo Compagnucci
2020-09-01 10:01 ` Jonathan Cameron
2020-09-01 14:08   ` Greg KH

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.