Skip to content

Commit c045337

Browse files
GustavoARSilvaummakynes
authored andcommitted
netfilter: ipset: use swap macro instead of _manually_ swapping values
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 <[email protected]> Signed-off-by: Jozsef Kadlecsik <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent a3c90f7 commit c045337

File tree

3 files changed

+6
-18
lines changed

3 files changed

+6
-18
lines changed

net/netfilter/ipset/ip_set_bitmap_ip.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,8 @@ bitmap_ip_create(struct net *net, struct ip_set *set, struct nlattr *tb[],
263263
ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP_TO], &last_ip);
264264
if (ret)
265265
return ret;
266-
if (first_ip > last_ip) {
267-
u32 tmp = first_ip;
268-
269-
first_ip = last_ip;
270-
last_ip = tmp;
271-
}
266+
if (first_ip > last_ip)
267+
swap(first_ip, last_ip);
272268
} else if (tb[IPSET_ATTR_CIDR]) {
273269
u8 cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]);
274270

net/netfilter/ipset/ip_set_bitmap_ipmac.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,8 @@ bitmap_ipmac_create(struct net *net, struct ip_set *set, struct nlattr *tb[],
337337
ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP_TO], &last_ip);
338338
if (ret)
339339
return ret;
340-
if (first_ip > last_ip) {
341-
u32 tmp = first_ip;
342-
343-
first_ip = last_ip;
344-
last_ip = tmp;
345-
}
340+
if (first_ip > last_ip)
341+
swap(first_ip, last_ip);
346342
} else if (tb[IPSET_ATTR_CIDR]) {
347343
u8 cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]);
348344

net/netfilter/ipset/ip_set_bitmap_port.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,8 @@ bitmap_port_create(struct net *net, struct ip_set *set, struct nlattr *tb[],
238238

239239
first_port = ip_set_get_h16(tb[IPSET_ATTR_PORT]);
240240
last_port = ip_set_get_h16(tb[IPSET_ATTR_PORT_TO]);
241-
if (first_port > last_port) {
242-
u16 tmp = first_port;
243-
244-
first_port = last_port;
245-
last_port = tmp;
246-
}
241+
if (first_port > last_port)
242+
swap(first_port, last_port);
247243

248244
elements = last_port - first_port + 1;
249245
set->dsize = ip_set_elem_len(set, tb, 0, 0);

0 commit comments

Comments
 (0)