Skip to contentSkip to conversation

netfilter: ipset: ip_set_bitmap_port: use swap macro in bitmap_port_create

PATCH New Gustavo A. R. Silva 1 participant 1 message Oct 28, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: ipset: ip_set_bitmap_port: use swap macro in bitmap_port_create

Make use of the swap macro and remove unnecessary variable tmp. This makes the code easier to read and maintain.

This code was detected with the help of Coccinelle.

---
 net/netfilter/ipset/ip_set_bitmap_port.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
net/netfilter/ipset/ip_set_bitmap_port.c +2 -6
index 7f9bbd7..b561ca8 100644
@@ -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);
Signature · 1 line
2.7.4