diff options
-rw-r--r-- | include/linux/gcd.h | 8 | ||||
-rw-r--r-- | lib/Makefile | 2 | ||||
-rw-r--r-- | lib/gcd.c | 18 |
3 files changed, 27 insertions, 1 deletions
diff --git a/include/linux/gcd.h b/include/linux/gcd.h new file mode 100644 index 000000000000..69f5e8a01bad --- /dev/null +++ b/include/linux/gcd.h | |||
@@ -0,0 +1,8 @@ | |||
1 | #ifndef _GCD_H | ||
2 | #define _GCD_H | ||
3 | |||
4 | #include <linux/compiler.h> | ||
5 | |||
6 | unsigned long gcd(unsigned long a, unsigned long b) __attribute_const__; | ||
7 | |||
8 | #endif /* _GCD_H */ | ||
diff --git a/lib/Makefile b/lib/Makefile index 8e9bcf9d3261..b6d1857bbf08 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -21,7 +21,7 @@ lib-y += kobject.o kref.o klist.o | |||
21 | 21 | ||
22 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ | 22 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ |
23 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ | 23 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ |
24 | string_helpers.o | 24 | string_helpers.o gcd.o |
25 | 25 | ||
26 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) | 26 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) |
27 | CFLAGS_kobject.o += -DDEBUG | 27 | CFLAGS_kobject.o += -DDEBUG |
diff --git a/lib/gcd.c b/lib/gcd.c new file mode 100644 index 000000000000..f879033d9822 --- /dev/null +++ b/lib/gcd.c | |||
@@ -0,0 +1,18 @@ | |||
1 | #include <linux/kernel.h> | ||
2 | #include <linux/gcd.h> | ||
3 | #include <linux/module.h> | ||
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); | ||
12 | while ((r = a % b) != 0) { | ||
13 | a = b; | ||
14 | b = r; | ||
15 | } | ||
16 | return b; | ||
17 | } | ||
18 | EXPORT_SYMBOL_GPL(gcd); | ||