From: Davidlohr Bueso Date: Fri, 28 Sep 2012 00:20:25 +0000 (+1000) Subject: lib/gcd.c: prevent possible div by 0 X-Git-Tag: next-20121005~1^2~122 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=8a578fc3fb933c06aee270f7a0642c86ff469954;p=karo-tx-linux.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 --- diff --git a/lib/gcd.c b/lib/gcd.c index cce4f3cd14b3..3657f129d7b8 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;