From 3806b45ba4655147a011df03242cc197ab986c43 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 12 Dec 2013 08:05:33 +0100 Subject: hwmon: Prevent some divide by zeros in FAN_TO_REG() The "rpm * div" operations can overflow here, so this patch adds an upper limit to rpm to prevent that. Jean Delvare helped me with this patch. Signed-off-by: Dan Carpenter Acked-by: Roger Lucas Cc: stable@vger.kernel.org Signed-off-by: Jean Delvare --- drivers/hwmon/lm78.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/hwmon/lm78.c') diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c index 6cf6bff79003..a2f3b4a365e4 100644 --- a/drivers/hwmon/lm78.c +++ b/drivers/hwmon/lm78.c @@ -94,6 +94,8 @@ static inline u8 FAN_TO_REG(long rpm, int div) { if (rpm <= 0) return 255; + if (rpm > 1350000) + return 1; return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); } -- cgit v1.2.3