From patchwork Thu Jan 28 21:58:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 8154641 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 46C8E9F9E8 for ; Thu, 28 Jan 2016 21:59:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 70E6D2021B for ; Thu, 28 Jan 2016 21:59:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 997D720218 for ; Thu, 28 Jan 2016 21:59:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966434AbcA1V7J (ORCPT ); Thu, 28 Jan 2016 16:59:09 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:64996 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932198AbcA1V7H (ORCPT ); Thu, 28 Jan 2016 16:59:07 -0500 Received: from wuerfel.localnet ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue103) with ESMTPSA (Nemesis) id 0LrHzA-1ZxMou3OF2-0139Lo; Thu, 28 Jan 2016 22:58:32 +0100 From: Arnd Bergmann To: Kalle Valo Cc: Jouni Malinen , netdev@vger.kernel.org, linux-wireless@vger.kernel.org, Arnd Bergmann , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Russell King - ARM Linux Subject: [PATCH v2] hostap: avoid uninitialized variable use in hfa384x_get_rid Date: Thu, 28 Jan 2016 22:58:28 +0100 Message-ID: <18181682.hKPVvnQWXk@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) MIME-Version: 1.0 X-Provags-ID: V03:K0:+fLE6ZLJpRJNwY13FjrJRa/VLY7Ejhflsk7Z9tI0sVff1Si7TkF HWPIH+8Jcfukscpjdk7Qkz1mBVvGpY0eblCwVd51eXn2iiSjhLiCbyJeSDKPso8ASqULhh3 SfI2SU01nCbu9/wFHCg63tM7M53DpAzW8SGAzpU0tYbNfiPoNrImaIXiQhiAtIHYPjw71Z3 /jnZ90PwSUR6XCmaGt5zA== X-UI-Out-Filterresults: notjunk:1; V01:K0:ymIHlINYfaM=:La5k+Tvmlei5rXa9AEEl3j ZlbiGCPqRD0HUt/SIB0DQVV8qocImfhN72VMKA92juIYKD5SVA+aNqN8xI7/CjWPZLfGsnZgn ccot3afDY5u15GLYyn2SY5+PB1odc33PM8Yp4IWkFjL8va3wFXFjNPV98mAtAfbFrDUud0ikp pwN31R8GIbiwTec94DApVxVkxOGC6h2MUWssifXS6LdxjMmOqT6gNWZOahjGW8htqUIybCE4B ZWXcLWfX0tYnTXURRG+Ei63B8elC5o4Wo8pz+/1lo2/yKfMyAQY1B8kdddqKw8gjlcmbXJtx5 sm4vDwFdawShstL19oIgMdT23echTiXoYYWixFYjZF2JbSuEQEowOwoszsHXR30ezjMACffHI FAU67IXLm4gentU/bhmRzqdIiEg/ZuwvJSQdLdAdFMXJ2QJkwSKh4hBt3CBzNg02W2Sv1bk4J 0w6BRK8uR3r1AZuBhY1hWeTSczNGoBPbOx0bNuv2/jf0hH/W3GdJYdXZ1hPe5psIH7YVWNlIg +TTXXwy3ienCA0LL+AlDlbKBr3ZW1utOuSjj5T0YZWJTpH8/88FERSXh5bbdgtxuDv2IFM6ke JhOrzFEfBtVi8f5ggPIG/HDnEWZlcVOYvMy5tECRMo0KKrN58R9CnTeVHTRpLrudg+hxVpiWC zUNSzPCLvROGoCk87z4TK7aqqnOOpog/yRPICnvHbvso5BnEh9Z+ZVMH/yMwhYbcSkFvwSMjB FWpOghsyCXnuutxi Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The driver reads a value from hfa384x_from_bap(), which may fail, and then assigns the value to a local variable. gcc detects that in in the failure case, the 'rlen' variable now contains uninitialized data: In file included from ../drivers/net/wireless/intersil/hostap/hostap_pci.c:220:0: drivers/net/wireless/intersil/hostap/hostap_hw.c: In function 'hfa384x_get_rid': drivers/net/wireless/intersil/hostap/hostap_hw.c:842:5: warning: 'rec' may be used uninitialized in this function [-Wmaybe-uninitialized] if (le16_to_cpu(rec.len) == 0) { This restructures the function as suggested by Russell King, to make it more readable and get more reliable error handling, by handling each failure mode using a goto. Signed-off-by: Arnd Bergmann --- 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 --git a/drivers/net/wireless/intersil/hostap/hostap_hw.c b/drivers/net/wireless/intersil/hostap/hostap_hw.c index 6df3ee561d52..515aa3f993f3 100644 --- a/drivers/net/wireless/intersil/hostap/hostap_hw.c +++ b/drivers/net/wireless/intersil/hostap/hostap_hw.c @@ -836,25 +836,30 @@ static int hfa384x_get_rid(struct net_device *dev, u16 rid, void *buf, int len, spin_lock_bh(&local->baplock); res = hfa384x_setup_bap(dev, BAP0, rid, 0); - if (!res) - res = hfa384x_from_bap(dev, BAP0, &rec, sizeof(rec)); + if (res) + goto unlock; + + res = hfa384x_from_bap(dev, BAP0, &rec, sizeof(rec)); + if (res) + goto unlock; if (le16_to_cpu(rec.len) == 0) { /* RID not available */ res = -ENODATA; + goto unlock; } rlen = (le16_to_cpu(rec.len) - 1) * 2; - if (!res && exact_len && rlen != len) { + if (exact_len && rlen != len) { printk(KERN_DEBUG "%s: hfa384x_get_rid - RID len mismatch: " "rid=0x%04x, len=%d (expected %d)\n", dev->name, rid, rlen, len); res = -ENODATA; } - if (!res) - res = hfa384x_from_bap(dev, BAP0, buf, len); + res = hfa384x_from_bap(dev, BAP0, buf, len); +unlock: spin_unlock_bh(&local->baplock); mutex_unlock(&local->rid_bap_mtx);