Skip to contentSkip to conversation

iio: adc: mcp3422: fix locking on error path

PATCH In review Angelo Compagnucci 3 participants 3 messages Sep 1, 2020 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: adc: mcp3422: fix locking on error path

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")
---
 drivers/iio/adc/mcp3422.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/mcp3422.c +3 -1
index 219adac2384b..da353dcb1e9d 100644
@@ -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)]);
 	}
 
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 2 lines · On Tue, 1 Sep 2020 11:32:18 +0200 Angelo Compagnucci…

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.

Quoted 2 lines
Fixes 07914c84ba30 ("iio: adc: Add driver for Microchip MCP3422/3/4 high resolution ADC")
Fixes 3f1093d83d71 ("iio: adc: mcp3422: fix locking scope")
Quoted 1 line

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

Quoted 20 lines
---
 drivers/iio/adc/mcp3422.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/mcp3422.c +3 -1
index 219adac2384b..da353dcb1e9d 100644
@@ -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 lore raw
Quoted 12 lines · Jonathan Cameron
Quoted 2 lines · On Tue, 1 Sep 2020 11:32:18 +0200 Angelo Compagnucci…

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.

Quoted 2 lines
Fixes 07914c84ba30 ("iio: adc: Add driver for Microchip MCP3422/3/4 high resolution ADC")
Fixes 3f1093d83d71 ("iio: adc: mcp3422: fix locking scope")
Quoted 8 lines
Quoted 1 line

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