mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] i40iw: avoid potential uninitialized variable use
@ 2016-03-23 10:34 Arnd Bergmann
  2016-03-23 20:56 ` Ismail, Mustafa
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2016-03-23 10:34 UTC (permalink / raw)
  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, linux-kernel

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")
---
 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");
-- 
2.7.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: [PATCH] i40iw: avoid potential uninitialized variable use
  2016-03-23 10:34 [PATCH] i40iw: avoid potential uninitialized variable use Arnd Bergmann
@ 2016-03-23 20:56 ` Ismail, Mustafa
  0 siblings, 0 replies; 2+ messages in thread
From: Ismail, Mustafa @ 2016-03-23 20:56 UTC (permalink / raw)
  To: Arnd Bergmann, Doug Ledford
  Cc: Latif, Faisal, Tung, Chien Tin, Saleem, Shiraz, Nikolova,
	Tatyana E, Hefty, Sean, Hal Rosenstock, Nelson, Shannon, Singhai,
	Anjali, linux-rdma, linux-kernel

> -----Original Message-----
> From: Arnd Bergmann [mailto:arnd@arndb.de]
> Sent: Wednesday, March 23, 2016 5:35 AM
> Subject: [PATCH] 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:
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Acked-by: Mustafa Ismail <Mustafa.ismail@intel.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-03-23 20:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-23 10:34 [PATCH] i40iw: avoid potential uninitialized variable use Arnd Bergmann
2016-03-23 20:56 ` Ismail, Mustafa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®