Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <garsilva@embeddedor.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

authored by

Gustavo A. R. Silva and committed by
Pablo Neira Ayuso
c0453377 a3c90f7a

+6 -18
+2 -6
net/netfilter/ipset/ip_set_bitmap_ip.c
··· 263 263 ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP_TO], &last_ip); 264 264 if (ret) 265 265 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); 272 268 } else if (tb[IPSET_ATTR_CIDR]) { 273 269 u8 cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]); 274 270
+2 -6
net/netfilter/ipset/ip_set_bitmap_ipmac.c
··· 337 337 ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP_TO], &last_ip); 338 338 if (ret) 339 339 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); 346 342 } else if (tb[IPSET_ATTR_CIDR]) { 347 343 u8 cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]); 348 344
+2 -6
net/netfilter/ipset/ip_set_bitmap_port.c
··· 238 238 239 239 first_port = ip_set_get_h16(tb[IPSET_ATTR_PORT]); 240 240 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); 247 243 248 244 elements = last_port - first_port + 1; 249 245 set->dsize = ip_set_elem_len(set, tb, 0, 0);