From: Davidlohr Bueso Date: Fri, 5 Oct 2012 00:13:18 +0000 (-0700) Subject: lib/gcd.c: prevent possible div by 0 X-Git-Tag: upstream/snapshot3+hdmi~6530^2~113 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;ds=sidebyside;h=e96875677fb2b7cb739c5d7769824dff7260d31d;p=platform%2Fadaptation%2Frenesas_rcar%2Frenesas_kernel.git lib/gcd.c: prevent possible div by 0 Account for all properties when a and/or b are 0: gcd(0, 0) = 0 gcd(a, 0) = a gcd(0, b) = b Fixes no known problems in current kernels. Signed-off-by: Davidlohr Bueso Cc: Eric Dumazet Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/lib/gcd.c b/lib/gcd.c index cce4f3c..3657f12 100644 --- a/lib/gcd.c +++ b/lib/gcd.c @@ -9,6 +9,9 @@ unsigned long gcd(unsigned long a, unsigned long b) if (a < b) swap(a, b); + + if (!b) + return a; while ((r = a % b) != 0) { a = b; b = r;