Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1634882 > unrolled thread

[BUG RFC] iio: pressure: zpa2326: incorrect condition or inconsistent return handling

Started byNicholas Mc Guire <der.herr@hofr.at>
First post2017-05-03 13:00 +0200
Last post2017-05-03 13:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [BUG RFC] iio: pressure: zpa2326: incorrect condition or inconsistent return handling Nicholas Mc Guire <der.herr@hofr.at> - 2017-05-03 13:00 +0200
    Re: [BUG RFC] iio: pressure: zpa2326: incorrect condition or  inconsistent return handling Peter Meerwald-Stadler <pmeerw@pmeerw.net> - 2017-05-03 13:50 +0200

#1634882 — [BUG RFC] iio: pressure: zpa2326: incorrect condition or inconsistent return handling

FromNicholas Mc Guire <der.herr@hofr.at>
Date2017-05-03 13:00 +0200
Subject[BUG RFC] iio: pressure: zpa2326: incorrect condition or inconsistent return handling
Message-ID<tD0aL-4bC-57@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1634903 — Re: [BUG RFC] iio: pressure: zpa2326: incorrect condition or inconsistent return handling

FromPeter Meerwald-Stadler <pmeerw@pmeerw.net>
Date2017-05-03 13:50 +0200
SubjectRe: [BUG RFC] iio: pressure: zpa2326: incorrect condition or inconsistent return handling
Message-ID<tD0X7-4Mk-7@gated-at.bofh.it>
In reply to#1634882
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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web