<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>[PATCH] pwm: fix used-uninitialized warning in pwm_get()</title>
        <description> From: Stephen Warren &amp;lt;swarren@nvidia.com&amp;gt;

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 &amp;quot;index&amp;quot; to a dummy value isn't just hiding the
problem.

Signed-off-by: Stephen Warren &amp;lt;swarren@nvidia.com&amp;gt;
---
 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 &amp;amp;&amp;amp; index != -1)
 		pwm = pwm_request_from_chip(chip, index, con_id ?: dev_id);
 
 	mutex_unlock(&amp;amp;pwm_lookup_lock);
-- 
1.7.0.4

--
To unsubscribe from this list: send the line &amp;quot;unsubscribe linux-kernel&amp;quot; in
the body of a message to &amp;#109;&amp;#97;&amp;#106;&amp;#111;&amp;#114;&amp;#100;&amp;#111;&amp;#109;&amp;#111;&amp;#64;&amp;#118;&amp;#103;&amp;#101;&amp;#114;&amp;#46;&amp;#107;&amp;#101;&amp;#114;&amp;#110;&amp;#101;&amp;#108;&amp;#46;&amp;#111;&amp;#114;&amp;#103;
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/</description>
        <link>http://www.serverphorums.com/read.php?12,523368,523368#msg-523368</link>
        <lastBuildDate>Thu, 20 Jun 2013 01:59:52 +0200</lastBuildDate>
        <generator>Phorum 5.2.18</generator>
        <item>
            <guid>http://www.serverphorums.com/read.php?12,523368,527121#msg-527121</guid>
            <title>Re: [PATCH] pwm: fix used-uninitialized warning in pwm_get()</title>
            <link>http://www.serverphorums.com/read.php?12,523368,527121#msg-527121</link>
            <description><![CDATA[ On Thu, Jul 05, 2012 at 09:56:50AM -0600, Stephen Warren wrote:<br />
&gt; On 07/03/2012 11:58 PM, Thierry Reding wrote:<br />
&gt; &gt; On Tue, Jul 03, 2012 at 02:34:21PM -0600, Stephen Warren wrote:<br />
&gt; &gt;&gt; From: Stephen Warren &lt;swarren@nvidia.com&gt;<br />
&gt; &gt;&gt; <br />
&gt; &gt;&gt; This fixes: drivers/pwm/core.c: In function 'pwm_get': <br />
&gt; &gt;&gt; drivers/pwm/core.c:534:15: warning: 'index' may be used<br />
&gt; &gt;&gt; uninitialized in this function<br />
&gt; &gt;&gt; <br />
&gt; &gt;&gt; The addition to the if condition at end of the function isn't<br />
&gt; &gt;&gt; strictly necessary to solve the warning, but does make it more<br />
&gt; &gt;&gt; obvious that the initialization of &quot;index&quot; to a dummy value isn't<br />
&gt; &gt;&gt; just hiding the problem.<br />
&gt; &gt; <br />
&gt; &gt; Actually this seems to be a false positive, and one that I don't<br />
&gt; &gt; see (I use GCC 4.6.3). index will be initialized when chip is set<br />
&gt; &gt; in the loop. My guess is that GCC 4.6.3 actually notices while your<br />
&gt; &gt; version doesn't.<br />
&gt; <br />
&gt; Yes, it is a false-positive, which is why I was fine with just<br />
&gt; initializing the variable to hide the warning rather than making some<br />
&gt; other code change. I think there's still value in hiding the warning<br />
&gt; though, so that:<br />
&gt; <br />
&gt; a) Nobody else has to look at the warning and decide it's a false<br />
&gt; positive and remember to ignore it.<br />
&gt; <br />
&gt; b) The fewer warnings there are, the more likely new warnings will be<br />
&gt; noticed and analyzed.<br />
&gt; <br />
&gt; So I'd still argue for this change, or some other fix for the warning,<br />
&gt; be merged.<br />
<br />
Okay, I've applied a patch based on what you did, with a more explicit<br />
description of what's going on. Since I didn't see the warning with my<br />
toolchain before it would be good if you could retest and verify that it<br />
indeed fixes the problem for you.<br />
<br />
Thierry]]></description>
            <dc:creator>Thierry Reding</dc:creator>
            <category>Linux Kernel</category>
            <pubDate>Wed, 11 Jul 2012 08:40:03 +0200</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?12,523368,524404#msg-524404</guid>
            <title>Re: [PATCH] pwm: fix used-uninitialized warning in pwm_get()</title>
            <link>http://www.serverphorums.com/read.php?12,523368,524404#msg-524404</link>
            <description><![CDATA[ On 07/03/2012 11:58 PM, Thierry Reding wrote:<br />
&gt; On Tue, Jul 03, 2012 at 02:34:21PM -0600, Stephen Warren wrote:<br />
&gt;&gt; From: Stephen Warren &lt;swarren@nvidia.com&gt;<br />
&gt;&gt; <br />
&gt;&gt; This fixes: drivers/pwm/core.c: In function 'pwm_get': <br />
&gt;&gt; drivers/pwm/core.c:534:15: warning: 'index' may be used<br />
&gt;&gt; uninitialized in this function<br />
&gt;&gt; <br />
&gt;&gt; The addition to the if condition at end of the function isn't<br />
&gt;&gt; strictly necessary to solve the warning, but does make it more<br />
&gt;&gt; obvious that the initialization of &quot;index&quot; to a dummy value isn't<br />
&gt;&gt; just hiding the problem.<br />
&gt; <br />
&gt; Actually this seems to be a false positive, and one that I don't<br />
&gt; see (I use GCC 4.6.3). index will be initialized when chip is set<br />
&gt; in the loop. My guess is that GCC 4.6.3 actually notices while your<br />
&gt; version doesn't.<br />
<br />
Yes, it is a false-positive, which is why I was fine with just<br />
initializing the variable to hide the warning rather than making some<br />
other code change. I think there's still value in hiding the warning<br />
though, so that:<br />
<br />
a) Nobody else has to look at the warning and decide it's a false<br />
positive and remember to ignore it.<br />
<br />
b) The fewer warnings there are, the more likely new warnings will be<br />
noticed and analyzed.<br />
<br />
So I'd still argue for this change, or some other fix for the warning,<br />
be merged.<br />
--<br />
To unsubscribe from this list: send the line &quot;unsubscribe linux-kernel&quot; in<br />
the body of a message to <a href="mailto:&#109;&#97;&#106;&#111;&#114;&#100;&#111;&#109;&#111;&#64;&#118;&#103;&#101;&#114;&#46;&#107;&#101;&#114;&#110;&#101;&#108;&#46;&#111;&#114;&#103;">&#109;&#97;&#106;&#111;&#114;&#100;&#111;&#109;&#111;&#64;&#118;&#103;&#101;&#114;&#46;&#107;&#101;&#114;&#110;&#101;&#108;&#46;&#111;&#114;&#103;</a><br />
More majordomo info at  <a href="http://vger.kernel.org/majordomo-info.html" target="_blank"  rel="nofollow">http://vger.kernel.org/majordomo-info.html</a><br />
Please read the FAQ at  <a href="http://www.tux.org/lkml/" target="_blank"  rel="nofollow">http://www.tux.org/lkml/</a>]]></description>
            <dc:creator>Stephen Warren</dc:creator>
            <category>Linux Kernel</category>
            <pubDate>Thu, 05 Jul 2012 18:00:03 +0200</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?12,523368,523524#msg-523524</guid>
            <title>Re: [PATCH] pwm: fix used-uninitialized warning in pwm_get()</title>
            <link>http://www.serverphorums.com/read.php?12,523368,523524#msg-523524</link>
            <description><![CDATA[ On Tue, Jul 03, 2012 at 02:34:21PM -0600, Stephen Warren wrote:<br />
&gt; From: Stephen Warren &lt;swarren@nvidia.com&gt;<br />
&gt; <br />
&gt; This fixes:<br />
&gt; drivers/pwm/core.c: In function 'pwm_get':<br />
&gt; drivers/pwm/core.c:534:15: warning: 'index' may be used uninitialized in this function<br />
&gt; <br />
&gt; The addition to the if condition at end of the function isn't strictly<br />
&gt; necessary to solve the warning, but does make it more obvious that the<br />
&gt; initialization of &quot;index&quot; to a dummy value isn't just hiding the<br />
&gt; problem.<br />
<br />
Actually this seems to be a false positive, and one that I don't see (I<br />
use GCC 4.6.3). index will be initialized when chip is set in the loop.<br />
My guess is that GCC 4.6.3 actually notices while your version doesn't.<br />
<br />
Thierry<br />
<br />
&gt; Signed-off-by: Stephen Warren &lt;swarren@nvidia.com&gt;<br />
&gt; ---<br />
&gt;  drivers/pwm/core.c |    4 ++--<br />
&gt;  1 files changed, 2 insertions(+), 2 deletions(-)<br />
&gt; <br />
&gt; diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c<br />
&gt; index dbab530..2b401c0 100644<br />
&gt; --- a/drivers/pwm/core.c<br />
&gt; +++ b/drivers/pwm/core.c<br />
&gt; @@ -531,7 +531,7 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)<br />
&gt;  	struct pwm_chip *chip = NULL;<br />
&gt;  	unsigned int best = 0;<br />
&gt;  	struct pwm_lookup *p;<br />
&gt; -	unsigned int index;<br />
&gt; +	unsigned int index = -1;<br />
&gt;  	unsigned int match;<br />
&gt;  <br />
&gt;  	/* look up via DT first */<br />
&gt; @@ -588,7 +588,7 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)<br />
&gt;  		}<br />
&gt;  	}<br />
&gt;  <br />
&gt; -	if (chip)<br />
&gt; +	if (chip &amp;&amp; index != -1)<br />
&gt;  		pwm = pwm_request_from_chip(chip, index, con_id ?: dev_id);<br />
&gt;  <br />
&gt;  	mutex_unlock(&amp;pwm_lookup_lock);<br />
&gt; -- <br />
&gt; 1.7.0.4<br />
&gt; <br />
&gt; <br />
&gt;]]></description>
            <dc:creator>Thierry Reding</dc:creator>
            <category>Linux Kernel</category>
            <pubDate>Wed, 04 Jul 2012 08:00:01 +0200</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?12,523368,523368#msg-523368</guid>
            <title>[PATCH] pwm: fix used-uninitialized warning in pwm_get()</title>
            <link>http://www.serverphorums.com/read.php?12,523368,523368#msg-523368</link>
            <description><![CDATA[ From: Stephen Warren &lt;swarren@nvidia.com&gt;<br />
<br />
This fixes:<br />
drivers/pwm/core.c: In function 'pwm_get':<br />
drivers/pwm/core.c:534:15: warning: 'index' may be used uninitialized in this function<br />
<br />
The addition to the if condition at end of the function isn't strictly<br />
necessary to solve the warning, but does make it more obvious that the<br />
initialization of &quot;index&quot; to a dummy value isn't just hiding the<br />
problem.<br />
<br />
Signed-off-by: Stephen Warren &lt;swarren@nvidia.com&gt;<br />
---<br />
 drivers/pwm/core.c |    4 ++--<br />
 1 files changed, 2 insertions(+), 2 deletions(-)<br />
<br />
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c<br />
index dbab530..2b401c0 100644<br />
--- a/drivers/pwm/core.c<br />
+++ b/drivers/pwm/core.c<br />
@@ -531,7 +531,7 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)<br />
 	struct pwm_chip *chip = NULL;<br />
 	unsigned int best = 0;<br />
 	struct pwm_lookup *p;<br />
-	unsigned int index;<br />
+	unsigned int index = -1;<br />
 	unsigned int match;<br />
 <br />
 	/* look up via DT first */<br />
@@ -588,7 +588,7 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)<br />
 		}<br />
 	}<br />
 <br />
-	if (chip)<br />
+	if (chip &amp;&amp; index != -1)<br />
 		pwm = pwm_request_from_chip(chip, index, con_id ?: dev_id);<br />
 <br />
 	mutex_unlock(&amp;pwm_lookup_lock);<br />
-- <br />
1.7.0.4<br />
<br />
--<br />
To unsubscribe from this list: send the line &quot;unsubscribe linux-kernel&quot; in<br />
the body of a message to <a href="mailto:&#109;&#97;&#106;&#111;&#114;&#100;&#111;&#109;&#111;&#64;&#118;&#103;&#101;&#114;&#46;&#107;&#101;&#114;&#110;&#101;&#108;&#46;&#111;&#114;&#103;">&#109;&#97;&#106;&#111;&#114;&#100;&#111;&#109;&#111;&#64;&#118;&#103;&#101;&#114;&#46;&#107;&#101;&#114;&#110;&#101;&#108;&#46;&#111;&#114;&#103;</a><br />
More majordomo info at  <a href="http://vger.kernel.org/majordomo-info.html" target="_blank"  rel="nofollow">http://vger.kernel.org/majordomo-info.html</a><br />
Please read the FAQ at  <a href="http://www.tux.org/lkml/" target="_blank"  rel="nofollow">http://www.tux.org/lkml/</a>]]></description>
            <dc:creator>Stephen Warren</dc:creator>
            <category>Linux Kernel</category>
            <pubDate>Tue, 03 Jul 2012 22:40:01 +0200</pubDate>
        </item>
    </channel>
</rss>
