diff mbox

Fix uninitialized-variable warnings.

Message ID 1365705330.1929.30.camel@joe-AO722 (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Joe Perches April 11, 2013, 6:35 p.m. UTC
On Thu, 2013-04-11 at 11:02 -0700, Han Shen wrote:
> GCC 4.8 is spitting out uninitialized-varaible warnings against "drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c".
> This trivial patch just adds initialization to the variable.

Not sure this is correct.
I think the logic should be inspected instead.

ofdm_index_old[1] _is_ used uninitialized.

It appears there might be a missing

	ofdm_index_old[1] = (u8) i;

as that's the same style test done in the
section above.

Maybe this:
---
 drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c | 1 +
 1 file changed, 1 insertion(+)



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

Comments

Larry Finger April 11, 2013, 8 p.m. UTC | #1
On 04/11/2013 01:35 PM, Joe Perches wrote:
> On Thu, 2013-04-11 at 11:02 -0700, Han Shen wrote:
>> GCC 4.8 is spitting out uninitialized-varaible warnings against "drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c".
>> This trivial patch just adds initialization to the variable.
>
> Not sure this is correct.
> I think the logic should be inspected instead.
>
> ofdm_index_old[1] _is_ used uninitialized.
>
> It appears there might be a missing
>
> 	ofdm_index_old[1] = (u8) i;
>
> as that's the same style test done in the
> section above.
>
> Maybe this:
> ---
>   drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
> index b793a65..56b2b2f 100644
> --- a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
> +++ b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
> @@ -717,6 +717,7 @@ static void rtl92c_dm_txpower_tracking_callback_thermalmeter(struct ieee80211_hw
>   			for (i = 0; i < OFDM_TABLE_LENGTH; i++) {
>   				if (ele_d == (ofdmswing_table[i] &
>   				    MASKOFDM_D)) {
> +					ofdm_index_old[1] = (u8) i;
>
>   					RT_TRACE(rtlpriv, COMP_POWER_TRACKING,
>   						 DBG_LOUD,

My earlier E-mail was too hasty. Joe's patch is correct. It should be marked for 
stable (2.6.39+).

Larry



--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Han Shen April 12, 2013, 10:20 p.m. UTC | #2
Hi, Joe's patch (the 1-line fix) does not work for me. The assignment
is in a conditional block, when refer to this ofdm_index_old later, I
still get error -

/mnt/host/source/src/third_party/kernel/files/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c:771:31:
error: 'ofdm_index_old[1]' may be used uninitialized in this function
[-Werror=maybe-uninitialized]
     rtlpriv->dm.ofdm_index[i] = ofdm_index_old[i];

(I'm working on 3.4 branch.)

Thanks,

On Thu, Apr 11, 2013 at 1:00 PM, Larry Finger <Larry.Finger@lwfinger.net> wrote:
> On 04/11/2013 01:35 PM, Joe Perches wrote:
>>
>> On Thu, 2013-04-11 at 11:02 -0700, Han Shen wrote:
>>>
>>> GCC 4.8 is spitting out uninitialized-varaible warnings against
>>> "drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c".
>>> This trivial patch just adds initialization to the variable.
>>
>>
>> Not sure this is correct.
>> I think the logic should be inspected instead.
>>
>> ofdm_index_old[1] _is_ used uninitialized.
>>
>> It appears there might be a missing
>>
>>         ofdm_index_old[1] = (u8) i;
>>
>> as that's the same style test done in the
>> section above.
>>
>> Maybe this:
>> ---
>>   drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
>> b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
>> index b793a65..56b2b2f 100644
>> --- a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
>> +++ b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
>> @@ -717,6 +717,7 @@ static void
>> rtl92c_dm_txpower_tracking_callback_thermalmeter(struct ieee80211_hw
>>                         for (i = 0; i < OFDM_TABLE_LENGTH; i++) {
>>                                 if (ele_d == (ofdmswing_table[i] &
>>                                     MASKOFDM_D)) {
>> +                                       ofdm_index_old[1] = (u8) i;
>>
>>                                         RT_TRACE(rtlpriv,
>> COMP_POWER_TRACKING,
>>                                                  DBG_LOUD,
>
>
> My earlier E-mail was too hasty. Joe's patch is correct. It should be marked
> for stable (2.6.39+).
>
> Larry
>
>
>
Larry Finger April 13, 2013, 12:42 a.m. UTC | #3
On 04/12/2013 05:20 PM, Han Shen(??) wrote:
> Hi, Joe's patch (the 1-line fix) does not work for me. The assignment
> is in a conditional block, when refer to this ofdm_index_old later, I
> still get error -
>
> /mnt/host/source/src/third_party/kernel/files/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c:771:31:
> error: 'ofdm_index_old[1]' may be used uninitialized in this function
> [-Werror=maybe-uninitialized]
>       rtlpriv->dm.ofdm_index[i] = ofdm_index_old[i];
>
> (I'm working on 3.4 branch.)

I would get rid of the -Werror=maybe-unitialized. Sometimes gcc generates a 
false warning, and you really should not error the build in that case.

The correct patch needs to initialize the array to 0, and set the element the 
way Joe's patch does.

Larry


--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
index b793a65..56b2b2f 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
@@ -717,6 +717,7 @@  static void rtl92c_dm_txpower_tracking_callback_thermalmeter(struct ieee80211_hw
 			for (i = 0; i < OFDM_TABLE_LENGTH; i++) {
 				if (ele_d == (ofdmswing_table[i] &
 				    MASKOFDM_D)) {
+					ofdm_index_old[1] = (u8) i;
 
 					RT_TRACE(rtlpriv, COMP_POWER_TRACKING,
 						 DBG_LOUD,