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: 101046 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2590976lbb; Wed, 27 Jan 2016 05:46:24 -0800 (PST) X-Received: by 10.66.159.38 with SMTP id wz6mr42623802pab.12.1453902383907; Wed, 27 Jan 2016 05:46:23 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p28si9654930pfi.217.2016.01.27.05.46.23; Wed, 27 Jan 2016 05:46:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932466AbcA0NqV (ORCPT + 30 others); Wed, 27 Jan 2016 08:46:21 -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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.7.0 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",