lkml.org 
[lkml]   [2009]   [Jun]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/8] add lib/gcd.c
On Thu, 04 Jun 2009 08:57:24 -0700 Joe Perches <joe@perches.com> wrote:

> On Thu, 2009-06-04 at 16:39 +0200, Florian Fainelli wrote:
> > diff --git a/lib/gcd.c b/lib/gcd.c
> > new file mode 100644
> > index 0000000..6634741
> > --- /dev/null
> > +++ b/lib/gcd.c
> > @@ -0,0 +1,20 @@
> > +#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) {
> > + r = a;
> > + a = b;
> > + b = r;
> swap(a, b)

yup

> > + }
> > + while ((r = a % b) != 0) {
> > + a = b;
> > + b = r;
> > + }
> > + return b;
> > +}
> > +EXPORT_SYMBOL_GPL(gcd);
>
> Shouldn't a generic gcd protect against a div0
> if gcd(0,0)?

nope. It's a caller bug, there's nothing the callee can do to fix it,
so an oops is a fine response.



\
 
 \ /
  Last update: 2009-06-04 21:09    [W:0.148 / U:0.488 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site