aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2014-08-23 14:58:54 -0400
committerDavid S. Miller <davem@davemloft.net>2014-08-23 15:21:21 -0400
commit8fc54f68919298ff9689d980efb495707ef43f30 (patch)
treec8a0c89621a9e670be02764a357bb6e73ed7ab6c /net/ipv4
parent690e36e726d00d2528bc569809048adf61550d80 (diff)
net: use reciprocal_scale() helper
Replace open codings of (((u64) <x> * <y>) >> 32) with reciprocal_scale(). Signed-off-by: Daniel Borkmann <dborkman@redhat.com> Cc: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/inet_hashtables.c2
-rw-r--r--net/ipv4/netfilter/ipt_CLUSTERIP.c2
-rw-r--r--net/ipv4/udp.c6
3 files changed, 5 insertions, 5 deletions
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 43116e8c8e13..9111a4e22155 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -229,7 +229,7 @@ begin:
229 } 229 }
230 } else if (score == hiscore && reuseport) { 230 } else if (score == hiscore && reuseport) {
231 matches++; 231 matches++;
232 if (((u64)phash * matches) >> 32 == 0) 232 if (reciprocal_scale(phash, matches) == 0)
233 result = sk; 233 result = sk;
234 phash = next_pseudo_random32(phash); 234 phash = next_pseudo_random32(phash);
235 } 235 }
diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
index 2510c02c2d21..e90f83a3415b 100644
--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
@@ -285,7 +285,7 @@ clusterip_hashfn(const struct sk_buff *skb,
285 } 285 }
286 286
287 /* node numbers are 1..n, not 0..n */ 287 /* node numbers are 1..n, not 0..n */
288 return (((u64)hashval * config->num_total_nodes) >> 32) + 1; 288 return reciprocal_scale(hashval, config->num_total_nodes) + 1;
289} 289}
290 290
291static inline int 291static inline int
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index f57c0e4c2326..32f9571e776b 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -224,7 +224,7 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
224 remaining = (high - low) + 1; 224 remaining = (high - low) + 1;
225 225
226 rand = prandom_u32(); 226 rand = prandom_u32();
227 first = (((u64)rand * remaining) >> 32) + low; 227 first = reciprocal_scale(rand, remaining) + low;
228 /* 228 /*
229 * force rand to be an odd multiple of UDP_HTABLE_SIZE 229 * force rand to be an odd multiple of UDP_HTABLE_SIZE
230 */ 230 */
@@ -448,7 +448,7 @@ begin:
448 } 448 }
449 } else if (score == badness && reuseport) { 449 } else if (score == badness && reuseport) {
450 matches++; 450 matches++;
451 if (((u64)hash * matches) >> 32 == 0) 451 if (reciprocal_scale(hash, matches) == 0)
452 result = sk; 452 result = sk;
453 hash = next_pseudo_random32(hash); 453 hash = next_pseudo_random32(hash);
454 } 454 }
@@ -529,7 +529,7 @@ begin:
529 } 529 }
530 } else if (score == badness && reuseport) { 530 } else if (score == badness && reuseport) {
531 matches++; 531 matches++;
532 if (((u64)hash * matches) >> 32 == 0) 532 if (reciprocal_scale(hash, matches) == 0)
533 result = sk; 533 result = sk;
534 hash = next_pseudo_random32(hash); 534 hash = next_pseudo_random32(hash);
535 } 535 }