All of lore.kernel.org
 help / color / mirror / Atom feed
* [BUG RFC] iio: pressure: zpa2326: incorrect condition or inconsistent return handling
@ 2017-05-03 10:53 Nicholas Mc Guire
  2017-05-03 11:42 ` Peter Meerwald-Stadler
  0 siblings, 1 reply; 2+ messages in thread
From: Nicholas Mc Guire @ 2017-05-03 10:53 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	simran singhal, Arnd Bergmann, Gregor Boirie, linux-iio,
	linux-kernel, Nicholas Mc Guire

wait_for_completion_interruptible_timeout() returns -ERESTARTSYS, 0 or
remaining time in jiffies (atleast 1), thus the if (ret != -ERESTARTSYS)
case here is unreachable. 

As it is not clear from the warn message if this should simply be changed
to if (ret == -ERESTARTSYS), this needs a review by someone that knows
the intent of this condition. In any case the current treatment of the
return value of wait_for_completion_interruptible_timeout() is inconsistent
with the specification of the same.

Also wait_for_completion_interruptible_timeout() returns a long not int.

Problem was introduced in commit 03b262f2bbf4 ("iio:pressure: initial zpa2326 barometer support")

 drivers/iio/pressure/zpa2326.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
index e58a0ad..80ca6ec 100644
--- a/drivers/iio/pressure/zpa2326.c
+++ b/drivers/iio/pressure/zpa2326.c
@@ -872,35 +872,35 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
 
 	ret = wait_for_completion_interruptible_timeout(
 		&private->data_ready, ZPA2326_CONVERSION_JIFFIES);
 	if (ret > 0)
 		/*
 		 * Interrupt handler completed before timeout: return operation
 		 * status.
 		 */
 		return private->result;
 
 	/* Clear all interrupts just to be sure. */
 	regmap_read(private->regmap, ZPA2326_INT_SOURCE_REG, &val);
 
 	if (!ret)
 		/* Timed out. */
 		ret = -ETIME;
 
-	if (ret != -ERESTARTSYS)
+	if (ret == -ERESTARTSYS)
 		zpa2326_warn(indio_dev, "no one shot interrupt occurred (%d)",
 			     ret);
 
 	return ret;
 }
 
 static int zpa2326_init_managed_irq(struct device          *parent,
 				    struct iio_dev         *indio_dev,
 				    struct zpa2326_private *private,
 				    int                     irq)
 {
 	int err;
 
 	private->irq = irq;
 
 	if (irq <= 0) {
 		/*
-- 
2.1.4

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

* Re: [BUG RFC] iio: pressure: zpa2326: incorrect condition or inconsistent return handling
  2017-05-03 10:53 [BUG RFC] iio: pressure: zpa2326: incorrect condition or inconsistent return handling Nicholas Mc Guire
@ 2017-05-03 11:42 ` Peter Meerwald-Stadler
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Meerwald-Stadler @ 2017-05-03 11:42 UTC (permalink / raw)
  To: Nicholas Mc Guire
  Cc: Jonathan Cameron, Lars-Peter Clausen, simran singhal,
	Gregor Boirie, linux-iio, linux-kernel

Hello,

> wait_for_completion_interruptible_timeout() returns -ERESTARTSYS, 0 or
> remaining time in jiffies (atleast 1), thus the if (ret != -ERESTARTSYS)
> case here is unreachable. 

if is not unreachable, there is a ret = -ETIME above it
 
> As it is not clear from the warn message if this should simply be changed
> to if (ret == -ERESTARTSYS), this needs a review by someone that knows
> the intent of this condition. In any case the current treatment of the
> return value of wait_for_completion_interruptible_timeout() is inconsistent
> with the specification of the same.

the intention of the code is not very clear, I agree

"no one shot interrupt" should probably be printed for the -ETIME case, 
i.e. when a timeout occurs
 
> Also wait_for_completion_interruptible_timeout() returns a long not int.

true
 
> Problem was introduced in commit 03b262f2bbf4 ("iio:pressure: initial zpa2326 barometer support")
> 
>  drivers/iio/pressure/zpa2326.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
> index e58a0ad..80ca6ec 100644
> --- a/drivers/iio/pressure/zpa2326.c
> +++ b/drivers/iio/pressure/zpa2326.c
> @@ -872,35 +872,35 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
>  
>  	ret = wait_for_completion_interruptible_timeout(
>  		&private->data_ready, ZPA2326_CONVERSION_JIFFIES);
>  	if (ret > 0)
>  		/*
>  		 * Interrupt handler completed before timeout: return operation
>  		 * status.
>  		 */
>  		return private->result;
>  
>  	/* Clear all interrupts just to be sure. */
>  	regmap_read(private->regmap, ZPA2326_INT_SOURCE_REG, &val);
>  
>  	if (!ret)
>  		/* Timed out. */
>  		ret = -ETIME;
>  
> -	if (ret != -ERESTARTSYS)
> +	if (ret == -ERESTARTSYS)
>  		zpa2326_warn(indio_dev, "no one shot interrupt occurred (%d)",
>  			     ret);
>  
>  	return ret;
>  }
>  
>  static int zpa2326_init_managed_irq(struct device          *parent,
>  				    struct iio_dev         *indio_dev,
>  				    struct zpa2326_private *private,
>  				    int                     irq)
>  {
>  	int err;
>  
>  	private->irq = irq;
>  
>  	if (irq <= 0) {
>  		/*
> 

-- 

Peter Meerwald-Stadler
Mobile: +43 664 24 44 418

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

end of thread, other threads:[~2017-05-03 11:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-03 10:53 [BUG RFC] iio: pressure: zpa2326: incorrect condition or inconsistent return handling Nicholas Mc Guire
2017-05-03 11:42 ` Peter Meerwald-Stadler

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.