summaryrefslogtreecommitdiffstats
path: root/kernel/lib/gcd.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/lib/gcd.c')
-rw-r--r--kernel/lib/gcd.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/kernel/lib/gcd.c b/kernel/lib/gcd.c
new file mode 100644
index 000000000..3657f129d
--- /dev/null
+++ b/kernel/lib/gcd.c
@@ -0,0 +1,21 @@
+#include <linux/kernel.h>
+#include <linux/gcd.h>
+#include <linux/export.h>
+
+/* Greatest common divisor */
+unsigned long gcd(unsigned long a, unsigned long b)
+{
+ unsigned long r;
+
+ if (a < b)
+ swap(a, b);
+
+ if (!b)
+ return a;
+ while ((r = a % b) != 0) {
+ a = b;
+ b = r;
+ }
+ return b;
+}
+EXPORT_SYMBOL_GPL(gcd);