Skip to contentSkip to conversation

iio: stmpe-adc: Remove unnecessary assignment

PATCH In review Philippe Schenker 4 participants 9 messages May 3, 2019 – May 7, 2019 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 iio: stmpe-adc: Remove unnecessary assignment

From: Philippe Schenker <[email protected]>

Remove unnecessary assignment. This could potentially cause an issue, if the wait function runs into a timeout. Furthermore is this assignment also not there in stmpe_read_temp()

---

 drivers/iio/adc/stmpe-adc.c | 2 --
 1 file changed, 2 deletions(-)
drivers/iio/adc/stmpe-adc.c +0 -2
index 37f4b74a5d32..87141177fbda 100644
@@ -78,8 +78,6 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
 	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_CAPT,
 			STMPE_ADC_CH(info->channel));
 
-	*val = info->value;
-
 	ret = wait_for_completion_interruptible_timeout
 		(&info->completion, STMPE_ADC_TIMEOUT);
 
Signature · 1 line
2.21.0
#1 lore raw

PATCH 2/3 iio: stmpe-adc: Make wait_completion non interruptible

From: Philippe Schenker <[email protected]>

In some cases, the wait_completion got interrupted. This caused the error-handling to mutex_unlock the function. The before turned on interrupt then got called anyway. In the ISR then completion() was called causing problems.

Making this wait_completion non interruptible solves the problem.

---

 drivers/iio/adc/stmpe-adc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/iio/adc/stmpe-adc.c +2 -4
index 87141177fbda..baa41ffc0d76 100644
@@ -78,8 +78,7 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
 	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_CAPT,
 			STMPE_ADC_CH(info->channel));
 
-	ret = wait_for_completion_interruptible_timeout
-		(&info->completion, STMPE_ADC_TIMEOUT);
+	ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
 
 	if (ret <= 0) {
 		mutex_unlock(&info->lock);
@@ -113,8 +112,7 @@ static int stmpe_read_temp(struct stmpe_adc *info,
 	stmpe_reg_write(info->stmpe, STMPE_REG_TEMP_CTRL,
 			STMPE_START_ONE_TEMP_CONV);
 
-	ret = wait_for_completion_interruptible_timeout
-		(&info->completion, STMPE_ADC_TIMEOUT);
+	ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
 
 	if (ret <= 0) {
 		mutex_unlock(&info->lock);
Signature · 1 line
2.21.0
#7 lore raw

PATCH 3/3 iio: stmpe-adc: Enable all stmpe-adc interrupts just once

In reply to Philippe Schenker

From: Philippe Schenker <[email protected]>

This commit will enable the interrupts of all channels handled by this driver only once in the probe function.

This will improve performance because one byte less has to be written over i2c on each read out of the adc. On the fastest ADC mode this will improve read out speed by 15%.

---

 drivers/iio/adc/stmpe-adc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/adc/stmpe-adc.c +3 -3
index baa41ffc0d76..427c890c6e7d 100644
@@ -72,9 +72,6 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
 		return -EINVAL;
 	}
 
-	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_EN,
-			STMPE_ADC_CH(info->channel));
-
 	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_CAPT,
 			STMPE_ADC_CH(info->channel));
 
@@ -328,6 +325,9 @@ static int stmpe_adc_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_EN,
+			~(norequest_mask & 0xFF));
+
 	return devm_iio_device_register(&pdev->dev, indio_dev);
 }
 
Signature · 1 line
2.21.0
#2 lore raw

RE: [PATCH 2/3] iio: stmpe-adc: Make wait_completion non interruptible

In reply to Philippe Schenker

From: Philippe Schenker

Quoted 7 lines

Sent: 03 May 2019 14:57
In some cases, the wait_completion got interrupted. This caused the error-handling to mutex_unlock the function. The before turned on interrupt then got called anyway. In the ISR then completion() was called causing problems.

Making this wait_completion non interruptible solves the problem.

Won't the same thing happen if the interrupt occurs just after the timeout?

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#3 lore raw

Re: [PATCH 2/3] iio: stmpe-adc: Make wait_completion non interruptible

Quoted 12 lines · David Laight

From: Philippe Schenker

Quoted 7 lines

Sent: 03 May 2019 14:57
In some cases, the wait_completion got interrupted. This caused the error-handling to mutex_unlock the function. The before turned on interrupt then got called anyway. In the ISR then completion() was called causing problems.

Making this wait_completion non interruptible solves the problem.

Won't the same thing happen if the interrupt occurs just after the timeout?

Quoted 8 lines

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

You're of course right... Thanks for pointing this out. I will send a v2 with a better solution then.

Philippe

maintainer
#10 lore raw
In reply to Philippe Schenker
Quoted 7 lines · On Fri, 3 May 2019 15:57:23 +0200 Philippe Schenker <[email protected]> wrote:

From: Philippe Schenker <[email protected]>

Remove unnecessary assignment. This could potentially cause an issue, if the wait function runs into a timeout. Furthermore is this assignment also not there in stmpe_read_temp()

This would probably have benefited from a statement that *val is set twice currently. Good find.

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.

Thanks,

Jonathan

Quoted 18 lines

---

 drivers/iio/adc/stmpe-adc.c | 2 --
 1 file changed, 2 deletions(-)
drivers/iio/adc/stmpe-adc.c +0 -2
index 37f4b74a5d32..87141177fbda 100644
@@ -78,8 +78,6 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
 	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_CAPT,
 			STMPE_ADC_CH(info->channel));
 
-	*val = info->value;
-
 	ret = wait_for_completion_interruptible_timeout
 		(&info->completion, STMPE_ADC_TIMEOUT);
 
maintainer
#8 lore raw

Re: [PATCH 3/3] iio: stmpe-adc: Enable all stmpe-adc interrupts just once

In reply to Philippe Schenker
Quoted 10 lines · On Fri, 3 May 2019 15:57:25 +0200 Philippe Schenker <[email protected]> wrote:

From: Philippe Schenker <[email protected]>

This commit will enable the interrupts of all channels handled by this driver only once in the probe function.

This will improve performance because one byte less has to be written over i2c on each read out of the adc. On the fastest ADC mode this will improve read out speed by 15%.

Makes sense. I'll pick this up once patch 2 discussion is sorted.

Jonathan

Quoted 30 lines

---

 drivers/iio/adc/stmpe-adc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/adc/stmpe-adc.c +3 -3
index baa41ffc0d76..427c890c6e7d 100644
@@ -72,9 +72,6 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
 		return -EINVAL;
 	}
 
-	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_EN,
-			STMPE_ADC_CH(info->channel));
-
 	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_CAPT,
 			STMPE_ADC_CH(info->channel));
 
@@ -328,6 +325,9 @@ static int stmpe_adc_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_EN,
+			~(norequest_mask & 0xFF));
+
 	return devm_iio_device_register(&pdev->dev, indio_dev);
 }
 
#6 lore raw

Re: [PATCH 2/3] iio: stmpe-adc: Make wait_completion non interruptible

In reply to a message not in the archive
Quoted 37 lines · David Laight

From: Jonathan Cameron

Quoted 27 lines

Sent: 05 May 2019 16:44

Quoted 23 lines · On Fri, 3 May 2019 15:58:38 +0000 Philippe Schenker…
Quoted 21 lines · David Laight

From: Philippe Schenker

Quoted 7 lines

Sent: 03 May 2019 14:57
In some cases, the wait_completion got interrupted. This caused the error-handling to mutex_unlock the function. The before turned on interrupt then got called anyway. In the ISR then completion() was called causing problems.

Making this wait_completion non interruptible solves the problem.

Won't the same thing happen if the interrupt occurs just after the timeout?

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT,
UK
Registration No: 1397386 (Wales)

Quoted 8 lines
Quoted 4 lines

You're of course right... Thanks for pointing this out. I will send a v2 with a
better solution then.

Isn't the timeout long enough that it should only happen if the hardware has a fault? If that's the case, I wouldn't worry too much about possibility of an interrupt causing confusion as long as it isn't catastrophic.

Quoted 7 lines

The 'confusion' is likely to be 'catastrophic' unless the code is written to handle it properly.

Cancelling callbacks is hard to get right and often not done properly. Timing out an interrupt is much the same problem.

David

I sorted it out now, there where also some more bugs I found and corrected.

@Jonathan: I will send a completely new series of patches that will include patch 3/3 from this series but not the one you already applied. This due to increased patch number and different order...

Quoted 6 lines

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

#9 lore raw

Re: [PATCH 3/3] iio: stmpe-adc: Enable all stmpe-adc interrupts just once

In reply to Jonathan Cameron
Quoted 8 lines · Jonathan Cameron
Quoted 5 lines · On Fri, 3 May 2019 15:57:25 +0200 Philippe Schenker <[email protected]> wrote:

From: Philippe Schenker <[email protected]>

This commit will enable the interrupts of all channels handled by this driver only once in the probe function.

Quoted 8 lines
Quoted 5 lines

This will improve performance because one byte less has to be written over i2c on each read out of the adc. On the fastest ADC mode this will improve read out speed by 15%.

Makes sense. I'll pick this up once patch 2 discussion is sorted.

Jonathan

Please ignore this patch here as I send a completely new series that includes this one.

Quoted 30 lines
Quoted 30 lines

---

 drivers/iio/adc/stmpe-adc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/adc/stmpe-adc.c +3 -3
index baa41ffc0d76..427c890c6e7d 100644
@@ -72,9 +72,6 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
 		return -EINVAL;
 	}
 
-	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_EN,
-			STMPE_ADC_CH(info->channel));
-
 	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_CAPT,
 			STMPE_ADC_CH(info->channel));
 
@@ -328,6 +325,9 @@ static int stmpe_adc_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_EN,
+			~(norequest_mask & 0xFF));
+
 	return devm_iio_device_register(&pdev->dev, indio_dev);
 }