]> granicus.if.org Git - ipset/commitdiff
netfilter: ipset: use swap macro instead of _manually_ swapping values
authorGustavo A. R. Silva <garsilva@embeddedor.com>
Mon, 30 Oct 2017 22:19:25 +0000 (17:19 -0500)
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Mon, 6 Nov 2017 08:37:31 +0000 (09:37 +0100)
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 <garsilva@embeddedor.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
kernel/net/netfilter/ipset/ip_set_bitmap_ip.c
kernel/net/netfilter/ipset/ip_set_bitmap_ipmac.c
kernel/net/netfilter/ipset/ip_set_bitmap_port.c

index 4783efff0bde6b7c70707c8153563669308d995a..9f4f28d6e714df6a280efdacb8831ccfa6f840f2 100644 (file)
@@ -261,12 +261,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]);
 
index 9a065f672d3a56f33a22e38937780ab59d318c13..f7415d41e8928872339cfa02b25970fb91732a85 100644 (file)
@@ -335,12 +335,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]);
 
index 7f0c733358a428225e15afe611aad1edcd52812a..c6e1ebf0f351ae817baf3b4b516e3a0a0ecde452 100644 (file)
@@ -236,12 +236,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);