From owner-freebsd-bugs@FreeBSD.ORG Sun Aug 5 20:20:02 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8F7C51065675 for ; Sun, 5 Aug 2012 20:20:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 625B38FC15 for ; Sun, 5 Aug 2012 20:20:02 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q75KK2M4077936 for ; Sun, 5 Aug 2012 20:20:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q75KK2Oq077935; Sun, 5 Aug 2012 20:20:02 GMT (envelope-from gnats) Resent-Date: Sun, 5 Aug 2012 20:20:02 GMT Resent-Message-Id: <201208052020.q75KK2Oq077935@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Dimitry Andric Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6745D1065672 for ; 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 ; 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 ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: kern/170397: Uninitialized variables in ah_eeprom_9287.c X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Aug 2012 20:20:02 -0000 >Number: 170397 >Category: kern >Synopsis: Uninitialized variables in ah_eeprom_9287.c >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >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: >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: >Unformatted: