iio: stmpe-adc: Fix wait_for_completion_timeout return value check
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
--- drivers/iio/adc/stmpe-adc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/stmpe-adc.c +2 -2
@@ -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
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")Signed-off-by Miaoqian Lin <[email protected]>---
drivers/iio/adc/stmpe-adc.c | 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)drivers/iio/adc/stmpe-adc.c +1
-1@@ -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);
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 caseHello 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")Signed-off-by Miaoqian Lin <[email protected]>---
drivers/iio/adc/stmpe-adc.c | 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)drivers/iio/adc/stmpe-adc.c +1
-1@@ -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);
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
---
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
@@ -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
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: Fixwait_for_completion_timeoutreturn 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")Signed-off-by Miaoqian Lin <[email protected]>---
changes in v2:
- Fix same issue instmpe_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@@ -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
-2STMPE_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
-1return -ETIMEDOUT ; } --2.17.1
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
---
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
@@ -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
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 caseFixes e813dde6f833 ("iio: stmpe-adc: Use
wait_for_completion_timeout")Signed-off-by Miaoqian Lin <[email protected]>
Quoted 46 lines
---
changes in v2:
- Fix same issue instmpe_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@@ -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