From patchwork Mon Oct 24 15:34:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 101622 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp2643001qge; Mon, 24 Oct 2016 08:36:05 -0700 (PDT) X-Received: by 10.99.110.14 with SMTP id j14mr24765322pgc.135.1477323365554; Mon, 24 Oct 2016 08:36:05 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 63si15937163pfa.79.2016.10.24.08.36.05; Mon, 24 Oct 2016 08:36:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S941221AbcJXPfu (ORCPT + 27 others); Mon, 24 Oct 2016 11:35:50 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:53271 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S938862AbcJXPfm (ORCPT ); Mon, 24 Oct 2016 11:35:42 -0400 Received: from wuerfel.lan. ([78.43.20.153]) by mrelayeu.kundenserver.de (mreue101) with ESMTPA (Nemesis) id 0MejHM-1cIZcF3Ub2-00ODVp; Mon, 24 Oct 2016 17:35:04 +0200 From: Arnd Bergmann To: Wensong Zhang , Simon Horman , Julian Anastasov Cc: Arnd Bergmann , Pablo Neira Ayuso , Patrick McHardy , Jozsef Kadlecsik , "David S. Miller" , Quentin Armitage , netdev@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-kernel@vger.kernel.org Subject: [PATCH] netfilter: ip_vs_sync: fix bogus maybe-uninitialized warning Date: Mon, 24 Oct 2016 17:34:32 +0200 Message-Id: <20161024153454.2766113-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 MIME-Version: 1.0 X-Provags-ID: V03:K0:chT7W5IJAYAM6H4BH0Psf8UkFQSadkllF+pNEIFmHtSBf/X+5KT iTb5+BEJUuIfuZuoUUnslQkyF1GFGiqgs54P5d5VnzBlEeJqcKbymZdLzKMNb4FIeQeARqF jEylyCzbvxy+J1T9NOuw7AugSG2wOHbDTySR+SA8mC5FwSvDZNJwX5LmrEsp0YtMAtGI9Oo BvBzz/NfeExTRnTcZfxZQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:QcS3OLPjG+Y=:cBbgfMOzLVJbjGq7PS/EWb +DYhRN1CnwYBPgor8cMdOa2StZ0kwuSvlMPp0L5UT1A2WsF8d+wH2xO52TKeEKyjz1uUMusK7 29j0PyyFsvcKqAQVxQ1HKX6R/AniS5bK+Nt+z7q9ioTWgz5WgbMR3kuof9jyCX8956MAnHuy8 eK8mxGs/xDfy0ETbLPzufk2X4IJWamljZDkrqRvu2l2xTp1+dz20nigssBrlTp/dRzdX0gVt5 YgeMwrcN6e6DK5Lg6shxPOvPZLzcXp4Ts/XcWL4iVh9wtkadWNemKFkCHomjwDzQ2CQPEPGaS NjUzfBb3xAHTydq106vV/hALver7p9vCBnYb7spB0v4TvgccEbY9OO7VljF+mYByGB4XEgGxo NMnXoGx6r2xePoM9l0GfOa4QnOmwr/52SXszFmW6qZIXNle/Kn0Y0+f6+Jav0DBC8GIxpwmxV HIWjZ4hqYpixU0FAVwRz4EDiNRnx3wVVvWtmjB9Ksrrtm92FXchbooo3FKOsPGOWiYNdcCAZU q6aninPKFkStAy9eCw5kE626P646nH5qOCov9e04ISjaTi0K6URv3ILyicXbejA3x6IcQRQVB 7GNdyJ5Zu8jlLqM0NAM0+XCaUykLxrjoCEopYtoG6Gqh8tWdRjSY+EAQfy0TRJwyowdE4t2oE 4HXfH4p6PEUJWdzViXAWS/YpHebCepL1n7IkqlfJwSyOXiVcvPjeuw5c+NUf30xuOPIP3arWD 86opJtL2sOSZl4k2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Building the ip_vs_sync code with CONFIG_OPTIMIZE_INLINING on x86 confuses the compiler to the point where it produces a rather dubious warning message: net/netfilter/ipvs/ip_vs_sync.c:1073:33: error: ‘opt.init_seq’ may be used uninitialized in this function [-Werror=maybe-uninitialized] struct ip_vs_sync_conn_options opt; ^~~ net/netfilter/ipvs/ip_vs_sync.c:1073:33: error: ‘opt.delta’ may be used uninitialized in this function [-Werror=maybe-uninitialized] net/netfilter/ipvs/ip_vs_sync.c:1073:33: error: ‘opt.previous_delta’ may be used uninitialized in this function [-Werror=maybe-uninitialized] net/netfilter/ipvs/ip_vs_sync.c:1073:33: error: ‘*((void *)&opt+12).init_seq’ may be used uninitialized in this function [-Werror=maybe-uninitialized] net/netfilter/ipvs/ip_vs_sync.c:1073:33: error: ‘*((void *)&opt+12).delta’ may be used uninitialized in this function [-Werror=maybe-uninitialized] net/netfilter/ipvs/ip_vs_sync.c:1073:33: error: ‘*((void *)&opt+12).previous_delta’ may be used uninitialized in this function [-Werror=maybe-uninitialized] The problem appears to be a combination of a number of factors, including the __builtin_bswap32 compiler builtin being slightly odd, having a large amount of code inlined into a single function, and the way that some functions only get partially inlined here. I've spent way too much time trying to work out a way to improve the code, but the best I've come up with is to add an explicit memset right before the ip_vs_seq structure is first initialized here. When the compiler works correctly, this has absolutely no effect, but in the case that produces the warning, the warning disappears. In the process of analysing this warning, I also noticed that we use memcpy to copy the larger ip_vs_sync_conn_options structure over two members of the ip_vs_conn structure. This works because the layout is identical, but seems error-prone, so I'm changing this in the process to directly copy the two members. This change seemed to have no effect on the object code or the warning, but it deals with the same data, so I kept the two changes together. Signed-off-by: Arnd Bergmann --- net/netfilter/ipvs/ip_vs_sync.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) -- 2.9.0 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c index 1b07578bedf3..9350530c16c1 100644 --- a/net/netfilter/ipvs/ip_vs_sync.c +++ b/net/netfilter/ipvs/ip_vs_sync.c @@ -283,6 +283,7 @@ struct ip_vs_sync_buff { */ static void ntoh_seq(struct ip_vs_seq *no, struct ip_vs_seq *ho) { + memset(ho, 0, sizeof(*ho)); ho->init_seq = get_unaligned_be32(&no->init_seq); ho->delta = get_unaligned_be32(&no->delta); ho->previous_delta = get_unaligned_be32(&no->previous_delta); @@ -917,8 +918,10 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa kfree(param->pe_data); } - if (opt) - memcpy(&cp->in_seq, opt, sizeof(*opt)); + if (opt) { + cp->in_seq = opt->in_seq; + cp->out_seq = opt->out_seq; + } atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs)); cp->state = state; cp->old_state = cp->state;