Commit d2829224619866daf336141b71550e223a198838

Authored by Florian Fainelli
Committed by Linus Torvalds
1 parent eae9d2ba0c

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
maintainers.

[akpm@linux-foundation.org: use swap() (pointed out by Joe)]
[akpm@linux-foundation.org: just add gcd.o to obj-y, remove Kconfig changes]
Signed-off-by: Florian Fainelli <florian@openwrt.org>
Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Cc: Takashi Iwai <tiwai@suse.de>
Cc: Simon Horman <horms@verge.net.au>
Cc: Julius Volz <juliusv@google.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Patrick McHardy <kaber@trash.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 3 changed files with 27 additions and 1 deletions Side-by-side Diff

  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 */
... ... @@ -21,7 +21,7 @@
21 21  
22 22 obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
23 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 26 ifeq ($(CONFIG_DEBUG_KOBJECT),y)
27 27 CFLAGS_kobject.o += -DDEBUG
  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);