All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pwm: fix used-uninitialized warning in pwm_get()
@ 2012-07-03 20:34 Stephen Warren
  2012-07-04  5:58 ` Thierry Reding
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Warren @ 2012-07-03 20:34 UTC (permalink / raw)
  To: Thierry Reding; +Cc: linux-kernel, Stephen Warren

From: Stephen Warren <swarren@nvidia.com>

This fixes:
drivers/pwm/core.c: In function 'pwm_get':
drivers/pwm/core.c:534:15: warning: 'index' may be used uninitialized in this function

The addition to the if condition at end of the function isn't strictly
necessary to solve the warning, but does make it more obvious that the
initialization of "index" to a dummy value isn't just hiding the
problem.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
 drivers/pwm/core.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index dbab530..2b401c0 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -531,7 +531,7 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
 	struct pwm_chip *chip = NULL;
 	unsigned int best = 0;
 	struct pwm_lookup *p;
-	unsigned int index;
+	unsigned int index = -1;
 	unsigned int match;
 
 	/* look up via DT first */
@@ -588,7 +588,7 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
 		}
 	}
 
-	if (chip)
+	if (chip && index != -1)
 		pwm = pwm_request_from_chip(chip, index, con_id ?: dev_id);
 
 	mutex_unlock(&pwm_lookup_lock);
-- 
1.7.0.4


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

* Re: [PATCH] pwm: fix used-uninitialized warning in pwm_get()
  2012-07-03 20:34 [PATCH] pwm: fix used-uninitialized warning in pwm_get() Stephen Warren
@ 2012-07-04  5:58 ` Thierry Reding
  2012-07-05 15:56   ` Stephen Warren
  0 siblings, 1 reply; 4+ messages in thread
From: Thierry Reding @ 2012-07-04  5:58 UTC (permalink / raw)
  To: Stephen Warren; +Cc: linux-kernel, Stephen Warren

[-- Attachment #1: Type: text/plain, Size: 1619 bytes --]

On Tue, Jul 03, 2012 at 02:34:21PM -0600, Stephen Warren wrote:
> From: Stephen Warren <swarren@nvidia.com>
> 
> This fixes:
> drivers/pwm/core.c: In function 'pwm_get':
> drivers/pwm/core.c:534:15: warning: 'index' may be used uninitialized in this function
> 
> The addition to the if condition at end of the function isn't strictly
> necessary to solve the warning, but does make it more obvious that the
> initialization of "index" to a dummy value isn't just hiding the
> problem.

Actually this seems to be a false positive, and one that I don't see (I
use GCC 4.6.3). index will be initialized when chip is set in the loop.
My guess is that GCC 4.6.3 actually notices while your version doesn't.

Thierry

> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> ---
>  drivers/pwm/core.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> index dbab530..2b401c0 100644
> --- a/drivers/pwm/core.c
> +++ b/drivers/pwm/core.c
> @@ -531,7 +531,7 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
>  	struct pwm_chip *chip = NULL;
>  	unsigned int best = 0;
>  	struct pwm_lookup *p;
> -	unsigned int index;
> +	unsigned int index = -1;
>  	unsigned int match;
>  
>  	/* look up via DT first */
> @@ -588,7 +588,7 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
>  		}
>  	}
>  
> -	if (chip)
> +	if (chip && index != -1)
>  		pwm = pwm_request_from_chip(chip, index, con_id ?: dev_id);
>  
>  	mutex_unlock(&pwm_lookup_lock);
> -- 
> 1.7.0.4
> 
> 
> 

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH] pwm: fix used-uninitialized warning in pwm_get()
  2012-07-04  5:58 ` Thierry Reding
@ 2012-07-05 15:56   ` Stephen Warren
  2012-07-11  6:39     ` Thierry Reding
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Warren @ 2012-07-05 15:56 UTC (permalink / raw)
  To: Thierry Reding; +Cc: linux-kernel, Stephen Warren

On 07/03/2012 11:58 PM, Thierry Reding wrote:
> On Tue, Jul 03, 2012 at 02:34:21PM -0600, Stephen Warren wrote:
>> From: Stephen Warren <swarren@nvidia.com>
>> 
>> This fixes: drivers/pwm/core.c: In function 'pwm_get': 
>> drivers/pwm/core.c:534:15: warning: 'index' may be used
>> uninitialized in this function
>> 
>> The addition to the if condition at end of the function isn't
>> strictly necessary to solve the warning, but does make it more
>> obvious that the initialization of "index" to a dummy value isn't
>> just hiding the problem.
> 
> Actually this seems to be a false positive, and one that I don't
> see (I use GCC 4.6.3). index will be initialized when chip is set
> in the loop. My guess is that GCC 4.6.3 actually notices while your
> version doesn't.

Yes, it is a false-positive, which is why I was fine with just
initializing the variable to hide the warning rather than making some
other code change. I think there's still value in hiding the warning
though, so that:

a) Nobody else has to look at the warning and decide it's a false
positive and remember to ignore it.

b) The fewer warnings there are, the more likely new warnings will be
noticed and analyzed.

So I'd still argue for this change, or some other fix for the warning,
be merged.

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

* Re: [PATCH] pwm: fix used-uninitialized warning in pwm_get()
  2012-07-05 15:56   ` Stephen Warren
@ 2012-07-11  6:39     ` Thierry Reding
  0 siblings, 0 replies; 4+ messages in thread
From: Thierry Reding @ 2012-07-11  6:39 UTC (permalink / raw)
  To: Stephen Warren; +Cc: linux-kernel, Stephen Warren

[-- Attachment #1: Type: text/plain, Size: 1695 bytes --]

On Thu, Jul 05, 2012 at 09:56:50AM -0600, Stephen Warren wrote:
> On 07/03/2012 11:58 PM, Thierry Reding wrote:
> > On Tue, Jul 03, 2012 at 02:34:21PM -0600, Stephen Warren wrote:
> >> From: Stephen Warren <swarren@nvidia.com>
> >> 
> >> This fixes: drivers/pwm/core.c: In function 'pwm_get': 
> >> drivers/pwm/core.c:534:15: warning: 'index' may be used
> >> uninitialized in this function
> >> 
> >> The addition to the if condition at end of the function isn't
> >> strictly necessary to solve the warning, but does make it more
> >> obvious that the initialization of "index" to a dummy value isn't
> >> just hiding the problem.
> > 
> > Actually this seems to be a false positive, and one that I don't
> > see (I use GCC 4.6.3). index will be initialized when chip is set
> > in the loop. My guess is that GCC 4.6.3 actually notices while your
> > version doesn't.
> 
> Yes, it is a false-positive, which is why I was fine with just
> initializing the variable to hide the warning rather than making some
> other code change. I think there's still value in hiding the warning
> though, so that:
> 
> a) Nobody else has to look at the warning and decide it's a false
> positive and remember to ignore it.
> 
> b) The fewer warnings there are, the more likely new warnings will be
> noticed and analyzed.
> 
> So I'd still argue for this change, or some other fix for the warning,
> be merged.

Okay, I've applied a patch based on what you did, with a more explicit
description of what's going on. Since I didn't see the warning with my
toolchain before it would be good if you could retest and verify that it
indeed fixes the problem for you.

Thierry

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

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

end of thread, other threads:[~2012-07-11  6:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-03 20:34 [PATCH] pwm: fix used-uninitialized warning in pwm_get() Stephen Warren
2012-07-04  5:58 ` Thierry Reding
2012-07-05 15:56   ` Stephen Warren
2012-07-11  6:39     ` Thierry Reding

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.