linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC] iio: pressure: zpa2326: report interrupted case as failure
@ 2017-05-14  8:43 Nicholas Mc Guire
  2017-05-14  9:46 ` Peter Meerwald-Stadler
  2017-07-04 10:40 ` Geert Uytterhoeven
  0 siblings, 2 replies; 12+ messages in thread
From: Nicholas Mc Guire @ 2017-05-14  8:43 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

If the timeout-case prints a warning message then probably the interrupted
case should also. Further, wait_for_completion_interruptible_timeout()
returns long not int. 

Fixes: commit 03b262f2bbf4 ("iio:pressure: initial zpa2326 barometer support")
Signed-off-by: Nicholas Mc Guire <der.herr@hofr.at>
---

The original control-flow was technically not wrong just confusing and a bit 
complicated. Not clear if reporting the interrupted case actually is useful,
but given that the timeout is relatively long (200ms) it is not that unlikely
so differentiating the cases seems helpful.

Patch was compile-tested with: x86_64_defconfig + CONFIG_IIO=m, CONFIG_ZPA2326=m

Patch is against v4.11 (localversion-next is next-20170512)

 drivers/iio/pressure/zpa2326.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
index e58a0ad..617926f 100644
--- a/drivers/iio/pressure/zpa2326.c
+++ b/drivers/iio/pressure/zpa2326.c
@@ -867,12 +867,13 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
 {
 	int          ret;
 	unsigned int val;
+	long     timeout;
 
 	zpa2326_dbg(indio_dev, "waiting for one shot completion interrupt");
 
-	ret = wait_for_completion_interruptible_timeout(
+	timeout = wait_for_completion_interruptible_timeout(
 		&private->data_ready, ZPA2326_CONVERSION_JIFFIES);
-	if (ret > 0)
+	if (timeout > 0)
 		/*
 		 * Interrupt handler completed before timeout: return operation
 		 * status.
@@ -882,13 +883,15 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
 	/* Clear all interrupts just to be sure. */
 	regmap_read(private->regmap, ZPA2326_INT_SOURCE_REG, &val);
 
-	if (!ret)
+	if (!timeout) {
 		/* Timed out. */
+		zpa2326_warn(indio_dev, "no one shot interrupt occurred (%ld)",
+			     timeout);
 		ret = -ETIME;
-
-	if (ret != -ERESTARTSYS)
-		zpa2326_warn(indio_dev, "no one shot interrupt occurred (%d)",
-			     ret);
+	} else if (timeout < 0) {
+		zpa2326_warn(indio_dev, "wait for one shot interrupt canceled");
+		ret = -ERESTARTSYS;
+	}
 
 	return ret;
 }
-- 
2.1.4

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

* Re: [PATCH RFC] iio: pressure: zpa2326: report interrupted case as failure
  2017-05-14  8:43 [PATCH RFC] iio: pressure: zpa2326: report interrupted case as failure Nicholas Mc Guire
@ 2017-05-14  9:46 ` Peter Meerwald-Stadler
  2017-05-14 11:29   ` Nicholas Mc Guire
  2017-05-14 14:29   ` Jonathan Cameron
  2017-07-04 10:40 ` Geert Uytterhoeven
  1 sibling, 2 replies; 12+ messages in thread
From: Peter Meerwald-Stadler @ 2017-05-14  9:46 UTC (permalink / raw)
  To: Nicholas Mc Guire
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	simran singhal, Arnd Bergmann, Gregor Boirie, linux-iio,
	linux-kernel


> If the timeout-case prints a warning message then probably the interrupted
> case should also. Further, wait_for_completion_interruptible_timeout()
> returns long not int. 
> 
> Fixes: commit 03b262f2bbf4 ("iio:pressure: initial zpa2326 barometer support")
> Signed-off-by: Nicholas Mc Guire <der.herr@hofr.at>

this is actually a v2, looks good to me

> ---
> 
> The original control-flow was technically not wrong just confusing and a bit 
> complicated. Not clear if reporting the interrupted case actually is useful,
> but given that the timeout is relatively long (200ms) it is not that unlikely
> so differentiating the cases seems helpful.
> 
> Patch was compile-tested with: x86_64_defconfig + CONFIG_IIO=m, CONFIG_ZPA2326=m
> 
> Patch is against v4.11 (localversion-next is next-20170512)
> 
>  drivers/iio/pressure/zpa2326.c | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
> index e58a0ad..617926f 100644
> --- a/drivers/iio/pressure/zpa2326.c
> +++ b/drivers/iio/pressure/zpa2326.c
> @@ -867,12 +867,13 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
>  {
>  	int          ret;
>  	unsigned int val;
> +	long     timeout;
>  
>  	zpa2326_dbg(indio_dev, "waiting for one shot completion interrupt");
>  
> -	ret = wait_for_completion_interruptible_timeout(
> +	timeout = wait_for_completion_interruptible_timeout(
>  		&private->data_ready, ZPA2326_CONVERSION_JIFFIES);
> -	if (ret > 0)
> +	if (timeout > 0)
>  		/*
>  		 * Interrupt handler completed before timeout: return operation
>  		 * status.
> @@ -882,13 +883,15 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
>  	/* Clear all interrupts just to be sure. */
>  	regmap_read(private->regmap, ZPA2326_INT_SOURCE_REG, &val);
>  
> -	if (!ret)
> +	if (!timeout) {
>  		/* Timed out. */
> +		zpa2326_warn(indio_dev, "no one shot interrupt occurred (%ld)",
> +			     timeout);
>  		ret = -ETIME;
> -
> -	if (ret != -ERESTARTSYS)
> -		zpa2326_warn(indio_dev, "no one shot interrupt occurred (%d)",
> -			     ret);
> +	} else if (timeout < 0) {
> +		zpa2326_warn(indio_dev, "wait for one shot interrupt canceled");
> +		ret = -ERESTARTSYS;
> +	}
>  
>  	return ret;
>  }
> 

-- 

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

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

* Re: [PATCH RFC] iio: pressure: zpa2326: report interrupted case as failure
  2017-05-14  9:46 ` Peter Meerwald-Stadler
@ 2017-05-14 11:29   ` Nicholas Mc Guire
  2017-05-14 14:29   ` Jonathan Cameron
  1 sibling, 0 replies; 12+ messages in thread
From: Nicholas Mc Guire @ 2017-05-14 11:29 UTC (permalink / raw)
  To: Peter Meerwald-Stadler
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	simran singhal, Arnd Bergmann, Gregor Boirie, linux-iio,
	linux-kernel

On Sun, May 14, 2017 at 11:46:58AM +0200, Peter Meerwald-Stadler wrote:
> 
> > If the timeout-case prints a warning message then probably the interrupted
> > case should also. Further, wait_for_completion_interruptible_timeout()
> > returns long not int. 
> > 
> > Fixes: commit 03b262f2bbf4 ("iio:pressure: initial zpa2326 barometer support")
> > Signed-off-by: Nicholas Mc Guire <der.herr@hofr.at>
> 
> this is actually a v2, looks good to me

yup - I was just not clear if I should have marked is as V2
as not only the subject did change (simply because my first
assumption that the control-flow was buggy was wrong) and if
it would have been marked as V2 with no equivalent original
Patch would that make much sense ?

If it does, I´ll resend with a V2 tag and ref to the original
(wrong) Patch.

Thanks for the review 

> 
> > ---
> > 
> > The original control-flow was technically not wrong just confusing and a bit 
> > complicated. Not clear if reporting the interrupted case actually is useful,
> > but given that the timeout is relatively long (200ms) it is not that unlikely
> > so differentiating the cases seems helpful.
> > 
> > Patch was compile-tested with: x86_64_defconfig + CONFIG_IIO=m, CONFIG_ZPA2326=m
> > 
> > Patch is against v4.11 (localversion-next is next-20170512)
> > 
> >  drivers/iio/pressure/zpa2326.c | 17 ++++++++++-------
> >  1 file changed, 10 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
> > index e58a0ad..617926f 100644
> > --- a/drivers/iio/pressure/zpa2326.c
> > +++ b/drivers/iio/pressure/zpa2326.c
> > @@ -867,12 +867,13 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
> >  {
> >  	int          ret;
> >  	unsigned int val;
> > +	long     timeout;
> >  
> >  	zpa2326_dbg(indio_dev, "waiting for one shot completion interrupt");
> >  
> > -	ret = wait_for_completion_interruptible_timeout(
> > +	timeout = wait_for_completion_interruptible_timeout(
> >  		&private->data_ready, ZPA2326_CONVERSION_JIFFIES);
> > -	if (ret > 0)
> > +	if (timeout > 0)
> >  		/*
> >  		 * Interrupt handler completed before timeout: return operation
> >  		 * status.
> > @@ -882,13 +883,15 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
> >  	/* Clear all interrupts just to be sure. */
> >  	regmap_read(private->regmap, ZPA2326_INT_SOURCE_REG, &val);
> >  
> > -	if (!ret)
> > +	if (!timeout) {
> >  		/* Timed out. */
> > +		zpa2326_warn(indio_dev, "no one shot interrupt occurred (%ld)",
> > +			     timeout);
> >  		ret = -ETIME;
> > -
> > -	if (ret != -ERESTARTSYS)
> > -		zpa2326_warn(indio_dev, "no one shot interrupt occurred (%d)",
> > -			     ret);
> > +	} else if (timeout < 0) {
> > +		zpa2326_warn(indio_dev, "wait for one shot interrupt canceled");
> > +		ret = -ERESTARTSYS;
> > +	}
> >  
> >  	return ret;
> >  }
> > 
> 
> -- 
>
thx!
hofrat 

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

* Re: [PATCH RFC] iio: pressure: zpa2326: report interrupted case as failure
  2017-05-14  9:46 ` Peter Meerwald-Stadler
  2017-05-14 11:29   ` Nicholas Mc Guire
@ 2017-05-14 14:29   ` Jonathan Cameron
  1 sibling, 0 replies; 12+ messages in thread
From: Jonathan Cameron @ 2017-05-14 14:29 UTC (permalink / raw)
  To: Peter Meerwald-Stadler, Nicholas Mc Guire
  Cc: Hartmut Knaack, Lars-Peter Clausen, simran singhal,
	Arnd Bergmann, Gregor Boirie, linux-iio, linux-kernel

On 14/05/17 10:46, Peter Meerwald-Stadler wrote:
> 
>> If the timeout-case prints a warning message then probably the interrupted
>> case should also. Further, wait_for_completion_interruptible_timeout()
>> returns long not int.
>>
>> Fixes: commit 03b262f2bbf4 ("iio:pressure: initial zpa2326 barometer support")
>> Signed-off-by: Nicholas Mc Guire <der.herr@hofr.at>
> 
> this is actually a v2, looks good to me
A formal ack would be good!  Anyhow, I'll take that as an informal one.

A typo in the error message that I've fixed.

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

BTW I don't think this one really should have been an RFC. It's a clear
tidy up to some confusing code being proposed for inclusion rather than
to start a discussion!

Jonathan
> 
>> ---
>>
>> The original control-flow was technically not wrong just confusing and a bit
>> complicated. Not clear if reporting the interrupted case actually is useful,
>> but given that the timeout is relatively long (200ms) it is not that unlikely
>> so differentiating the cases seems helpful.
>>
>> Patch was compile-tested with: x86_64_defconfig + CONFIG_IIO=m, CONFIG_ZPA2326=m
>>
>> Patch is against v4.11 (localversion-next is next-20170512)
>>
>>   drivers/iio/pressure/zpa2326.c | 17 ++++++++++-------
>>   1 file changed, 10 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
>> index e58a0ad..617926f 100644
>> --- a/drivers/iio/pressure/zpa2326.c
>> +++ b/drivers/iio/pressure/zpa2326.c
>> @@ -867,12 +867,13 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
>>   {
>>   	int          ret;
>>   	unsigned int val;
>> +	long     timeout;
>>   
>>   	zpa2326_dbg(indio_dev, "waiting for one shot completion interrupt");
>>   
>> -	ret = wait_for_completion_interruptible_timeout(
>> +	timeout = wait_for_completion_interruptible_timeout(
>>   		&private->data_ready, ZPA2326_CONVERSION_JIFFIES);
>> -	if (ret > 0)
>> +	if (timeout > 0)
>>   		/*
>>   		 * Interrupt handler completed before timeout: return operation
>>   		 * status.
>> @@ -882,13 +883,15 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
>>   	/* Clear all interrupts just to be sure. */
>>   	regmap_read(private->regmap, ZPA2326_INT_SOURCE_REG, &val);
>>   
>> -	if (!ret)
>> +	if (!timeout) {
>>   		/* Timed out. */
>> +		zpa2326_warn(indio_dev, "no one shot interrupt occurred (%ld)",
>> +			     timeout);
>>   		ret = -ETIME;
>> -
>> -	if (ret != -ERESTARTSYS)
>> -		zpa2326_warn(indio_dev, "no one shot interrupt occurred (%d)",
>> -			     ret);
>> +	} else if (timeout < 0) {
>> +		zpa2326_warn(indio_dev, "wait for one shot interrupt canceled");
cancelled. I'll fix that.
>> +		ret = -ERESTARTSYS;
>> +	}
>>   
>>   	return ret;
>>   }
>>
> 

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

* Re: [PATCH RFC] iio: pressure: zpa2326: report interrupted case as failure
  2017-05-14  8:43 [PATCH RFC] iio: pressure: zpa2326: report interrupted case as failure Nicholas Mc Guire
  2017-05-14  9:46 ` Peter Meerwald-Stadler
@ 2017-07-04 10:40 ` Geert Uytterhoeven
  2017-07-04 19:08   ` Jonathan Cameron
  1 sibling, 1 reply; 12+ messages in thread
From: Geert Uytterhoeven @ 2017-07-04 10:40 UTC (permalink / raw)
  To: Nicholas Mc Guire
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, simran singhal, Arnd Bergmann,
	Gregor Boirie, linux-iio, linux-kernel

Hi Nicholas,

On Sun, May 14, 2017 at 10:43 AM, Nicholas Mc Guire <der.herr@hofr.at> wrote:
> If the timeout-case prints a warning message then probably the interrupted
> case should also. Further, wait_for_completion_interruptible_timeout()
> returns long not int.
>
> Fixes: commit 03b262f2bbf4 ("iio:pressure: initial zpa2326 barometer support")
> Signed-off-by: Nicholas Mc Guire <der.herr@hofr.at>
> ---
>
> The original control-flow was technically not wrong just confusing and a bit
> complicated. Not clear if reporting the interrupted case actually is useful,
> but given that the timeout is relatively long (200ms) it is not that unlikely
> so differentiating the cases seems helpful.
>
> Patch was compile-tested with: x86_64_defconfig + CONFIG_IIO=m, CONFIG_ZPA2326=m
>
> Patch is against v4.11 (localversion-next is next-20170512)
>
>  drivers/iio/pressure/zpa2326.c | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
> index e58a0ad..617926f 100644
> --- a/drivers/iio/pressure/zpa2326.c
> +++ b/drivers/iio/pressure/zpa2326.c
> @@ -867,12 +867,13 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
>  {
>         int          ret;
>         unsigned int val;
> +       long     timeout;
>
>         zpa2326_dbg(indio_dev, "waiting for one shot completion interrupt");
>
> -       ret = wait_for_completion_interruptible_timeout(
> +       timeout = wait_for_completion_interruptible_timeout(
>                 &private->data_ready, ZPA2326_CONVERSION_JIFFIES);
> -       if (ret > 0)
> +       if (timeout > 0)

Check for strict positive timeout.

>                 /*
>                  * Interrupt handler completed before timeout: return operation
>                  * status.
> @@ -882,13 +883,15 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
>         /* Clear all interrupts just to be sure. */
>         regmap_read(private->regmap, ZPA2326_INT_SOURCE_REG, &val);
>
> -       if (!ret)
> +       if (!timeout) {

Check for zero timeout.

>                 /* Timed out. */
> +               zpa2326_warn(indio_dev, "no one shot interrupt occurred (%ld)",
> +                            timeout);
>                 ret = -ETIME;
> -
> -       if (ret != -ERESTARTSYS)
> -               zpa2326_warn(indio_dev, "no one shot interrupt occurred (%d)",
> -                            ret);
> +       } else if (timeout < 0) {

So if we get here, timeout is always strict negative, so the check can
be removed.

> +               zpa2326_warn(indio_dev, "wait for one shot interrupt canceled");
> +               ret = -ERESTARTSYS;
> +       }
>
>         return ret;

But gcc-4.1.2 is not smart enough:

drivers/iio/pressure/zpa2326.c:868: warning: ‘ret’ may be used
uninitialized in this function

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH RFC] iio: pressure: zpa2326: report interrupted case as failure
  2017-07-04 10:40 ` Geert Uytterhoeven
@ 2017-07-04 19:08   ` Jonathan Cameron
  2017-07-05  7:37     ` Nicholas Mc Guire
  0 siblings, 1 reply; 12+ messages in thread
From: Jonathan Cameron @ 2017-07-04 19:08 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Nicholas Mc Guire, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, simran singhal, Arnd Bergmann,
	Gregor Boirie, linux-iio, linux-kernel

On Tue, 4 Jul 2017 12:40:33 +0200
Geert Uytterhoeven <geert@linux-m68k.org> wrote:

> Hi Nicholas,
> 
> On Sun, May 14, 2017 at 10:43 AM, Nicholas Mc Guire <der.herr@hofr.at> wrote:
> > If the timeout-case prints a warning message then probably the interrupted
> > case should also. Further, wait_for_completion_interruptible_timeout()
> > returns long not int.
> >
> > Fixes: commit 03b262f2bbf4 ("iio:pressure: initial zpa2326 barometer support")
> > Signed-off-by: Nicholas Mc Guire <der.herr@hofr.at>
> > ---
> >
> > The original control-flow was technically not wrong just confusing and a bit
> > complicated. Not clear if reporting the interrupted case actually is useful,
> > but given that the timeout is relatively long (200ms) it is not that unlikely
> > so differentiating the cases seems helpful.
> >
> > Patch was compile-tested with: x86_64_defconfig + CONFIG_IIO=m, CONFIG_ZPA2326=m
> >
> > Patch is against v4.11 (localversion-next is next-20170512)
> >
> >  drivers/iio/pressure/zpa2326.c | 17 ++++++++++-------
> >  1 file changed, 10 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
> > index e58a0ad..617926f 100644
> > --- a/drivers/iio/pressure/zpa2326.c
> > +++ b/drivers/iio/pressure/zpa2326.c
> > @@ -867,12 +867,13 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
> >  {
> >         int          ret;
> >         unsigned int val;
> > +       long     timeout;
> >
> >         zpa2326_dbg(indio_dev, "waiting for one shot completion interrupt");
> >
> > -       ret = wait_for_completion_interruptible_timeout(
> > +       timeout = wait_for_completion_interruptible_timeout(
> >                 &private->data_ready, ZPA2326_CONVERSION_JIFFIES);
> > -       if (ret > 0)
> > +       if (timeout > 0)  
> 
> Check for strict positive timeout.
> 
> >                 /*
> >                  * Interrupt handler completed before timeout: return operation
> >                  * status.
> > @@ -882,13 +883,15 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
> >         /* Clear all interrupts just to be sure. */
> >         regmap_read(private->regmap, ZPA2326_INT_SOURCE_REG, &val);
> >
> > -       if (!ret)
> > +       if (!timeout) {  
> 
> Check for zero timeout.
> 
> >                 /* Timed out. */
> > +               zpa2326_warn(indio_dev, "no one shot interrupt occurred (%ld)",
> > +                            timeout);
> >                 ret = -ETIME;
> > -
> > -       if (ret != -ERESTARTSYS)
> > -               zpa2326_warn(indio_dev, "no one shot interrupt occurred (%d)",
> > -                            ret);
> > +       } else if (timeout < 0) {  
> 
> So if we get here, timeout is always strict negative, so the check can
> be removed.
> 
> > +               zpa2326_warn(indio_dev, "wait for one shot interrupt canceled");
> > +               ret = -ERESTARTSYS;
> > +       }
> >
> >         return ret;  
> 
> But gcc-4.1.2 is not smart enough:
> 
> drivers/iio/pressure/zpa2326.c:868: warning: ‘ret’ may be used
> uninitialized in this function
Good analysis.  Care to send the obvious patch?

J
> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
>                                 -- Linus Torvalds
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH RFC] iio: pressure: zpa2326: report interrupted case as failure
  2017-07-04 19:08   ` Jonathan Cameron
@ 2017-07-05  7:37     ` Nicholas Mc Guire
  2017-07-05  8:02       ` Geert Uytterhoeven
  2017-07-05  8:06       ` Jonathan Cameron
  0 siblings, 2 replies; 12+ messages in thread
From: Nicholas Mc Guire @ 2017-07-05  7:37 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Geert Uytterhoeven, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, simran singhal, Arnd Bergmann,
	Gregor Boirie, linux-iio, linux-kernel

On Tue, Jul 04, 2017 at 08:08:53PM +0100, Jonathan Cameron wrote:
> On Tue, 4 Jul 2017 12:40:33 +0200
> Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> 
> > Hi Nicholas,
> > 
> > On Sun, May 14, 2017 at 10:43 AM, Nicholas Mc Guire <der.herr@hofr.at> wrote:
> > > If the timeout-case prints a warning message then probably the interrupted
> > > case should also. Further, wait_for_completion_interruptible_timeout()
> > > returns long not int.
> > >
> > > Fixes: commit 03b262f2bbf4 ("iio:pressure: initial zpa2326 barometer support")
> > > Signed-off-by: Nicholas Mc Guire <der.herr@hofr.at>
> > > ---
> > >
> > > The original control-flow was technically not wrong just confusing and a bit
> > > complicated. Not clear if reporting the interrupted case actually is useful,
> > > but given that the timeout is relatively long (200ms) it is not that unlikely
> > > so differentiating the cases seems helpful.
> > >
> > > Patch was compile-tested with: x86_64_defconfig + CONFIG_IIO=m, CONFIG_ZPA2326=m
> > >
> > > Patch is against v4.11 (localversion-next is next-20170512)
> > >
> > >  drivers/iio/pressure/zpa2326.c | 17 ++++++++++-------
> > >  1 file changed, 10 insertions(+), 7 deletions(-)
> > >
> > > diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
> > > index e58a0ad..617926f 100644
> > > --- a/drivers/iio/pressure/zpa2326.c
> > > +++ b/drivers/iio/pressure/zpa2326.c
> > > @@ -867,12 +867,13 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
> > >  {
> > >         int          ret;
> > >         unsigned int val;
> > > +       long     timeout;
> > >
> > >         zpa2326_dbg(indio_dev, "waiting for one shot completion interrupt");
> > >
> > > -       ret = wait_for_completion_interruptible_timeout(
> > > +       timeout = wait_for_completion_interruptible_timeout(
> > >                 &private->data_ready, ZPA2326_CONVERSION_JIFFIES);
> > > -       if (ret > 0)
> > > +       if (timeout > 0)  
> > 
> > Check for strict positive timeout.
> > 
> > >                 /*
> > >                  * Interrupt handler completed before timeout: return operation
> > >                  * status.
> > > @@ -882,13 +883,15 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
> > >         /* Clear all interrupts just to be sure. */
> > >         regmap_read(private->regmap, ZPA2326_INT_SOURCE_REG, &val);
> > >
> > > -       if (!ret)
> > > +       if (!timeout) {  
> > 
> > Check for zero timeout.
> > 
> > >                 /* Timed out. */
> > > +               zpa2326_warn(indio_dev, "no one shot interrupt occurred (%ld)",
> > > +                            timeout);
> > >                 ret = -ETIME;
> > > -
> > > -       if (ret != -ERESTARTSYS)
> > > -               zpa2326_warn(indio_dev, "no one shot interrupt occurred (%d)",
> > > -                            ret);
> > > +       } else if (timeout < 0) {  
> > 
> > So if we get here, timeout is always strict negative, so the check can
> > be removed.
> > 
> > > +               zpa2326_warn(indio_dev, "wait for one shot interrupt canceled");
> > > +               ret = -ERESTARTSYS;
> > > +       }
> > >
> > >         return ret;  
> > 
> > But gcc-4.1.2 is not smart enough:
> > 
> > drivers/iio/pressure/zpa2326.c:868: warning: ???ret??? may be used
> > uninitialized in this function
> Good analysis.  Care to send the obvious patch?
> 
Thanks Geert for finding that - yes ret needs to be 
initialized to 0 here, success case as documented in 
the header of zpa2326_wait_oneshot_completion - 
interestingly enough gcc gcc (Debian 4.9.2-10) 4.9.2 
does not flag this uninitioalized variable !

thx!
hofrat

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

* Re: [PATCH RFC] iio: pressure: zpa2326: report interrupted case as failure
  2017-07-05  7:37     ` Nicholas Mc Guire
@ 2017-07-05  8:02       ` Geert Uytterhoeven
  2017-07-05  8:55         ` Nicholas Mc Guire
  2017-07-05  8:06       ` Jonathan Cameron
  1 sibling, 1 reply; 12+ messages in thread
From: Geert Uytterhoeven @ 2017-07-05  8:02 UTC (permalink / raw)
  To: Nicholas Mc Guire
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, simran singhal, Arnd Bergmann,
	Gregor Boirie, linux-iio, linux-kernel

Hi Nicholas,

On Wed, Jul 5, 2017 at 9:37 AM, Nicholas Mc Guire <der.herr@hofr.at> wrote:
> On Tue, Jul 04, 2017 at 08:08:53PM +0100, Jonathan Cameron wrote:
>> On Tue, 4 Jul 2017 12:40:33 +0200
>> Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>> > On Sun, May 14, 2017 at 10:43 AM, Nicholas Mc Guire <der.herr@hofr.at> wrote:
>> > > If the timeout-case prints a warning message then probably the interrupted
>> > > case should also. Further, wait_for_completion_interruptible_timeout()
>> > > returns long not int.
>> > >
>> > > Fixes: commit 03b262f2bbf4 ("iio:pressure: initial zpa2326 barometer support")
>> > > Signed-off-by: Nicholas Mc Guire <der.herr@hofr.at>
>> > > ---
>> > >
>> > > The original control-flow was technically not wrong just confusing and a bit
>> > > complicated. Not clear if reporting the interrupted case actually is useful,
>> > > but given that the timeout is relatively long (200ms) it is not that unlikely
>> > > so differentiating the cases seems helpful.
>> > >
>> > > Patch was compile-tested with: x86_64_defconfig + CONFIG_IIO=m, CONFIG_ZPA2326=m
>> > >
>> > > Patch is against v4.11 (localversion-next is next-20170512)
>> > >
>> > >  drivers/iio/pressure/zpa2326.c | 17 ++++++++++-------
>> > >  1 file changed, 10 insertions(+), 7 deletions(-)
>> > >
>> > > diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
>> > > index e58a0ad..617926f 100644
>> > > --- a/drivers/iio/pressure/zpa2326.c
>> > > +++ b/drivers/iio/pressure/zpa2326.c
>> > > @@ -867,12 +867,13 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
>> > >  {
>> > >         int          ret;
>> > >         unsigned int val;
>> > > +       long     timeout;
>> > >
>> > >         zpa2326_dbg(indio_dev, "waiting for one shot completion interrupt");
>> > >
>> > > -       ret = wait_for_completion_interruptible_timeout(
>> > > +       timeout = wait_for_completion_interruptible_timeout(
>> > >                 &private->data_ready, ZPA2326_CONVERSION_JIFFIES);
>> > > -       if (ret > 0)
>> > > +       if (timeout > 0)
>> >
>> > Check for strict positive timeout.
>> >
>> > >                 /*
>> > >                  * Interrupt handler completed before timeout: return operation
>> > >                  * status.
>> > > @@ -882,13 +883,15 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
>> > >         /* Clear all interrupts just to be sure. */
>> > >         regmap_read(private->regmap, ZPA2326_INT_SOURCE_REG, &val);
>> > >
>> > > -       if (!ret)
>> > > +       if (!timeout) {
>> >
>> > Check for zero timeout.
>> >
>> > >                 /* Timed out. */
>> > > +               zpa2326_warn(indio_dev, "no one shot interrupt occurred (%ld)",
>> > > +                            timeout);
>> > >                 ret = -ETIME;
>> > > -
>> > > -       if (ret != -ERESTARTSYS)
>> > > -               zpa2326_warn(indio_dev, "no one shot interrupt occurred (%d)",
>> > > -                            ret);
>> > > +       } else if (timeout < 0) {
>> >
>> > So if we get here, timeout is always strict negative, so the check can
>> > be removed.
>> >
>> > > +               zpa2326_warn(indio_dev, "wait for one shot interrupt canceled");
>> > > +               ret = -ERESTARTSYS;
>> > > +       }
>> > >
>> > >         return ret;
>> >
>> > But gcc-4.1.2 is not smart enough:
>> >
>> > drivers/iio/pressure/zpa2326.c:868: warning: ???ret??? may be used
>> > uninitialized in this function
>> Good analysis.  Care to send the obvious patch?
>>
> Thanks Geert for finding that - yes ret needs to be
> initialized to 0 here, success case as documented in
> the header of zpa2326_wait_oneshot_completion -

No, ret does not need to be initialized to 0, as it would prevent the warning
from reappearing in case of future logic errors.

Instead the last "if" should be removed, as it's always true.
Will send a patch, as requested by Jonathan.

> interestingly enough gcc gcc (Debian 4.9.2-10) 4.9.2
> does not flag this uninitioalized variable !

Only very old or very new versions of gcc do that.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH RFC] iio: pressure: zpa2326: report interrupted case as failure
  2017-07-05  7:37     ` Nicholas Mc Guire
  2017-07-05  8:02       ` Geert Uytterhoeven
@ 2017-07-05  8:06       ` Jonathan Cameron
  1 sibling, 0 replies; 12+ messages in thread
From: Jonathan Cameron @ 2017-07-05  8:06 UTC (permalink / raw)
  To: Nicholas Mc Guire
  Cc: Jonathan Cameron, Geert Uytterhoeven, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler, simran singhal,
	Arnd Bergmann, Gregor Boirie, linux-iio, linux-kernel

On Wed, 5 Jul 2017 07:37:05 +0000
Nicholas Mc Guire <der.herr@hofr.at> wrote:

> On Tue, Jul 04, 2017 at 08:08:53PM +0100, Jonathan Cameron wrote:
> > On Tue, 4 Jul 2017 12:40:33 +0200
> > Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> >   
> > > Hi Nicholas,
> > > 
> > > On Sun, May 14, 2017 at 10:43 AM, Nicholas Mc Guire
> > > <der.herr@hofr.at> wrote:  
> > > > If the timeout-case prints a warning message then probably the
> > > > interrupted case should also. Further,
> > > > wait_for_completion_interruptible_timeout() returns long not
> > > > int.
> > > >
> > > > Fixes: commit 03b262f2bbf4 ("iio:pressure: initial zpa2326
> > > > barometer support") Signed-off-by: Nicholas Mc Guire
> > > > <der.herr@hofr.at> ---
> > > >
> > > > The original control-flow was technically not wrong just
> > > > confusing and a bit complicated. Not clear if reporting the
> > > > interrupted case actually is useful, but given that the timeout
> > > > is relatively long (200ms) it is not that unlikely so
> > > > differentiating the cases seems helpful.
> > > >
> > > > Patch was compile-tested with: x86_64_defconfig + CONFIG_IIO=m,
> > > > CONFIG_ZPA2326=m
> > > >
> > > > Patch is against v4.11 (localversion-next is next-20170512)
> > > >
> > > >  drivers/iio/pressure/zpa2326.c | 17 ++++++++++-------
> > > >  1 file changed, 10 insertions(+), 7 deletions(-)
> > > >
> > > > diff --git a/drivers/iio/pressure/zpa2326.c
> > > > b/drivers/iio/pressure/zpa2326.c index e58a0ad..617926f 100644
> > > > --- a/drivers/iio/pressure/zpa2326.c
> > > > +++ b/drivers/iio/pressure/zpa2326.c
> > > > @@ -867,12 +867,13 @@ static int
> > > > zpa2326_wait_oneshot_completion(const struct iio_dev
> > > > *indio_dev, { int          ret;
> > > >         unsigned int val;
> > > > +       long     timeout;
> > > >
> > > >         zpa2326_dbg(indio_dev, "waiting for one shot completion
> > > > interrupt");
> > > >
> > > > -       ret = wait_for_completion_interruptible_timeout(
> > > > +       timeout = wait_for_completion_interruptible_timeout(
> > > >                 &private->data_ready,
> > > > ZPA2326_CONVERSION_JIFFIES);
> > > > -       if (ret > 0)
> > > > +       if (timeout > 0)    
> > > 
> > > Check for strict positive timeout.
> > >   
> > > >                 /*
> > > >                  * Interrupt handler completed before timeout:
> > > > return operation
> > > >                  * status.
> > > > @@ -882,13 +883,15 @@ static int
> > > > zpa2326_wait_oneshot_completion(const struct iio_dev
> > > > *indio_dev, /* Clear all interrupts just to be sure. */
> > > > regmap_read(private->regmap, ZPA2326_INT_SOURCE_REG, &val);
> > > >
> > > > -       if (!ret)
> > > > +       if (!timeout) {    
> > > 
> > > Check for zero timeout.
> > >   
> > > >                 /* Timed out. */
> > > > +               zpa2326_warn(indio_dev, "no one shot interrupt
> > > > occurred (%ld)",
> > > > +                            timeout);
> > > >                 ret = -ETIME;
> > > > -
> > > > -       if (ret != -ERESTARTSYS)
> > > > -               zpa2326_warn(indio_dev, "no one shot interrupt
> > > > occurred (%d)",
> > > > -                            ret);
> > > > +       } else if (timeout < 0) {    
> > > 
> > > So if we get here, timeout is always strict negative, so the
> > > check can be removed.
> > >   
> > > > +               zpa2326_warn(indio_dev, "wait for one shot
> > > > interrupt canceled");
> > > > +               ret = -ERESTARTSYS;
> > > > +       }
> > > >
> > > >         return ret;    
> > > 
> > > But gcc-4.1.2 is not smart enough:
> > > 
> > > drivers/iio/pressure/zpa2326.c:868: warning: ???ret??? may be used
> > > uninitialized in this function  
> > Good analysis.  Care to send the obvious patch?
> >   
> Thanks Geert for finding that - yes ret needs to be 
> initialized to 0 here, success case as documented in 
> the header of zpa2326_wait_oneshot_completion - 
> interestingly enough gcc gcc (Debian 4.9.2-10) 4.9.2 
> does not flag this uninitioalized variable !
I think Geert's analysis also suggests that you can just drop the last
conditional without changing the code. gcc should be fine with that

Jonathan
> 
> thx!
> hofrat
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio"
> in the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH RFC] iio: pressure: zpa2326: report interrupted case as failure
  2017-07-05  8:02       ` Geert Uytterhoeven
@ 2017-07-05  8:55         ` Nicholas Mc Guire
  2017-07-05 10:06           ` Jonathan Cameron
  0 siblings, 1 reply; 12+ messages in thread
From: Nicholas Mc Guire @ 2017-07-05  8:55 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, simran singhal, Arnd Bergmann,
	Gregor Boirie, linux-iio, linux-kernel

On Wed, Jul 05, 2017 at 10:02:17AM +0200, Geert Uytterhoeven wrote:
> Hi Nicholas,
> 
> On Wed, Jul 5, 2017 at 9:37 AM, Nicholas Mc Guire <der.herr@hofr.at> wrote:
> > On Tue, Jul 04, 2017 at 08:08:53PM +0100, Jonathan Cameron wrote:
> >> On Tue, 4 Jul 2017 12:40:33 +0200
> >> Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> >> > On Sun, May 14, 2017 at 10:43 AM, Nicholas Mc Guire <der.herr@hofr.at> wrote:
> >> > > If the timeout-case prints a warning message then probably the interrupted
> >> > > case should also. Further, wait_for_completion_interruptible_timeout()
> >> > > returns long not int.
> >> > >
> >> > > Fixes: commit 03b262f2bbf4 ("iio:pressure: initial zpa2326 barometer support")
> >> > > Signed-off-by: Nicholas Mc Guire <der.herr@hofr.at>
> >> > > ---
> >> > >
> >> > > The original control-flow was technically not wrong just confusing and a bit
> >> > > complicated. Not clear if reporting the interrupted case actually is useful,
> >> > > but given that the timeout is relatively long (200ms) it is not that unlikely
> >> > > so differentiating the cases seems helpful.
> >> > >
> >> > > Patch was compile-tested with: x86_64_defconfig + CONFIG_IIO=m, CONFIG_ZPA2326=m
> >> > >
> >> > > Patch is against v4.11 (localversion-next is next-20170512)
> >> > >
> >> > >  drivers/iio/pressure/zpa2326.c | 17 ++++++++++-------
> >> > >  1 file changed, 10 insertions(+), 7 deletions(-)
> >> > >
> >> > > diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
> >> > > index e58a0ad..617926f 100644
> >> > > --- a/drivers/iio/pressure/zpa2326.c
> >> > > +++ b/drivers/iio/pressure/zpa2326.c
> >> > > @@ -867,12 +867,13 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
> >> > >  {
> >> > >         int          ret;
> >> > >         unsigned int val;
> >> > > +       long     timeout;
> >> > >
> >> > >         zpa2326_dbg(indio_dev, "waiting for one shot completion interrupt");
> >> > >
> >> > > -       ret = wait_for_completion_interruptible_timeout(
> >> > > +       timeout = wait_for_completion_interruptible_timeout(
> >> > >                 &private->data_ready, ZPA2326_CONVERSION_JIFFIES);
> >> > > -       if (ret > 0)
> >> > > +       if (timeout > 0)
> >> >
> >> > Check for strict positive timeout.
> >> >
> >> > >                 /*
> >> > >                  * Interrupt handler completed before timeout: return operation
> >> > >                  * status.
> >> > > @@ -882,13 +883,15 @@ static int zpa2326_wait_oneshot_completion(const struct iio_dev   *indio_dev,
> >> > >         /* Clear all interrupts just to be sure. */
> >> > >         regmap_read(private->regmap, ZPA2326_INT_SOURCE_REG, &val);
> >> > >
> >> > > -       if (!ret)
> >> > > +       if (!timeout) {
> >> >
> >> > Check for zero timeout.
> >> >
> >> > >                 /* Timed out. */
> >> > > +               zpa2326_warn(indio_dev, "no one shot interrupt occurred (%ld)",
> >> > > +                            timeout);
> >> > >                 ret = -ETIME;
> >> > > -
> >> > > -       if (ret != -ERESTARTSYS)
> >> > > -               zpa2326_warn(indio_dev, "no one shot interrupt occurred (%d)",
> >> > > -                            ret);
> >> > > +       } else if (timeout < 0) {
> >> >
> >> > So if we get here, timeout is always strict negative, so the check can
> >> > be removed.
> >> >
> >> > > +               zpa2326_warn(indio_dev, "wait for one shot interrupt canceled");
> >> > > +               ret = -ERESTARTSYS;
> >> > > +       }
> >> > >
> >> > >         return ret;
> >> >
> >> > But gcc-4.1.2 is not smart enough:
> >> >
> >> > drivers/iio/pressure/zpa2326.c:868: warning: ???ret??? may be used
> >> > uninitialized in this function
> >> Good analysis.  Care to send the obvious patch?
> >>
> > Thanks Geert for finding that - yes ret needs to be
> > initialized to 0 here, success case as documented in
> > the header of zpa2326_wait_oneshot_completion -
> 
> No, ret does not need to be initialized to 0, as it would prevent the warning
> from reappearing in case of future logic errors.
> 
> Instead the last "if" should be removed, as it's always true.
> Will send a patch, as requested by Jonathan.
>
hmm... the if can be removed but then it would be two return statements
and one could simply drop ret all together

        if (!timeout) {
                /* Timed out. */
                zpa2326_warn(indio_dev, "no one shot interrupt occurred (%ld)",
                             timeout);
                return -ETIME;
        } 
        zpa2326_warn(indio_dev, "wait for one shot interrupt cancelled");
        return -ERESTARTSYS

but I assumed that kernel code should try to not end up
with too many exit points, in which case the if is needed
and the warning could be elimnated by initializing ret to 0
even if that is more or less usless.

> > interestingly enough gcc gcc (Debian 4.9.2-10) 4.9.2
> > does not flag this uninitioalized variable !
> 
> Only very old or very new versions of gcc do that.
>
thanks - so I need to upgrad my gcc as the compile-checking
will fail to catch uninitilized vars then, atleast in
some cases.

thx!
hofrat 

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

* Re: [PATCH RFC] iio: pressure: zpa2326: report interrupted case as failure
  2017-07-05  8:55         ` Nicholas Mc Guire
@ 2017-07-05 10:06           ` Jonathan Cameron
  2017-07-05 10:11             ` Nicholas Mc Guire
  0 siblings, 1 reply; 12+ messages in thread
From: Jonathan Cameron @ 2017-07-05 10:06 UTC (permalink / raw)
  To: Nicholas Mc Guire
  Cc: Geert Uytterhoeven, Jonathan Cameron, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler, simran singhal,
	Arnd Bergmann, Gregor Boirie, linux-iio, linux-kernel

On Wed, 5 Jul 2017 08:55:47 +0000
Nicholas Mc Guire <der.herr@hofr.at> wrote:

> On Wed, Jul 05, 2017 at 10:02:17AM +0200, Geert Uytterhoeven wrote:
> > Hi Nicholas,
> > 
> > On Wed, Jul 5, 2017 at 9:37 AM, Nicholas Mc Guire
> > <der.herr@hofr.at> wrote:  
> > > On Tue, Jul 04, 2017 at 08:08:53PM +0100, Jonathan Cameron
> > > wrote:  
> > >> On Tue, 4 Jul 2017 12:40:33 +0200
> > >> Geert Uytterhoeven <geert@linux-m68k.org> wrote:  
> > >> > On Sun, May 14, 2017 at 10:43 AM, Nicholas Mc Guire
> > >> > <der.herr@hofr.at> wrote:  
> > >> > > If the timeout-case prints a warning message then probably
> > >> > > the interrupted case should also. Further,
> > >> > > wait_for_completion_interruptible_timeout() returns long not
> > >> > > int.
> > >> > >
> > >> > > Fixes: commit 03b262f2bbf4 ("iio:pressure: initial zpa2326
> > >> > > barometer support") Signed-off-by: Nicholas Mc Guire
> > >> > > <der.herr@hofr.at> ---
> > >> > >
> > >> > > The original control-flow was technically not wrong just
> > >> > > confusing and a bit complicated. Not clear if reporting the
> > >> > > interrupted case actually is useful, but given that the
> > >> > > timeout is relatively long (200ms) it is not that unlikely
> > >> > > so differentiating the cases seems helpful.
> > >> > >
> > >> > > Patch was compile-tested with: x86_64_defconfig +
> > >> > > CONFIG_IIO=m, CONFIG_ZPA2326=m
> > >> > >
> > >> > > Patch is against v4.11 (localversion-next is next-20170512)
> > >> > >
> > >> > >  drivers/iio/pressure/zpa2326.c | 17 ++++++++++-------
> > >> > >  1 file changed, 10 insertions(+), 7 deletions(-)
> > >> > >
> > >> > > diff --git a/drivers/iio/pressure/zpa2326.c
> > >> > > b/drivers/iio/pressure/zpa2326.c index e58a0ad..617926f
> > >> > > 100644 --- a/drivers/iio/pressure/zpa2326.c
> > >> > > +++ b/drivers/iio/pressure/zpa2326.c
> > >> > > @@ -867,12 +867,13 @@ static int
> > >> > > zpa2326_wait_oneshot_completion(const struct iio_dev
> > >> > > *indio_dev, { int          ret;
> > >> > >         unsigned int val;
> > >> > > +       long     timeout;
> > >> > >
> > >> > >         zpa2326_dbg(indio_dev, "waiting for one shot
> > >> > > completion interrupt");
> > >> > >
> > >> > > -       ret = wait_for_completion_interruptible_timeout(
> > >> > > +       timeout = wait_for_completion_interruptible_timeout(
> > >> > >                 &private->data_ready,
> > >> > > ZPA2326_CONVERSION_JIFFIES);
> > >> > > -       if (ret > 0)
> > >> > > +       if (timeout > 0)  
> > >> >
> > >> > Check for strict positive timeout.
> > >> >  
> > >> > >                 /*
> > >> > >                  * Interrupt handler completed before
> > >> > > timeout: return operation
> > >> > >                  * status.
> > >> > > @@ -882,13 +883,15 @@ static int
> > >> > > zpa2326_wait_oneshot_completion(const struct iio_dev
> > >> > > *indio_dev, /* Clear all interrupts just to be sure. */
> > >> > > regmap_read(private->regmap, ZPA2326_INT_SOURCE_REG, &val);
> > >> > >
> > >> > > -       if (!ret)
> > >> > > +       if (!timeout) {  
> > >> >
> > >> > Check for zero timeout.
> > >> >  
> > >> > >                 /* Timed out. */
> > >> > > +               zpa2326_warn(indio_dev, "no one shot
> > >> > > interrupt occurred (%ld)",
> > >> > > +                            timeout);
> > >> > >                 ret = -ETIME;
> > >> > > -
> > >> > > -       if (ret != -ERESTARTSYS)
> > >> > > -               zpa2326_warn(indio_dev, "no one shot
> > >> > > interrupt occurred (%d)",
> > >> > > -                            ret);
> > >> > > +       } else if (timeout < 0) {  
> > >> >
> > >> > So if we get here, timeout is always strict negative, so the
> > >> > check can be removed.
> > >> >  
> > >> > > +               zpa2326_warn(indio_dev, "wait for one shot
> > >> > > interrupt canceled");
> > >> > > +               ret = -ERESTARTSYS;
> > >> > > +       }
> > >> > >
> > >> > >         return ret;  
> > >> >
> > >> > But gcc-4.1.2 is not smart enough:
> > >> >
> > >> > drivers/iio/pressure/zpa2326.c:868: warning: ???ret??? may be
> > >> > used uninitialized in this function  
> > >> Good analysis.  Care to send the obvious patch?
> > >>  
> > > Thanks Geert for finding that - yes ret needs to be
> > > initialized to 0 here, success case as documented in
> > > the header of zpa2326_wait_oneshot_completion -  
> > 
> > No, ret does not need to be initialized to 0, as it would prevent
> > the warning from reappearing in case of future logic errors.
> > 
> > Instead the last "if" should be removed, as it's always true.
> > Will send a patch, as requested by Jonathan.
> >  
> hmm... the if can be removed but then it would be two return
> statements and one could simply drop ret all together
> 
>         if (!timeout) {
>                 /* Timed out. */
>                 zpa2326_warn(indio_dev, "no one shot interrupt
> occurred (%ld)", timeout);
>                 return -ETIME;
>         } 
>         zpa2326_warn(indio_dev, "wait for one shot interrupt
> cancelled"); return -ERESTARTSYS
> 
> but I assumed that kernel code should try to not end up
> with too many exit points, in which case the if is needed
> and the warning could be elimnated by initializing ret to 0
> even if that is more or less usless.
Usual rule of thumb for kernel style is that if you have cleanup to
do (releasing locks etc) then it should be done at a common location.
If there is no cleanup then you should return directly.  

Jonathan
> 
> > > interestingly enough gcc gcc (Debian 4.9.2-10) 4.9.2
> > > does not flag this uninitioalized variable !  
> > 
> > Only very old or very new versions of gcc do that.
> >  
> thanks - so I need to upgrad my gcc as the compile-checking
> will fail to catch uninitilized vars then, atleast in
> some cases.
> 
> thx!
> hofrat 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio"
> in the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH RFC] iio: pressure: zpa2326: report interrupted case as failure
  2017-07-05 10:06           ` Jonathan Cameron
@ 2017-07-05 10:11             ` Nicholas Mc Guire
  0 siblings, 0 replies; 12+ messages in thread
From: Nicholas Mc Guire @ 2017-07-05 10:11 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Geert Uytterhoeven, Jonathan Cameron, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler, simran singhal,
	Arnd Bergmann, Gregor Boirie, linux-iio, linux-kernel

On Wed, Jul 05, 2017 at 06:06:09PM +0800, Jonathan Cameron wrote:
> On Wed, 5 Jul 2017 08:55:47 +0000
> Nicholas Mc Guire <der.herr@hofr.at> wrote:
> 
> > On Wed, Jul 05, 2017 at 10:02:17AM +0200, Geert Uytterhoeven wrote:
> > > Hi Nicholas,
> > > 
> > > On Wed, Jul 5, 2017 at 9:37 AM, Nicholas Mc Guire
> > > <der.herr@hofr.at> wrote:  
> > > > On Tue, Jul 04, 2017 at 08:08:53PM +0100, Jonathan Cameron
> > > > wrote:  
> > > >> On Tue, 4 Jul 2017 12:40:33 +0200
> > > >> Geert Uytterhoeven <geert@linux-m68k.org> wrote:  
> > > >> > On Sun, May 14, 2017 at 10:43 AM, Nicholas Mc Guire
> > > >> > <der.herr@hofr.at> wrote:  
> > > >> > > If the timeout-case prints a warning message then probably
> > > >> > > the interrupted case should also. Further,
> > > >> > > wait_for_completion_interruptible_timeout() returns long not
> > > >> > > int.
> > > >> > >
> > > >> > > Fixes: commit 03b262f2bbf4 ("iio:pressure: initial zpa2326
> > > >> > > barometer support") Signed-off-by: Nicholas Mc Guire
> > > >> > > <der.herr@hofr.at> ---
> > > >> > >
> > > >> > > The original control-flow was technically not wrong just
> > > >> > > confusing and a bit complicated. Not clear if reporting the
> > > >> > > interrupted case actually is useful, but given that the
> > > >> > > timeout is relatively long (200ms) it is not that unlikely
> > > >> > > so differentiating the cases seems helpful.
> > > >> > >
> > > >> > > Patch was compile-tested with: x86_64_defconfig +
> > > >> > > CONFIG_IIO=m, CONFIG_ZPA2326=m
> > > >> > >
> > > >> > > Patch is against v4.11 (localversion-next is next-20170512)
> > > >> > >
> > > >> > >  drivers/iio/pressure/zpa2326.c | 17 ++++++++++-------
> > > >> > >  1 file changed, 10 insertions(+), 7 deletions(-)
> > > >> > >
> > > >> > > diff --git a/drivers/iio/pressure/zpa2326.c
> > > >> > > b/drivers/iio/pressure/zpa2326.c index e58a0ad..617926f
> > > >> > > 100644 --- a/drivers/iio/pressure/zpa2326.c
> > > >> > > +++ b/drivers/iio/pressure/zpa2326.c
> > > >> > > @@ -867,12 +867,13 @@ static int
> > > >> > > zpa2326_wait_oneshot_completion(const struct iio_dev
> > > >> > > *indio_dev, { int          ret;
> > > >> > >         unsigned int val;
> > > >> > > +       long     timeout;
> > > >> > >
> > > >> > >         zpa2326_dbg(indio_dev, "waiting for one shot
> > > >> > > completion interrupt");
> > > >> > >
> > > >> > > -       ret = wait_for_completion_interruptible_timeout(
> > > >> > > +       timeout = wait_for_completion_interruptible_timeout(
> > > >> > >                 &private->data_ready,
> > > >> > > ZPA2326_CONVERSION_JIFFIES);
> > > >> > > -       if (ret > 0)
> > > >> > > +       if (timeout > 0)  
> > > >> >
> > > >> > Check for strict positive timeout.
> > > >> >  
> > > >> > >                 /*
> > > >> > >                  * Interrupt handler completed before
> > > >> > > timeout: return operation
> > > >> > >                  * status.
> > > >> > > @@ -882,13 +883,15 @@ static int
> > > >> > > zpa2326_wait_oneshot_completion(const struct iio_dev
> > > >> > > *indio_dev, /* Clear all interrupts just to be sure. */
> > > >> > > regmap_read(private->regmap, ZPA2326_INT_SOURCE_REG, &val);
> > > >> > >
> > > >> > > -       if (!ret)
> > > >> > > +       if (!timeout) {  
> > > >> >
> > > >> > Check for zero timeout.
> > > >> >  
> > > >> > >                 /* Timed out. */
> > > >> > > +               zpa2326_warn(indio_dev, "no one shot
> > > >> > > interrupt occurred (%ld)",
> > > >> > > +                            timeout);
> > > >> > >                 ret = -ETIME;
> > > >> > > -
> > > >> > > -       if (ret != -ERESTARTSYS)
> > > >> > > -               zpa2326_warn(indio_dev, "no one shot
> > > >> > > interrupt occurred (%d)",
> > > >> > > -                            ret);
> > > >> > > +       } else if (timeout < 0) {  
> > > >> >
> > > >> > So if we get here, timeout is always strict negative, so the
> > > >> > check can be removed.
> > > >> >  
> > > >> > > +               zpa2326_warn(indio_dev, "wait for one shot
> > > >> > > interrupt canceled");
> > > >> > > +               ret = -ERESTARTSYS;
> > > >> > > +       }
> > > >> > >
> > > >> > >         return ret;  
> > > >> >
> > > >> > But gcc-4.1.2 is not smart enough:
> > > >> >
> > > >> > drivers/iio/pressure/zpa2326.c:868: warning: ???ret??? may be
> > > >> > used uninitialized in this function  
> > > >> Good analysis.  Care to send the obvious patch?
> > > >>  
> > > > Thanks Geert for finding that - yes ret needs to be
> > > > initialized to 0 here, success case as documented in
> > > > the header of zpa2326_wait_oneshot_completion -  
> > > 
> > > No, ret does not need to be initialized to 0, as it would prevent
> > > the warning from reappearing in case of future logic errors.
> > > 
> > > Instead the last "if" should be removed, as it's always true.
> > > Will send a patch, as requested by Jonathan.
> > >  
> > hmm... the if can be removed but then it would be two return
> > statements and one could simply drop ret all together
> > 
> >         if (!timeout) {
> >                 /* Timed out. */
> >                 zpa2326_warn(indio_dev, "no one shot interrupt
> > occurred (%ld)", timeout);
> >                 return -ETIME;
> >         } 
> >         zpa2326_warn(indio_dev, "wait for one shot interrupt
> > cancelled"); return -ERESTARTSYS
> > 
> > but I assumed that kernel code should try to not end up
> > with too many exit points, in which case the if is needed
> > and the warning could be elimnated by initializing ret to 0
> > even if that is more or less usless.
> Usual rule of thumb for kernel style is that if you have cleanup to
> do (releasing locks etc) then it should be done at a common location.
> If there is no cleanup then you should return directly.  
>
yup - just rechecked "7) Centralized exiting of functions" in coding-style.rst
so the solution I posted was wrong - thanks for the clarification !

thx!
hforat

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

end of thread, other threads:[~2017-07-05 10:12 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-14  8:43 [PATCH RFC] iio: pressure: zpa2326: report interrupted case as failure Nicholas Mc Guire
2017-05-14  9:46 ` Peter Meerwald-Stadler
2017-05-14 11:29   ` Nicholas Mc Guire
2017-05-14 14:29   ` Jonathan Cameron
2017-07-04 10:40 ` Geert Uytterhoeven
2017-07-04 19:08   ` Jonathan Cameron
2017-07-05  7:37     ` Nicholas Mc Guire
2017-07-05  8:02       ` Geert Uytterhoeven
2017-07-05  8:55         ` Nicholas Mc Guire
2017-07-05 10:06           ` Jonathan Cameron
2017-07-05 10:11             ` Nicholas Mc Guire
2017-07-05  8:06       ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).