linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 03/28] [v2] infiniband: shut up a maybe-uninitialized warning
       [not found] ` <20161017220342.1627073-1-arnd-r2nGTMty4D4@public.gmane.org>
@ 2016-10-17 22:05   ` Arnd Bergmann
       [not found]     ` <20161017220557.1688282-3-arnd-r2nGTMty4D4@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2016-10-17 22:05 UTC (permalink / raw)
  To: Doug Ledford
  Cc: Linus Torvalds, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	Arnd Bergmann, Sean Hefty, Hal Rosenstock, Matan Barak,
	Haggai Eran, Leon Romanovsky, Sagi Grimberg, Bart Van Assche,
	Alex Vesker, Guy Shapiro, linux-rdma-u79uwXL29TY76Z2rM5mHXA

Some configurations produce this harmless warning when built with
gcc -Wmaybe-uninitialized:

infiniband/core/cma.c: In function 'cma_get_net_dev':
infiniband/core/cma.c:1242:12: warning: 'src_addr_storage.sin_addr.s_addr' may be used uninitialized in this function [-Wmaybe-uninitialized]

I previously reported this for the powerpc64 defconfig, but have now
reproduced the same thing for x86 as well, using gcc-5 or higher.

The code looks correct to me, and this change just rearranges it
by making sure we alway initialize the entire address structure
to make the warning disappear. My first approach added an
initialization at the time of the declaration, which Doug commented
may be too costly, so I hope this version doesn't add overhead.

Link: http://arm-soc.lixom.net/buildlogs/mainline/v4.7-rc6/buildall.powerpc.ppc64_defconfig.log.passed
Link: https://patchwork.kernel.org/patch/9212825/
Signed-off-by: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>
---
 drivers/infiniband/core/cma.c | 56 ++++++++++++++++++++++---------------------
 1 file changed, 29 insertions(+), 27 deletions(-)

diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index 36bf50e..24e0ea6 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -1094,47 +1094,47 @@ static void cma_save_ib_info(struct sockaddr *src_addr,
 	}
 }
 
-static void cma_save_ip4_info(struct sockaddr *src_addr,
-			      struct sockaddr *dst_addr,
+static void cma_save_ip4_info(struct sockaddr_in *src_addr,
+			      struct sockaddr_in *dst_addr,
 			      struct cma_hdr *hdr,
 			      __be16 local_port)
 {
-	struct sockaddr_in *ip4;
-
 	if (src_addr) {
-		ip4 = (struct sockaddr_in *)src_addr;
-		ip4->sin_family = AF_INET;
-		ip4->sin_addr.s_addr = hdr->dst_addr.ip4.addr;
-		ip4->sin_port = local_port;
+		*src_addr = (struct sockaddr_in) {
+			.sin_family = AF_INET,
+			.sin_addr.s_addr = hdr->dst_addr.ip4.addr,
+			.sin_port = local_port,
+		};
 	}
 
 	if (dst_addr) {
-		ip4 = (struct sockaddr_in *)dst_addr;
-		ip4->sin_family = AF_INET;
-		ip4->sin_addr.s_addr = hdr->src_addr.ip4.addr;
-		ip4->sin_port = hdr->port;
+		*dst_addr = (struct sockaddr_in) {
+			.sin_family = AF_INET,
+			.sin_addr.s_addr = hdr->src_addr.ip4.addr,
+			.sin_port = hdr->port,
+		};
 	}
 }
 
-static void cma_save_ip6_info(struct sockaddr *src_addr,
-			      struct sockaddr *dst_addr,
+static void cma_save_ip6_info(struct sockaddr_in6 *src_addr,
+			      struct sockaddr_in6 *dst_addr,
 			      struct cma_hdr *hdr,
 			      __be16 local_port)
 {
-	struct sockaddr_in6 *ip6;
-
 	if (src_addr) {
-		ip6 = (struct sockaddr_in6 *)src_addr;
-		ip6->sin6_family = AF_INET6;
-		ip6->sin6_addr = hdr->dst_addr.ip6;
-		ip6->sin6_port = local_port;
+		*src_addr = (struct sockaddr_in6) {
+			.sin6_family = AF_INET6,
+			.sin6_addr = hdr->dst_addr.ip6,
+			.sin6_port = local_port,
+		};
 	}
 
 	if (dst_addr) {
-		ip6 = (struct sockaddr_in6 *)dst_addr;
-		ip6->sin6_family = AF_INET6;
-		ip6->sin6_addr = hdr->src_addr.ip6;
-		ip6->sin6_port = hdr->port;
+		*dst_addr = (struct sockaddr_in6) {
+			.sin6_family = AF_INET6,
+			.sin6_addr = hdr->src_addr.ip6,
+			.sin6_port = hdr->port,
+		};
 	}
 }
 
@@ -1159,10 +1159,12 @@ static int cma_save_ip_info(struct sockaddr *src_addr,
 
 	switch (cma_get_ip_ver(hdr)) {
 	case 4:
-		cma_save_ip4_info(src_addr, dst_addr, hdr, port);
+		cma_save_ip4_info((struct sockaddr_in *)src_addr,
+				  (struct sockaddr_in *)dst_addr, hdr, port);
 		break;
 	case 6:
-		cma_save_ip6_info(src_addr, dst_addr, hdr, port);
+		cma_save_ip6_info((struct sockaddr_in6 *)src_addr,
+				  (struct sockaddr_in6 *)dst_addr, hdr, port);
 		break;
 	default:
 		return -EAFNOSUPPORT;
@@ -1309,7 +1311,7 @@ static bool validate_net_dev(struct net_device *net_dev,
 static struct net_device *cma_get_net_dev(struct ib_cm_event *ib_event,
 					  const struct cma_req_info *req)
 {
-	struct sockaddr_storage listen_addr_storage, src_addr_storage;
+	struct sockaddr_storage listen_addr_storage = {}, src_addr_storage = {};
 	struct sockaddr *listen_addr = (struct sockaddr *)&listen_addr_storage,
 			*src_addr = (struct sockaddr *)&src_addr_storage;
 	struct net_device *net_dev;
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 03/28] [v2] infiniband: shut up a maybe-uninitialized warning
       [not found]     ` <20161017220557.1688282-3-arnd-r2nGTMty4D4@public.gmane.org>
@ 2016-10-18  6:47       ` Haggai Eran
       [not found]         ` <33302790-0a4c-e2b3-868d-3e7dadbd3c07-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Haggai Eran @ 2016-10-18  6:47 UTC (permalink / raw)
  To: Arnd Bergmann, Doug Ledford
  Cc: Linus Torvalds, linux-kernel-u79uwXL29TY76Z2rM5mHXA, Sean Hefty,
	Hal Rosenstock, Matan Barak, Leon Romanovsky, Sagi Grimberg,
	Bart Van Assche, Alex Vesker, Guy Shapiro,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA

On 10/18/2016 1:05 AM, Arnd Bergmann wrote:
> @@ -1309,7 +1311,7 @@ static bool validate_net_dev(struct net_device *net_dev,
>  static struct net_device *cma_get_net_dev(struct ib_cm_event *ib_event,
>  					  const struct cma_req_info *req)
>  {
> -	struct sockaddr_storage listen_addr_storage, src_addr_storage;
> +	struct sockaddr_storage listen_addr_storage = {}, src_addr_storage = {};

Doesn't this still translate to an extra initialization that Doug was
worried about?

Haggai
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 03/28] [v2] infiniband: shut up a maybe-uninitialized warning
       [not found]         ` <33302790-0a4c-e2b3-868d-3e7dadbd3c07-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
@ 2016-10-18 10:18           ` Arnd Bergmann
  2016-10-18 10:32             ` Haggai Eran
  0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2016-10-18 10:18 UTC (permalink / raw)
  To: Haggai Eran
  Cc: Doug Ledford, Linus Torvalds, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	Sean Hefty, Hal Rosenstock, Matan Barak, Leon Romanovsky,
	Sagi Grimberg, Bart Van Assche, Alex Vesker, Guy Shapiro,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA

On Tuesday, October 18, 2016 9:47:31 AM CEST Haggai Eran wrote:
> On 10/18/2016 1:05 AM, Arnd Bergmann wrote:
> > @@ -1309,7 +1311,7 @@ static bool validate_net_dev(struct net_device *net_dev,
> >  static struct net_device *cma_get_net_dev(struct ib_cm_event *ib_event,
> >                                         const struct cma_req_info *req)
> >  {
> > -     struct sockaddr_storage listen_addr_storage, src_addr_storage;
> > +     struct sockaddr_storage listen_addr_storage = {}, src_addr_storage = {};
> 
> Doesn't this still translate to an extra initialization that Doug was
> worried about?

Thanks for spotting this. I must have screwed up while rebasing the patch
at some point, this one change should not be there, the other changes by
themselves sufficiently address the warning.

	Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 03/28] [v2] infiniband: shut up a maybe-uninitialized warning
  2016-10-18 10:18           ` Arnd Bergmann
@ 2016-10-18 10:32             ` Haggai Eran
  0 siblings, 0 replies; 4+ messages in thread
From: Haggai Eran @ 2016-10-18 10:32 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Doug Ledford, Linus Torvalds, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	Sean Hefty, Hal Rosenstock, Matan Barak, Leon Romanovsky,
	Sagi Grimberg, Bart Van Assche, Alex Vesker, Guy Shapiro,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA

On 10/18/2016 1:18 PM, Arnd Bergmann wrote:
> On Tuesday, October 18, 2016 9:47:31 AM CEST Haggai Eran wrote:
>> On 10/18/2016 1:05 AM, Arnd Bergmann wrote:
>>> @@ -1309,7 +1311,7 @@ static bool validate_net_dev(struct net_device *net_dev,
>>>  static struct net_device *cma_get_net_dev(struct ib_cm_event *ib_event,
>>>                                         const struct cma_req_info *req)
>>>  {
>>> -     struct sockaddr_storage listen_addr_storage, src_addr_storage;
>>> +     struct sockaddr_storage listen_addr_storage = {}, src_addr_storage = {};
>>
>> Doesn't this still translate to an extra initialization that Doug was
>> worried about?
> 
> Thanks for spotting this. I must have screwed up while rebasing the patch
> at some point, this one change should not be there, the other changes by
> themselves sufficiently address the warning.

Okay, other than this the patch looks good to me.

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2016-10-18 10:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20161017220342.1627073-1-arnd@arndb.de>
     [not found] ` <20161017220342.1627073-1-arnd-r2nGTMty4D4@public.gmane.org>
2016-10-17 22:05   ` [PATCH 03/28] [v2] infiniband: shut up a maybe-uninitialized warning Arnd Bergmann
     [not found]     ` <20161017220557.1688282-3-arnd-r2nGTMty4D4@public.gmane.org>
2016-10-18  6:47       ` Haggai Eran
     [not found]         ` <33302790-0a4c-e2b3-868d-3e7dadbd3c07-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-10-18 10:18           ` Arnd Bergmann
2016-10-18 10:32             ` Haggai Eran

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).