Florian Fainelli | d282922 | 2009-06-17 16:28:38 -0700 | [diff] [blame] | 1 | #include <linux/kernel.h> |
| 2 | #include <linux/gcd.h> |
Paul Gortmaker | 8bc3bcc | 2011-11-16 21:29:17 -0500 | [diff] [blame] | 3 | #include <linux/export.h> |
Florian Fainelli | d282922 | 2009-06-17 16:28:38 -0700 | [diff] [blame] | 4 | |
| 5 | /* Greatest common divisor */ |
| 6 | unsigned long gcd(unsigned long a, unsigned long b) |
| 7 | { |
| 8 | unsigned long r; |
| 9 | |
| 10 | if (a < b) |
| 11 | swap(a, b); |
Davidlohr Bueso | e968756 | 2012-10-04 17:13:18 -0700 | [diff] [blame] | 12 | |
| 13 | if (!b) |
| 14 | return a; |
Florian Fainelli | d282922 | 2009-06-17 16:28:38 -0700 | [diff] [blame] | 15 | while ((r = a % b) != 0) { |
| 16 | a = b; |
| 17 | b = r; |
| 18 | } |
| 19 | return b; |
| 20 | } |
| 21 | EXPORT_SYMBOL_GPL(gcd); |