Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965456AbcJQWHl (ORCPT ); Mon, 17 Oct 2016 18:07:41 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:60659 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964923AbcJQWHg (ORCPT ); Mon, 17 Oct 2016 18:07:36 -0400 From: Arnd Bergmann To: Doug Ledford Cc: Linus Torvalds , linux-kernel@vger.kernel.org, Arnd Bergmann , Sean Hefty , Hal Rosenstock , Matan Barak , Haggai Eran , Leon Romanovsky , Sagi Grimberg , Bart Van Assche , Alex Vesker , Guy Shapiro , linux-rdma@vger.kernel.org Subject: [PATCH 03/28] [v2] infiniband: shut up a maybe-uninitialized warning Date: Tue, 18 Oct 2016 00:05:32 +0200 Message-Id: <20161017220557.1688282-3-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20161017220342.1627073-1-arnd@arndb.de> References: <20161017220342.1627073-1-arnd@arndb.de> X-Provags-ID: V03:K0:fnuW5gstPB6PzBewaFmX9yw+3PxCWbmxprxdcz4ODnCGaou49Pm Geq3XwIZpckajGWeJlHhHGojl3y6zecehG7Ew5aTGKOlWbBKjuLP/o525epVUWPGjTFgeyG i0cRnlYfn/L9YOOOvJeV8qfjWyeuuewtNQxgin/IkiMBXDt83FbuSgkiLX9lhLYbKRZ4/t8 U6d+EtT91HQC4Y71/RRhw== X-UI-Out-Filterresults: notjunk:1;V01:K0:/beImIbhc/4=:oYZfwQmLIHo3NBtQJma9Aq AMv1IjHGK3SHNJ+tRdOwI1xEAD4JWSSgwTRnsEl1fGpbXOBmKz5ZkWjkhr39dxLYA16djG5zI FPFdPqosDB1VPD+KVO+jSWrUUtOOTN8igwUPJo7vPlR4VI40E1My8ku+Bn6By50cHqHsa0w9h qZQhcyQtY0bGToG7ioeZcJORiU2WEzlnGF/T80VdpkgBG+ZPGhxaFGDWtwGMvNNL6mV9NUmET ufq68eNoF2POI4y87UUrx4S732Cd67OUcPWd/V40c98rBmJ7WNmoV29X1V30Bhrr3w8kSI6/x gc9H+y6mnhfA55TpOYwfxfKZvL5u7gpa6KrenSl1izw+Rp/1i4O/dKYhsBAgblitGl8eYmBYq NqoxE4axbbX+VXIyNBiRFdpNeCvPYLyZjpG8zkI0jUF6kruBhgQoURUeyHtyGUQJXJP26uamN 8jQMh3j2VkMfOmUL2Ts+k5WYnnrcyx/Dzm6OA/fE+XyJlC4hA4q/F3Cbzamwk6grz9sx5aFE8 h4ZU1j7VbzafsotrXqCPYlNkvW6t1UY3zdxob1P02BljJ/NxdTs01sqpXj1WX27Bpjemz9I5x K5uYSw6eaUvvJeI5H9/cn4utl6GesZIt8cR4A95ahX50KiJdqZDIbmfrdQeC6EQnXetnhS/Ud E9wPFJQc4q0j3jUSoazi1xFKUkSSbikV+eAS7NUQ/lbxJcMRcPveW9ju6Fq7QXP8Anyk= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4197 Lines: 124 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 --- 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