summaryrefslogtreecommitdiffstats
path: root/lib/lcm.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lcm.c')
-rw-r--r--lib/lcm.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/lcm.c b/lib/lcm.c
new file mode 100644
index 00000000000..157cd88a6ff
--- /dev/null
+++ b/lib/lcm.c
@@ -0,0 +1,15 @@
+#include <linux/kernel.h>
+#include <linux/gcd.h>
+#include <linux/module.h>
+
+/* Lowest common multiple */
+unsigned long lcm(unsigned long a, unsigned long b)
+{
+ if (a && b)
+ return (a * b) / gcd(a, b);
+ else if (b)
+ return b;
+
+ return a;
+}
+EXPORT_SYMBOL_GPL(lcm);