Commit d2829224 authored by Florian Fainelli's avatar Florian Fainelli Committed by Linus Torvalds
Browse files

lib: add lib/gcd.c

This patch adds lib/gcd.c which contains a greatest common divider
implementation taken from sound/core/pcm_timer.c

Several usages of this new library function will be sent to subsystem

[ use swap() (pointed out by Joe)]
[ just add gcd.o to obj-y, remove Kconfig changes]
Signed-off-by: default avatarFlorian Fainelli <>
Cc: Sergei Shtylyov <>
Cc: Takashi Iwai <>
Cc: Simon Horman <>
Cc: Julius Volz <>
Cc: David S. Miller <>
Cc: Patrick McHardy <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent eae9d2ba
#ifndef _GCD_H
#define _GCD_H
#include <linux/compiler.h>
unsigned long gcd(unsigned long a, unsigned long b) __attribute_const__;
#endif /* _GCD_H */
......@@ -21,7 +21,7 @@ lib-y += kobject.o kref.o klist.o
obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \
string_helpers.o gcd.o
CFLAGS_kobject.o += -DDEBUG
#include <linux/kernel.h>
#include <linux/gcd.h>
#include <linux/module.h>
/* Greatest common divisor */
unsigned long gcd(unsigned long a, unsigned long b)
unsigned long r;
if (a < b)
swap(a, b);
while ((r = a % b) != 0) {
a = b;
b = r;
return b;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment