Received: by 10.223.164.221 with SMTP id h29csp3119174wrb; Mon, 30 Oct 2017 15:44:14 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SZKKpN2ADjc1b3tearLdQ9WDGVMP8Em7yyusNmrTm6Q4y9+L4QUEChVpWrOBuKWMMiYo8t X-Received: by 10.98.207.71 with SMTP id b68mr10094536pfg.125.1509403454247; Mon, 30 Oct 2017 15:44:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509403454; cv=none; d=google.com; s=arc-20160816; b=x/8bsOwqAMX11cRJVyHO7aExp3wrdafmQ+irvNOWYnqyM6EZndUm9vKMMbBOgauWGf mRoPezO5bPpi/EYMfuFhRs/B4Z6D0m0eDbNiW2UHo7O1l2uw7IOiQe+AgIGlJZ7JZiou x63mCOiR3QVBRGcJRdEICxeJCyp9r6gsXnPETfUHN94YX9hj+WzpZvHyIiPL+B02mYp5 BWucNaWKMRg//1NeQGTvzWjyTf/8DW5zr5Kaofl3BICBMMsQJf2CPsxHRvcZFOxFn1b8 mqdfPNID6G2Q74iDvd+Pni5c/aZfo0ZbEZRh8VE7B/EplcdWz1Tep8CmHKFvrwSTmvXC DDrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date :arc-authentication-results; bh=TBLVmjXbT62TGXi1qjHF68FDK48tw4QqkMGfWyXIWQI=; b=W5BMgwCS2mLe+CQgHsvcSpAk8JRKcc3DeGXd7iTOXgXgH8n1IW5E2YEPOA61gdGVP1 7ePoVA2GWxJhg7OiCsG//m6X+ZYz4lxoSuguzHtqe1ZGdQvrE+U/7w9/65QKLjYXmax0 3nE+DdtsbMu97HXT1Sbwk20gt5+hxofi6hmisj4rNPYdq1uzCkf8YvB9hFy0JAXTbi52 QDcRpdyHkiqv9IRnmUUo1EmCQ3El1sFkvvRCjLEQQoz4Ob1xSA5HPZRrkBdxgjpELYS+ nAOOg5Vi9LdgSXNjWIV1i/JCHiBxLrCcCtkhsej7pxQGm+Q6Q2n73p7SZ8mmyImLM6zA By5A== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k2si4952plt.571.2017.10.30.15.44.01; Mon, 30 Oct 2017 15:44:14 -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 S932416AbdJ3WTa (ORCPT + 99 others); Mon, 30 Oct 2017 18:19:30 -0400 Received: from gateway31.websitewelcome.com ([192.185.144.97]:38738 "EHLO gateway31.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752712AbdJ3WT2 (ORCPT ); Mon, 30 Oct 2017 18:19:28 -0400 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway31.websitewelcome.com (Postfix) with ESMTP id EC1C722D911 for ; Mon, 30 Oct 2017 17:19:27 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id 9IP1eXxcP5b6T9IP1enLew; Mon, 30 Oct 2017 17:19:27 -0500 Received: from [189.175.7.72] (port=57646 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.87) (envelope-from ) id 1e9IP1-001KUW-C2; Mon, 30 Oct 2017 17:19:27 -0500 Date: Mon, 30 Oct 2017 17:19:25 -0500 From: "Gustavo A. R. Silva" To: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" Cc: netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] netfilter: ipset: use swap macro instead of _manually_ swapping values Message-ID: <20171030221925.GA28998@embeddedor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.175.7.72 X-Source-L: No X-Exim-ID: 1e9IP1-001KUW-C2 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.175.7.72]:57646 X-Source-Auth: garsilva@embeddedor.com X-Email-Count: 8 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make use of the swap macro and remove unnecessary variables tmp. This makes the code easier to read and maintain. This code was detected with the help of Coccinelle. Signed-off-by: Gustavo A. R. Silva --- net/netfilter/ipset/ip_set_bitmap_ip.c | 8 ++------ net/netfilter/ipset/ip_set_bitmap_ipmac.c | 8 ++------ net/netfilter/ipset/ip_set_bitmap_port.c | 8 ++------ 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/net/netfilter/ipset/ip_set_bitmap_ip.c b/net/netfilter/ipset/ip_set_bitmap_ip.c index d8975a0..488d6d0 100644 --- a/net/netfilter/ipset/ip_set_bitmap_ip.c +++ b/net/netfilter/ipset/ip_set_bitmap_ip.c @@ -263,12 +263,8 @@ bitmap_ip_create(struct net *net, struct ip_set *set, struct nlattr *tb[], ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP_TO], &last_ip); if (ret) return ret; - if (first_ip > last_ip) { - u32 tmp = first_ip; - - first_ip = last_ip; - last_ip = tmp; - } + if (first_ip > last_ip) + swap(first_ip, last_ip); } else if (tb[IPSET_ATTR_CIDR]) { u8 cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]); diff --git a/net/netfilter/ipset/ip_set_bitmap_ipmac.c b/net/netfilter/ipset/ip_set_bitmap_ipmac.c index 4c279fb..c00b6a2 100644 --- a/net/netfilter/ipset/ip_set_bitmap_ipmac.c +++ b/net/netfilter/ipset/ip_set_bitmap_ipmac.c @@ -337,12 +337,8 @@ bitmap_ipmac_create(struct net *net, struct ip_set *set, struct nlattr *tb[], ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP_TO], &last_ip); if (ret) return ret; - if (first_ip > last_ip) { - u32 tmp = first_ip; - - first_ip = last_ip; - last_ip = tmp; - } + if (first_ip > last_ip) + swap(first_ip, last_ip); } else if (tb[IPSET_ATTR_CIDR]) { u8 cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]); diff --git a/net/netfilter/ipset/ip_set_bitmap_port.c b/net/netfilter/ipset/ip_set_bitmap_port.c index 7f9bbd7..b561ca8 100644 --- a/net/netfilter/ipset/ip_set_bitmap_port.c +++ b/net/netfilter/ipset/ip_set_bitmap_port.c @@ -238,12 +238,8 @@ bitmap_port_create(struct net *net, struct ip_set *set, struct nlattr *tb[], first_port = ip_set_get_h16(tb[IPSET_ATTR_PORT]); last_port = ip_set_get_h16(tb[IPSET_ATTR_PORT_TO]); - if (first_port > last_port) { - u16 tmp = first_port; - - first_port = last_port; - last_port = tmp; - } + if (first_port > last_port) + swap(first_port, last_port); elements = last_port - first_port + 1; set->dsize = ip_set_elem_len(set, tb, 0, 0); -- 2.7.4 From 1583283748937932051@xxx Mon Nov 06 02:57:26 +0000 2017 X-GM-THRID: 1581691652519634530 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread