Message ID | 20161017220557.1688282-3-arnd@arndb.de (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
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@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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;
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@arndb.de> --- drivers/infiniband/core/cma.c | 56 ++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 27 deletions(-)