From patchwork Wed Mar 23 10:34:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 8648961 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5B084C0553 for ; Wed, 23 Mar 2016 10:36:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 58426203AA for ; Wed, 23 Mar 2016 10:36:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2FF102038A for ; Wed, 23 Mar 2016 10:36:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752282AbcCWKgU (ORCPT ); Wed, 23 Mar 2016 06:36:20 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:58346 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751611AbcCWKgT (ORCPT ); Wed, 23 Mar 2016 06:36:19 -0400 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue002) with ESMTPA (Nemesis) id 0LpkJD-1a620B3XwV-00ffJr; Wed, 23 Mar 2016 11:36:05 +0100 From: Arnd Bergmann To: Doug Ledford Cc: Arnd Bergmann , Faisal Latif , Chien Tin Tung , Mustafa Ismail , Shiraz Saleem , Tatyana Nikolova , Sean Hefty , Hal Rosenstock , Shannon Nelson , Anjali Singhai Jain , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] i40iw: avoid potential uninitialized variable use Date: Wed, 23 Mar 2016 11:34:36 +0100 Message-Id: <1458729361-3089439-1-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 2.7.0 X-Provags-ID: V03:K0:jiIdTPfRmGXcC2t7Ym4by0fY1/baCXxI4YbnLlh3mi7iHMFH1Xj RciRXEGsxFIH1c0kegW68Fi3KmL3dqMLsNkisGwKmw6nmwkz6j4KNlIcpfgE/SEfT5+1Wi2 p3XgmuOZZhwpn/XDTMDOEJgYDZwq5u/ayCcHdHeIlKOQ72l0RAYMoZk02v2LRCgoWX8ykhk HYLiVAwh0bhofFd3nDLSQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:dfMyb5QuvZc=:2POGbKqr/ZY5kbnQvm7m6B 7iyZDBm+gsb8hMnItykcVtzWKTeDEbbeOBi1vA46htc1XwsRHjZcEz/UKPst796dWiOdVxDv6 n6G6Tbs0nzFYohz+1Dz/sf0ZXQgXj2EKWN1WG4LTRJXsjwgcnPSLxFboMG0U3Eq0wWwOTG2Tp Cx16EReqLfMaVDRrI0RoJbbYqf5u+zHIZRtUOXhNpuhA5Zhp+NZ6A2RdiA7b6P74TAMtAjHmq uvqwvE1BPkW0CzlNuJtKWPncen7P9aPajRHSdwHzeLOiDUIZBa81aGnvayunGL8pPImXrLaou PDWJmICPuBQ2EifeZ4p3ni3tLEXV7ZUC9DXP7VsVNvhx9vqHUdmfzh50jtqtEs58BImnQtg2x 71QNROi5LYs/jydjzDlWfbp0wkkkFh6ms4grirXsQYuARWXBdtoSZ0zvfzynnVs6oLDpwxQVl hYDKW+/6EUNgHJA78IkXryy0GL2hNWfi7irHDYL9YVooDEXt2OEut1pB1OPSsobMxr6kStgNA hgNLswXDPVOFNzTrxsebJ0m3YpkwgBoRoGXT+K2nwXPQab8MNZjkW7B9c6tS9+lIWMLlrlJGn YpnVnHfj3yscmhvbLnWXo+/eFKN0D3/d5Ea/w9D1K4bBuidg42Sa6KklRijF9x+nUtWI5YzfW RJPV9dVs4e7FLNNkT8xhI+mFKJ7zGRCvCXyME91tpSYEP8GtvHVmbFeGkr1hKfDCK/ss= Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 gcc finds that the i40iw_make_cm_node() function in the recently added i40iw driver uses an uninitilized variable as an index into an array if CONFIG_IPV6 is disabled and the driver uses IPv6 mode: drivers/infiniband/hw/i40iw/i40iw_cm.c: In function 'i40iw_make_cm_node': drivers/infiniband/hw/i40iw/i40iw_cm.c:2206:52: error: 'arpindex' may be used uninitialized in this function [-Werror=maybe-uninitialized] ether_addr_copy(cm_node->rem_mac, iwdev->arp_table[arpindex].mac_addr); As far as I can tell, this code path can not be used because the ipv4 variable is always set with CONFIG_IPV6 is disabled, but it's better to be sure and prevent the undefined behavior, as well as shut up that warning in a proper way. This adds an 'else' clause for the case we get the warning about, causing the function to return an error in a controlled way. To avoid adding extra mess with combined io()/#ifdef clauses, I'm also converting the existing #ifdef into a more readable if(IS_ENABLED()) check. Signed-off-by: Arnd Bergmann Fixes: f27b4746f378 ("i40iw: add connection management code") Acked-by: Mustafa Ismail --- drivers/infiniband/hw/i40iw/i40iw_cm.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/infiniband/hw/i40iw/i40iw_cm.c b/drivers/infiniband/hw/i40iw/i40iw_cm.c index 92745d755272..38f917a6c778 100644 --- a/drivers/infiniband/hw/i40iw/i40iw_cm.c +++ b/drivers/infiniband/hw/i40iw/i40iw_cm.c @@ -1992,7 +1992,6 @@ static int i40iw_addr_resolve_neigh(struct i40iw_device *iwdev, /** * i40iw_get_dst_ipv6 */ -#if IS_ENABLED(CONFIG_IPV6) static struct dst_entry *i40iw_get_dst_ipv6(struct sockaddr_in6 *src_addr, struct sockaddr_in6 *dst_addr) { @@ -2008,7 +2007,6 @@ static struct dst_entry *i40iw_get_dst_ipv6(struct sockaddr_in6 *src_addr, dst = ip6_route_output(&init_net, NULL, &fl6); return dst; } -#endif /** * i40iw_addr_resolve_neigh_ipv6 - resolve neighbor ipv6 address @@ -2016,7 +2014,6 @@ static struct dst_entry *i40iw_get_dst_ipv6(struct sockaddr_in6 *src_addr, * @dst_ip: remote ip address * @arpindex: if there is an arp entry */ -#if IS_ENABLED(CONFIG_IPV6) static int i40iw_addr_resolve_neigh_ipv6(struct i40iw_device *iwdev, u32 *src, u32 *dest, @@ -2089,7 +2086,6 @@ static int i40iw_addr_resolve_neigh_ipv6(struct i40iw_device *iwdev, dst_release(dst); return rc; } -#endif /** * i40iw_ipv4_is_loopback - check if loopback @@ -2190,13 +2186,13 @@ static struct i40iw_cm_node *i40iw_make_cm_node( cm_info->loc_addr[0], cm_info->rem_addr[0], oldarpindex); -#if IS_ENABLED(CONFIG_IPV6) - else + else if (IS_ENABLED(CONFIG_IPV6)) arpindex = i40iw_addr_resolve_neigh_ipv6(iwdev, cm_info->loc_addr, cm_info->rem_addr, oldarpindex); -#endif + else + arpindex = -EINVAL; } if (arpindex < 0) { i40iw_pr_err("cm_node arpindex\n");