From patchwork Wed Jan 27 13:45:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 8133841 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 20F419F818 for ; Wed, 27 Jan 2016 13:46:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 77B17202E6 for ; Wed, 27 Jan 2016 13:46:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D0A7620279 for ; Wed, 27 Jan 2016 13:46:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932383AbcA0NqU (ORCPT ); Wed, 27 Jan 2016 08:46:20 -0500 Received: from mout.kundenserver.de ([212.227.126.131]:60502 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754099AbcA0NqS (ORCPT ); Wed, 27 Jan 2016 08:46:18 -0500 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue002) with ESMTPA (Nemesis) id 0M0Y5m-1a64380foE-00urUi; Wed, 27 Jan 2016 14:45:48 +0100 From: Arnd Bergmann To: Jouni Malinen , Kalle Valo Cc: linux-arm-kernel@lists.infradead.org, Arnd Bergmann , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] hostap: avoid uninitialized variable use in hfa384x_get_rid Date: Wed, 27 Jan 2016 14:45:26 +0100 Message-Id: <1453902342-3420391-1-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 2.7.0 X-Provags-ID: V03:K0:oq3t3CJYe8zo3scbUnNAlu+nRvCHNN3MZSS9njEmSvEdFsxW7qu Aq6eb3xdMRggpHhOz6t6wVYvMz+YKm09kaMd7bh4xM7PZsXhJFMQkAhH4w0rwG/RpP3VZQB pu2l1yAfrriL5GGmPmPUzYMm6q9yAjtKbCzLMS5pzH1wMtMPhwAV+rIhgbU5e9xQ5UxYYuo se1e61fURH/phrd0SQ4xg== X-UI-Out-Filterresults: notjunk:1; V01:K0:B20Ryep3uwI=:Xf+VvvxFlY8+DbpdGPqGnV iEY9SRVyHjVbDfCgzVkU0T8ZJQSXpbtC1qvl9lG4Nf4M/RHbMI1VEnKnP3ZSA8Wws4xaY31MS Nj9rqHblJ4odLNBTu5om+IvriphbOeyp+oNwYus8f1PpjHNqFZU/T5NzAQ/yJ6hKseqyjMUKr 8HSya2pJgbdcO1UjN/w6N4Lv563paFt+kuscb/ze354dOnyZD604dpXRxhLBWVbDDbSGOrZAj C2IL2jiHtoeqHjRKXBh9Y36asZFq88wjQ1JlrF8nP82+vkN6iTRuMbgcTQIg+NqqoeWzufirG LRu21OOnzGcr4FK1hcAXAZU/PrcDvaWz96dOh/whRqIib0nCANKV7wkzjvUjGQ9u9salvbXIo IdHlOdShCMOYHCinvzfUdpjpesHkHQUnQJ+j7COCxmtXtwYIm/UvQpxfvSwrPyvh7kL4eXd8d mhewD1547Irq3AalrDX3m+QmhZRQuesAccPJfktRjvyCO4xY8Oc6SmSdxDxC5j02MyANO6cxJ nxaj/iceXwFW3TTRJ4/NH2vaCSEBfHxnY5y1zpl7OyPm/gtFOSpOPud1ZkEC2TEnz26j+vFh9 m5lUQDJHZjLm5D+cM+fJ1t+9WFXzt1TQYDl7FFXvwdWmuFgUYcxUIZFQ2shhIkMdyrX764+E2 cPEYQ1kemZbJqAo/OTG1izVpq663YgPKmb6HzDZDn5ePnFvCFEVOVmWVx5G0fX3uKMVI= 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) { To ensure we get consistent error handling here, this changes the code to only set rlen if we actually read data correctly, which also takes care of the warning. Signed-off-by: Arnd Bergmann --- drivers/net/wireless/intersil/hostap/hostap_hw.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/intersil/hostap/hostap_hw.c b/drivers/net/wireless/intersil/hostap/hostap_hw.c index 6df3ee561d52..6dbf8ee9490a 100644 --- a/drivers/net/wireless/intersil/hostap/hostap_hw.c +++ b/drivers/net/wireless/intersil/hostap/hostap_hw.c @@ -839,12 +839,15 @@ static int hfa384x_get_rid(struct net_device *dev, u16 rid, void *buf, int len, if (!res) res = hfa384x_from_bap(dev, BAP0, &rec, sizeof(rec)); - if (le16_to_cpu(rec.len) == 0) { - /* RID not available */ - res = -ENODATA; + if (!res) { + if (le16_to_cpu(rec.len) == 0) { + /* RID not available */ + res = -ENODATA; + } + + rlen = (le16_to_cpu(rec.len) - 1) * 2; } - rlen = (le16_to_cpu(rec.len) - 1) * 2; if (!res && exact_len && rlen != len) { printk(KERN_DEBUG "%s: hfa384x_get_rid - RID len mismatch: " "rid=0x%04x, len=%d (expected %d)\n",