Received: by 10.223.164.200 with SMTP id h8csp910559wrb; Mon, 6 Nov 2017 00:44:03 -0800 (PST) X-Google-Smtp-Source: ABhQp+QAmaeuGGqydzwU9NaBjDsAOp1k2l4HD4eFazGqkG1sgk5CshkK5cZLmCyrfqdQnogX8O2B X-Received: by 10.159.244.14 with SMTP id x14mr13747280plr.75.1509957843434; Mon, 06 Nov 2017 00:44:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509957843; cv=none; d=google.com; s=arc-20160816; b=1GWHJYq9RrmCkUb8e7kb5Q7J/83X2VmKfgfrA14DVNWDvr3W5YUFQLqz2L/qdQqdqS 12UyeaeUnIBuD/+lhVl0MU4hu4YqWeH0ywh6POwH8LDalZiNnTNtcmFll68Zb8QYMT29 TJZM5YfDq9ou+GVLH4KH3otNe3syxhrj+YbSHEUXRXB9lGX/6jaNzcPJmv3lr1nLyp4r isd+Km844KNZ0szxQN9hpEbw8RyRks4AuXZS4noO60McEERzeMm2lhBYz1y2lVfiVsCw zSeJRcfV6RZZBWY9IB6rGZNTDfwQ4GA0qbZXVFauTyB7az2c37f3+VQddXWFYLwJ1CnM Glwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=NWbrjf3ivLxf2099h4yFGDnJBrkfWz4zaxAhvzkyvDw=; b=yVco23g54tiDA52zy7LO9Hxiie9MP2DzS7Gh+k719cIhUIZGzLBfXXnOJdoH6mBFEV l0Mcp7NWtEv3rRbriSCD+cmOxNu2k+DzMt9QypaPSatyI7RY/9y2CaN/AFDuQHYK8Q67 6jkUgQfPSCdvxRnADnVV9Mmg+VNGtaMKQlXqYIVA1Kk9vko0QSg+mxrDDtZwmZe+mZIn KeKvpyNYeEMp0A6e5iEbJTW0uoY3lKmgY7IZZaPV1xzKrn8EFnbPOsu14gLFAko7fPeC RJ2g9C/aCSFVU67T5/LLBiSY5EIIRV07TClPNWRhGklUw1sGPWPeZ8c+n6iuAAHTry3f AFJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@blackhole.kfki.hu header.s=20151130 header.b=RKW3/zaP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=blackhole.kfki.hu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e72si12189051pfm.35.2017.11.06.00.43.49; Mon, 06 Nov 2017 00:44:03 -0800 (PST) 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; dkim=pass header.i=@blackhole.kfki.hu header.s=20151130 header.b=RKW3/zaP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=blackhole.kfki.hu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751959AbdKFImC (ORCPT + 98 others); Mon, 6 Nov 2017 03:42:02 -0500 Received: from smtp1.kfki.hu ([148.6.0.26]:57606 "EHLO smtp1.kfki.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750853AbdKFImA (ORCPT ); Mon, 6 Nov 2017 03:42:00 -0500 Received: from localhost (localhost [127.0.0.1]) by smtp1.kfki.hu (Postfix) with ESMTP id 9EE643C80103; Mon, 6 Nov 2017 09:41:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= blackhole.kfki.hu; h=mime-version:user-agent:references :message-id:in-reply-to:from:from:date:date:received:received :received; s=20151130; t=1509957716; x=1511772117; bh=NWbrjf3ivL xf2099h4yFGDnJBrkfWz4zaxAhvzkyvDw=; b=RKW3/zaPtwM+4K9nBlSkP5Um4l W34uoMndlCc0ntW//oGLUoAbpr/5JqtiydhUwoaiN5kMUDtIttDLjGV5MwzIRDoy hNS+WsVVE1BWdodOf5JC9iYQvHI+JloKJzrTaDTa3otGjogoH/EVDoBZw/MoyPwI Ob3RrftVTPaAFe1Ng= X-Virus-Scanned: Debian amavisd-new at smtp1.kfki.hu Received: from smtp1.kfki.hu ([127.0.0.1]) by localhost (smtp1.kfki.hu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id krPK1UkRLarL; Mon, 6 Nov 2017 09:41:56 +0100 (CET) Received: from blackhole.kfki.hu (blackhole.szhk.kfki.hu [148.6.240.2]) by smtp1.kfki.hu (Postfix) with ESMTP id 40B0D3C800C1; Mon, 6 Nov 2017 09:41:55 +0100 (CET) Received: by blackhole.kfki.hu (Postfix, from userid 1000) id 86101202EF; Mon, 6 Nov 2017 09:41:55 +0100 (CET) Date: Mon, 6 Nov 2017 09:41:55 +0100 (CET) From: Jozsef Kadlecsik To: "Gustavo A. R. Silva" cc: Pablo Neira Ayuso , Florian Westphal , "David S. Miller" , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] netfilter: ipset: use swap macro instead of _manually_ swapping values In-Reply-To: <20171030221925.GA28998@embeddedor.com> Message-ID: References: <20171030221925.GA28998@embeddedor.com> User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Mon, 30 Oct 2017, Gustavo A. R. Silva wrote: > 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(-) Patch is applied in the ipset git tree and will be included in the next batch. Thanks! Best regards, Jozsef > 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 > > -- > To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > - E-mail : kadlec@blackhole.kfki.hu, kadlecsik.jozsef@wigner.mta.hu PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences H-1525 Budapest 114, POB. 49, Hungary From 1582724236383126573@xxx Mon Oct 30 22:44:14 +0000 2017 X-GM-THRID: 1582724236383126573 X-Gmail-Labels: Inbox,Category Forums