# \[PATCH 3/8\] net/netfilter/ipvs/ip\_vs\_wrr.c: use lib/gcd.c

- Subsystems: IPVS, NETWORKING \[GENERAL\], NETFILTER, THE REST
- Maintainers: Simon Horman, Julian Anastasov, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Pablo Neira Ayuso, Florian Westphal, Linus Torvalds
- List: netdev
- 2 messages, 2 authors
- Page: https://ratatoskr.run/netdev/2009/06/1259080/t

## \[PATCH 3/8\] net/netfilter/ipvs/ip\_vs\_wrr.c: use lib/gcd.c

- From: Florian Fainelli \<florian@openwrt.org\>
- Date: 2009-06-04 14:16:35 
- Message: https://ratatoskr.run/netdev/2009/06/1259080.md

```text
This patch removes the open-coded version of the
greatest common divider to use lib/gcd.c, the latter
also implementing the a < b case.

Signed-off-by: Florian Fainelli <florian@openwrt.org>
---
diff --git a/net/netfilter/ipvs/Kconfig b/net/netfilter/ipvs/Kconfig
index 79a6980..5b37675 100644
--- a/net/netfilter/ipvs/Kconfig
+++ b/net/netfilter/ipvs/Kconfig
@@ -113,6 +113,7 @@ config	IP_VS_RR
  
 config	IP_VS_WRR
         tristate "weighted round-robin scheduling" 
+	select GCD
 	---help---
 	  The weighted robin-robin scheduling algorithm directs network
 	  connections to different real servers based on server weights
diff --git a/net/netfilter/ipvs/ip_vs_wrr.c b/net/netfilter/ipvs/ip_vs_wrr.c
index f7d74ef..8701212 100644
--- a/net/netfilter/ipvs/ip_vs_wrr.c
+++ b/net/netfilter/ipvs/ip_vs_wrr.c
@@ -21,6 +21,7 @@
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/net.h>
+#include <linux/gcd.h>
 
 #include <net/ip_vs.h>
 
@@ -35,20 +36,6 @@ struct ip_vs_wrr_mark {
 };
 
 
-/*
- *    Get the gcd of server weights
- */
-static int gcd(int a, int b)
-{
-	int c;
-
-	while ((c = a % b)) {
-		a = b;
-		b = c;
-	}
-	return b;
-}
-
 static int ip_vs_wrr_gcd_weight(struct ip_vs_service *svc)
 {
 	struct ip_vs_dest *dest;
```

## Re: \[PATCH 3/8\] net/netfilter/ipvs/ip\_vs\_wrr.c: use lib/gcd.c

- From: Simon Horman \<horms@verge.net.au\>
- Date: 2009-06-07 09:07:17 
- Message: https://ratatoskr.run/netdev/2009/06/1260266.md

```text
On Thu, Jun 04, 2009 at 04:16:21PM +0200, Florian Fainelli wrote:
> This patch removes the open-coded version of the
> greatest common divider to use lib/gcd.c, the latter
> also implementing the a < b case.
> 
> Signed-off-by: Florian Fainelli <florian@openwrt.org>

Acked-by: Simon Horman <horms@verge.net.au>
```
