Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934915AbcJQWGY (ORCPT ); Mon, 17 Oct 2016 18:06:24 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:63884 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934489AbcJQWGW (ORCPT ); Mon, 17 Oct 2016 18:06:22 -0400 From: Arnd Bergmann To: Pablo Neira Ayuso , Patrick McHardy , Jozsef Kadlecsik , "David S. Miller" Cc: Linus Torvalds , linux-kernel@vger.kernel.org, Arnd Bergmann , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org Subject: [PATCH 01/28] [v2] netfilter: nf_tables: avoid uninitialized variable warning Date: Tue, 18 Oct 2016 00:05:30 +0200 Message-Id: <20161017220557.1688282-1-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:kPMAsGuQ1RMudUSIisawTRiG0+l+glctJAM7rf7e6JpfpaeptRB 7KvWvwEBXq0CJ3ZrOKYqagFGpKHOf24O24U4CfWQNvipFZGxOqIatCqy5N936PXbHMmneJr RwYea1NORNTBjOs3OdlnbhsDN/LLO6d0+C4AlTbte5wpEBu2aGLjkyeKLufrQYThzcDSE72 pxJsJEuZ3IworVbiMHpsA== X-UI-Out-Filterresults: notjunk:1;V01:K0:OFI5U1tbUt8=:AFGIF+vnT3buPILj/hcVbS KbYo4Yi+BdCvcrudi1rb3YXQNnKRcv+PPpfyWov6bYIRNGoJEadATJjdSrBa6mWjsiDGqhm3l 8GysuwBxFew2Lfimp2xHBFAsnEpoQkoSyOOSRioS7Lagz/iLS4HAeT6E3RmG8hS424cArQVj0 5FtN9sb1/Zy+h7GKjdZZNh55S42bV5Ao0huOl9QUZnUXHJZiCx29XkdH4Xitj/gOnA9daNNzI h5Cgoc3uS9T+c5P2CYCPXo5bGp9D0Q3EaZhYedcFWE5ZwYLR6f55Wv8eyqK7o4n1epfxFI0cg tW8rKRuqfIdASngJJHDBTNU12z5Zeb4/nvwGDPDBSpScpyjTPYFt0FP0P0ZmBX02Sab0m+IgQ ZggAK8nW5gdURmcZaEzAlJ2AHaEyygLwFCbJrsdSXj8pdFIddqSTeNYeA5MKT0wHVcMF7Tow7 NOAO0N1Aj5CWx1uvGO1yNI1t+k27QzHmPs9xLNcauo9aAJhutSW2wv3u4sdkTKVrP+ZC332Sm 0oulgwWshFl4vPFCbJTYYAu7KDat09QHhheBGReewnzOce3KCP2tFhgsUOKoqGZELUpQ04yPD opKOROU1UE0lm4JmRr+BwEGsMRj0zP4yFLjr/Lo7DQE/k8pTPYCImNnCC/ULm3Y4nxwjyVSRS 0uDPG6GR3UJu+SLAPEEha/LHLUwaOyJjkQ3EVGLroZMO0HsjiCcuHEnic+YCxUhuUyDU= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1886 Lines: 56 The newly added nft_range_eval() function handles the two possible nft range operations, but as the compiler warning points out, any unexpected value would lead to the 'mismatch' variable being used without being initialized: net/netfilter/nft_range.c: In function 'nft_range_eval': net/netfilter/nft_range.c:45:5: error: 'mismatch' may be used uninitialized in this function [-Werror=maybe-uninitialized] This removes the variable in question and instead moves the condition into the switch itself, which is potentially more efficient than adding a bogus 'default' clause as in my first approach, and is nicer than using the 'uninitialized_var' macro. Fixes: 0f3cd9b36977 ("netfilter: nf_tables: add range expression") Link: http://patchwork.ozlabs.org/patch/677114/ Signed-off-by: Arnd Bergmann --- net/netfilter/nft_range.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) Cc: Pablo Neira Ayuso diff --git a/net/netfilter/nft_range.c b/net/netfilter/nft_range.c index c6d5358..2dd80f4 100644 --- a/net/netfilter/nft_range.c +++ b/net/netfilter/nft_range.c @@ -28,22 +28,20 @@ static void nft_range_eval(const struct nft_expr *expr, const struct nft_pktinfo *pkt) { const struct nft_range_expr *priv = nft_expr_priv(expr); - bool mismatch; int d1, d2; d1 = memcmp(®s->data[priv->sreg], &priv->data_from, priv->len); d2 = memcmp(®s->data[priv->sreg], &priv->data_to, priv->len); switch (priv->op) { case NFT_RANGE_EQ: - mismatch = (d1 < 0 || d2 > 0); + if (d1 < 0 || d2 > 0) + regs->verdict.code = NFT_BREAK; break; case NFT_RANGE_NEQ: - mismatch = (d1 >= 0 && d2 <= 0); + if (d1 >= 0 && d2 <= 0) + regs->verdict.code = NFT_BREAK; break; } - - if (mismatch) - regs->verdict.code = NFT_BREAK; } static const struct nla_policy nft_range_policy[NFTA_RANGE_MAX + 1] = { -- 2.9.0