From nobody@FreeBSD.org  Sun Aug  5 20:12:11 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 6745D1065672
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  5 Aug 2012 20:12:11 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 3926C8FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  5 Aug 2012 20:12:11 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q75KCBAM088645
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 5 Aug 2012 20:12:11 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q75KCAjp088644;
	Sun, 5 Aug 2012 20:12:10 GMT
	(envelope-from nobody)
Message-Id: <201208052012.q75KCAjp088644@red.freebsd.org>
Date: Sun, 5 Aug 2012 20:12:10 GMT
From: Dimitry Andric <dim@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Uninitialized variables in ah_eeprom_9287.c
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         170397
>Category:       kern
>Synopsis:       [ath] [patch] Uninitialized variables in ah_eeprom_9287.c
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-wireless
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Aug 05 20:20:02 UTC 2012
>Closed-Date:    
>Last-Modified:  Mon Aug 06 01:30:29 UTC 2012
>Originator:     Dimitry Andric
>Release:        FreeBSD 10.0-CURRENT
>Organization:
The FreeBSD Project
>Environment:
FreeBSD vm-dvs-dimtest1.home.andric.com 10.0-CURRENT FreeBSD 10.0-CURRENT #1 r238827M: Fri Jul 27 20:42:11 CEST 2012     dim@vm-dvs-dimtest1.home.andric.com:/usr/obj/usr/src/sys/GENERIC  i386
>Description:
I'm busy with importing a new clang snapshot into head.  This version
has a bunch of interesting new warnings, and I got the following one
during building of ath:

  sys/dev/ath/ath_hal/ah_eeprom_9287.c:307:6: error: variable 'magic' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
          if (ah->ah_eepromdata == NULL) {
              ^~~~~~~~~~~~~~~~~~~~~~~~~
  sys/dev/ath/ath_hal/ah_eeprom_9287.c:316:6: note: uninitialized use occurs here
          if (magic != AR5416_EEPROM_MAGIC) {
              ^~~~~
  sys/dev/ath/ath_hal/ah_eeprom_9287.c:307:2: note: remove the 'if' if its condition is always true
          if (ah->ah_eepromdata == NULL) {
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  sys/dev/ath/ath_hal/ah_eeprom_9287.c:295:27: note: initialize the variable 'magic' to silence this warning
          uint16_t *eep_data, magic;
                                   ^
                                    = 0

It's because if ah->ah_eepromdata is non-null, magic just contains
garbage, and is then still checked against AR5416_EEPROM_MAGIC.  If the
comment above ("Don't check magic if we're supplied with an EEPROM
block") applies, then I suggest to move the checking block inside the
previous if, as in the attached patch.

>How-To-Repeat:

>Fix:


Patch attached with submission follows:

diff --git a/sys/dev/ath/ath_hal/ah_eeprom_9287.c b/sys/dev/ath/ath_hal/ah_eeprom_9287.c
index 099fe34..abdbce0 100644
--- a/sys/dev/ath/ath_hal/ah_eeprom_9287.c
+++ b/sys/dev/ath/ath_hal/ah_eeprom_9287.c
@@ -310,12 +310,12 @@ ath_hal_9287EepromAttach(struct ath_hal *ah)
 			    "%s Error reading Eeprom MAGIC\n", __func__);
 			return HAL_EEREAD;
 		}
-	}
-	HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s Eeprom Magic = 0x%x\n",
-	    __func__, magic);
-	if (magic != AR5416_EEPROM_MAGIC) {
-		HALDEBUG(ah, HAL_DEBUG_ANY, "Bad magic number\n");
-		return HAL_EEMAGIC;
+		HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s Eeprom Magic = 0x%x\n",
+		    __func__, magic);
+		if (magic != AR5416_EEPROM_MAGIC) {
+			HALDEBUG(ah, HAL_DEBUG_ANY, "Bad magic number\n");
+			return HAL_EEMAGIC;
+		}
 	}
 
 	ee = ath_hal_malloc(sizeof(HAL_EEPROM_9287));


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-wireless 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Mon Aug 6 01:30:13 UTC 2012 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=170397 
>Unformatted:
