Skip to contentSkip to conversation

iio: stmpe-adc: Fix wait_for_completion_timeout return value check

PATCH Superseded Miaoqian Lin 3 participants 7 messages Apr 11, 2022 – Apr 12, 2022

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

PATCH 1/1 iio: stmpe-adc: Fix wait_for_completion_timeout return value check

wait_for_completion_timeout() returns unsigned long not long. it returns 0 if timed out, and positive if completed. The check for <= 0 is ambiguous and should be == 0 here indicating timeout which is the only error case

Fixes e813dde6f833 ("iio: stmpe-adc: Use wait_for_completion_timeout")
---
 drivers/iio/adc/stmpe-adc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/stmpe-adc.c +2 -2
index d2d405388499..d475d1c17bfc 100644
@@ -61,7 +61,7 @@ struct stmpe_adc {
 static int stmpe_read_voltage(struct stmpe_adc *info,
 		struct iio_chan_spec const *chan, int *val)
 {
-	long ret;
+	unsigned long ret;
 
 	mutex_lock(&info->lock);
 
@@ -79,7 +79,7 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
 
 	ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
 
-	if (ret <= 0) {
+	if (ret == 0) {
 		stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA,
 				STMPE_ADC_CH(info->channel));
 		mutex_unlock(&info->lock);
Signature · 1 line
2.17.1
#1 lore raw
Quoted 4 lines · Miaoqian Lin

wait_for_completion_timeout() returns unsigned long not long. it returns 0 if timed out, and positive if completed. The check for <= 0 is ambiguous and should be == 0 here indicating timeout which is the only error case

Hello and thanks for your fix. Any specific reason you didn't apply this also in function stmpe_read_temp?

Philippe

Quoted 32 lines
Fixes e813dde6f833 ("iio: stmpe-adc: Use

wait_for_completion_timeout")

---
 drivers/iio/adc/stmpe-adc.c | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/stmpe-adc.c +1 -1
index d2d405388499..d475d1c17bfc 100644
@@ -61,7 +61,7 @@ struct stmpe_adc {
  static int stmpe_read_voltage(struct stmpe_adc *info,
                 struct iio_chan_spec const *chan, int *val)
  {
-       long ret;
+       unsigned long ret;


        mutex_lock(&info->lock);

drivers/iio/adc/stmpe-adc.c +0 -0
@@ -79,7 +79,7 @@ static int stmpe_read_voltage(struct stmpe_adc
 *info,


        ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);

-       if (ret <= 0) {
+       if (ret == 0) {
                stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA, STMPE_ADC_CH(info->channel)); mutex_unlock(&info->lock);

#2 lore raw
Quoted 7 lines · Philippe Schenker
Quoted 4 lines · Miaoqian Lin

wait_for_completion_timeout() returns unsigned long not long. it returns 0 if timed out, and positive if completed. The check for <= 0 is ambiguous and should be == 0 here indicating timeout which is the only error case

Hello and thanks for your fix. Any specific reason you didn't apply this also in function stmpe_read_temp?

Hi,sorry I just missed that. I will send v2 to fix this.

Quoted 31 lines
Quoted 31 lines
Fixes e813dde6f833 ("iio: stmpe-adc: Use

wait_for_completion_timeout")

---
 drivers/iio/adc/stmpe-adc.c | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/stmpe-adc.c +1 -1
index d2d405388499..d475d1c17bfc 100644
@@ -61,7 +61,7 @@ struct stmpe_adc {
  static int stmpe_read_voltage(struct stmpe_adc *info,
                 struct iio_chan_spec const *chan, int *val)
  {
-       long ret;
+       unsigned long ret;


        mutex_lock(&info->lock);

drivers/iio/adc/stmpe-adc.c +0 -0
@@ -79,7 +79,7 @@ static int stmpe_read_voltage(struct stmpe_adc
 *info,


        ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);

-       if (ret <= 0) {
+       if (ret == 0) {
                stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA, STMPE_ADC_CH(info->channel)); mutex_unlock(&info->lock);

#3 lore raw

PATCH v2 1/1 iio: stmpe-adc: Fix wait_for_completion_timeout return value check

wait_for_completion_timeout() returns unsigned long not long. it returns 0 if timed out, and positive if completed. The check for <= 0 is ambiguous and should be == 0 here indicating timeout which is the only error case

Fixes e813dde6f833 ("iio: stmpe-adc: Use wait_for_completion_timeout")

---
changes in v2:
- Fix same issue in stmpe_read_temp.

---
 drivers/iio/adc/stmpe-adc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/iio/adc/stmpe-adc.c +4 -4
index d2d405388499..83e0ac4467ca 100644
@@ -61,7 +61,7 @@ struct stmpe_adc {
 static int stmpe_read_voltage(struct stmpe_adc *info,
 		struct iio_chan_spec const *chan, int *val)
 {
-	long ret;
+	unsigned long ret;
 
 	mutex_lock(&info->lock);
 
@@ -79,7 +79,7 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
 
 	ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
 
-	if (ret <= 0) {
+	if (ret == 0) {
 		stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA,
 				STMPE_ADC_CH(info->channel));
 		mutex_unlock(&info->lock);
@@ -96,7 +96,7 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
 static int stmpe_read_temp(struct stmpe_adc *info,
 		struct iio_chan_spec const *chan, int *val)
 {
-	long ret;
+	unsigned long ret;
 
 	mutex_lock(&info->lock);
 
@@ -114,7 +114,7 @@ static int stmpe_read_temp(struct stmpe_adc *info,
 
 	ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
 
-	if (ret <= 0) {
+	if (ret == 0) {
 		mutex_unlock(&info->lock);
 		return -ETIMEDOUT;
 	}
Signature · 1 line
2.17.1
reviewer Reviewed-by on v2 1/1
#4 lore raw
Quoted 23 lines

-----Original Message-----
From: Miaoqian Lin <[email protected]>
Sent: Tuesday, April 12, 2022 3:56 AM
To: Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Maxime Coquelin <[email protected]>; Alexandre Torgue <[email protected]>; Kees Cook <[email protected]>; Miaoqian Lin <[email protected]>; Philippe Schenker <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v2] iio: stmpe-adc: Fix wait_for_completion_timeout return value check

[External]

wait_for_completion_timeout() returns unsigned long not long. it returns 0 if timed out, and positive if completed. The check for <= 0 is ambiguous and should be == 0 here indicating timeout which is the only error case

Quoted 7 lines
Fixes e813dde6f833 ("iio: stmpe-adc: Use

wait_for_completion_timeout")

---
changes in v2:
- Fix same issue in stmpe_read_temp.
---

(I guess the subject also needs tweaking for the preferred format)

Quoted 51 lines
 drivers/iio/adc/stmpe-adc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/iio/adc/stmpe-adc.c +2 -2
index d2d405388499..83e0ac4467ca 100644
@@ -61,7 +61,7 @@ struct stmpe_adc {
 static int stmpe_read_voltage(struct stmpe_adc *info,
 		struct iio_chan_spec const *chan, int *val)
 {
-	long ret;
+	unsigned long ret;
 
 	mutex_lock(&info->lock);
 
@@ -79,7 +79,7 @@ static int stmpe_read_voltage(struct stmpe_adc
 *info,
 
 	ret = wait_for_completion_timeout(&info->completion,
 STMPE_ADC_TIMEOUT);
 
-	if (ret <= 0) {
+	if (ret == 0) {
 		stmpe_reg_write(info->stmpe,

STMPE_REG_ADC_INT_STA,

drivers/iio/adc/stmpe-adc.c +2 -2
 				STMPE_ADC_CH(info->channel));
 		mutex_unlock(&info->lock);
@@ -96,7 +96,7 @@ static int stmpe_read_voltage(struct stmpe_adc
 *info,
 static int stmpe_read_temp(struct stmpe_adc *info,
 		struct iio_chan_spec const *chan, int *val)
 {
-	long ret;
+	unsigned long ret;
 
 	mutex_lock(&info->lock);
@@ -114,7 +114,7 @@ static int stmpe_read_temp(struct stmpe_adc
 *info,
 
 	ret = wait_for_completion_timeout(&info->completion,
 STMPE_ADC_TIMEOUT);
 
-	if (ret <= 0) {
+	if (ret == 0) {
 		mutex_unlock(&info->lock);
drivers/iio/adc/stmpe-adc.c +0 -1
 		return -ETIMEDOUT;
 	}
--

2.17.1

#5 lore raw

PATCH v3 1/1 iio: adc: stmpe-adc: Fix wait_for_completion_timeout return value check

wait_for_completion_timeout() returns unsigned long not long. it returns 0 if timed out, and positive if completed. The check for <= 0 is ambiguous and should be == 0 here indicating timeout which is the only error case

Fixes e813dde6f833 ("iio: stmpe-adc: Use wait_for_completion_timeout")

---
changes in v2:
- Fix same issue in stmpe_read_temp.
---
changes in v3:
- update the patch subject.

---
 drivers/iio/adc/stmpe-adc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/iio/adc/stmpe-adc.c +4 -4
index d2d405388499..83e0ac4467ca 100644
@@ -61,7 +61,7 @@ struct stmpe_adc {
 static int stmpe_read_voltage(struct stmpe_adc *info,
 		struct iio_chan_spec const *chan, int *val)
 {
-	long ret;
+	unsigned long ret;
 
 	mutex_lock(&info->lock);
 
@@ -79,7 +79,7 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
 
 	ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
 
-	if (ret <= 0) {
+	if (ret == 0) {
 		stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA,
 				STMPE_ADC_CH(info->channel));
 		mutex_unlock(&info->lock);
@@ -96,7 +96,7 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
 static int stmpe_read_temp(struct stmpe_adc *info,
 		struct iio_chan_spec const *chan, int *val)
 {
-	long ret;
+	unsigned long ret;
 
 	mutex_lock(&info->lock);
 
@@ -114,7 +114,7 @@ static int stmpe_read_temp(struct stmpe_adc *info,
 
 	ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
 
-	if (ret <= 0) {
+	if (ret == 0) {
 		mutex_unlock(&info->lock);
 		return -ETIMEDOUT;
 	}
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by on v3 1/1
#6 lore raw

Re: [PATCH v3] iio: adc: stmpe-adc: Fix wait_for_completion_timeout return value check

Quoted 8 lines · Miaoqian Lin

wait_for_completion_timeout() returns unsigned long not long. it returns 0 if timed out, and positive if completed. The check for <= 0 is ambiguous and should be == 0 here indicating timeout which is the only error case

Fixes e813dde6f833 ("iio: stmpe-adc: Use

wait_for_completion_timeout")

Quoted 46 lines

---
changes in v2:
- Fix same issue in stmpe_read_temp.
---
changes in v3:
- update the patch subject.
---
 drivers/iio/adc/stmpe-adc.c | 8 ++++----

 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/iio/adc/stmpe-adc.c +1 -1
index d2d405388499..83e0ac4467ca 100644
@@ -61,7 +61,7 @@ struct stmpe_adc {
  static int stmpe_read_voltage(struct stmpe_adc *info,
                 struct iio_chan_spec const *chan, int *val)
  {
-       long ret;
+       unsigned long ret;


        mutex_lock(&info->lock);

drivers/iio/adc/stmpe-adc.c +0 -0
@@ -79,7 +79,7 @@ static int stmpe_read_voltage(struct stmpe_adc
 *info,


        ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);

-       if (ret <= 0) {
+       if (ret == 0) {
                stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA, STMPE_ADC_CH(info->channel)); mutex_unlock(&info->lock);

drivers/iio/adc/stmpe-adc.c +1 -1
@@ -96,7 +96,7 @@ static int stmpe_read_voltage(struct stmpe_adc
 *info,
  static int stmpe_read_temp(struct stmpe_adc *info,
                 struct iio_chan_spec const *chan, int *val)
  {
-       long ret;
+       unsigned long ret;


        mutex_lock(&info->lock);

drivers/iio/adc/stmpe-adc.c +0 -0
@@ -114,7 +114,7 @@ static int stmpe_read_temp(struct stmpe_adc *info,

Quoted 8 lines

        ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);

-       if (ret <= 0) {
+       if (ret == 0) {
                mutex_unlock(&info->lock);
                return -ETIMEDOUT;
        }

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel