diff options
author | Arnd Bergmann <arnd@arndb.de> | 2016-03-23 06:34:36 -0400 |
---|---|---|
committer | Doug Ledford <dledford@redhat.com> | 2016-04-06 10:37:16 -0400 |
commit | 2fe7857176ad6b70e8b2a318506525410e774f34 (patch) | |
tree | 8e80dcb5d585a4945e2c4b7ee2b528da37e667d0 | |
parent | 9967c70abc929e9b910be8d419fdf6a85411a066 (diff) |
i40iw: avoid potential uninitialized variable use
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 <arnd@arndb.de>
Fixes: f27b4746f378 ("i40iw: add connection management code")
Acked-by: Mustafa Ismail <Mustafa.ismail@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
-rw-r--r-- | drivers/infiniband/hw/i40iw/i40iw_cm.c | 10 |
1 files 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, | |||
1992 | /** | 1992 | /** |
1993 | * i40iw_get_dst_ipv6 | 1993 | * i40iw_get_dst_ipv6 |
1994 | */ | 1994 | */ |
1995 | #if IS_ENABLED(CONFIG_IPV6) | ||
1996 | static struct dst_entry *i40iw_get_dst_ipv6(struct sockaddr_in6 *src_addr, | 1995 | static struct dst_entry *i40iw_get_dst_ipv6(struct sockaddr_in6 *src_addr, |
1997 | struct sockaddr_in6 *dst_addr) | 1996 | struct sockaddr_in6 *dst_addr) |
1998 | { | 1997 | { |
@@ -2008,7 +2007,6 @@ static struct dst_entry *i40iw_get_dst_ipv6(struct sockaddr_in6 *src_addr, | |||
2008 | dst = ip6_route_output(&init_net, NULL, &fl6); | 2007 | dst = ip6_route_output(&init_net, NULL, &fl6); |
2009 | return dst; | 2008 | return dst; |
2010 | } | 2009 | } |
2011 | #endif | ||
2012 | 2010 | ||
2013 | /** | 2011 | /** |
2014 | * i40iw_addr_resolve_neigh_ipv6 - resolve neighbor ipv6 address | 2012 | * 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, | |||
2016 | * @dst_ip: remote ip address | 2014 | * @dst_ip: remote ip address |
2017 | * @arpindex: if there is an arp entry | 2015 | * @arpindex: if there is an arp entry |
2018 | */ | 2016 | */ |
2019 | #if IS_ENABLED(CONFIG_IPV6) | ||
2020 | static int i40iw_addr_resolve_neigh_ipv6(struct i40iw_device *iwdev, | 2017 | static int i40iw_addr_resolve_neigh_ipv6(struct i40iw_device *iwdev, |
2021 | u32 *src, | 2018 | u32 *src, |
2022 | u32 *dest, | 2019 | u32 *dest, |
@@ -2089,7 +2086,6 @@ static int i40iw_addr_resolve_neigh_ipv6(struct i40iw_device *iwdev, | |||
2089 | dst_release(dst); | 2086 | dst_release(dst); |
2090 | return rc; | 2087 | return rc; |
2091 | } | 2088 | } |
2092 | #endif | ||
2093 | 2089 | ||
2094 | /** | 2090 | /** |
2095 | * i40iw_ipv4_is_loopback - check if loopback | 2091 | * i40iw_ipv4_is_loopback - check if loopback |
@@ -2190,13 +2186,13 @@ static struct i40iw_cm_node *i40iw_make_cm_node( | |||
2190 | cm_info->loc_addr[0], | 2186 | cm_info->loc_addr[0], |
2191 | cm_info->rem_addr[0], | 2187 | cm_info->rem_addr[0], |
2192 | oldarpindex); | 2188 | oldarpindex); |
2193 | #if IS_ENABLED(CONFIG_IPV6) | 2189 | else if (IS_ENABLED(CONFIG_IPV6)) |
2194 | else | ||
2195 | arpindex = i40iw_addr_resolve_neigh_ipv6(iwdev, | 2190 | arpindex = i40iw_addr_resolve_neigh_ipv6(iwdev, |
2196 | cm_info->loc_addr, | 2191 | cm_info->loc_addr, |
2197 | cm_info->rem_addr, | 2192 | cm_info->rem_addr, |
2198 | oldarpindex); | 2193 | oldarpindex); |
2199 | #endif | 2194 | else |
2195 | arpindex = -EINVAL; | ||
2200 | } | 2196 | } |
2201 | if (arpindex < 0) { | 2197 | if (arpindex < 0) { |
2202 | i40iw_pr_err("cm_node arpindex\n"); | 2198 | i40iw_pr_err("cm_node arpindex\n"); |