Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965362AbaDJDji (ORCPT ); Wed, 9 Apr 2014 23:39:38 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:41314 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935120AbaDJDW7 (ORCPT ); Wed, 9 Apr 2014 23:22:59 -0400 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Roger Lucas , Jean Delvare , Ben Hutchings , Qiang Huang Subject: [PATCH 3.4 117/134] hwmon: Prevent some divide by zeros in FAN_TO_REG() Date: Wed, 9 Apr 2014 20:23:53 -0700 Message-Id: <20140410032314.303949802@linuxfoundation.org> X-Mailer: git-send-email 1.9.0 In-Reply-To: <20140410032259.587501440@linuxfoundation.org> References: <20140410032259.587501440@linuxfoundation.org> User-Agent: quilt/0.60-1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Carpenter commit 3806b45ba4655147a011df03242cc197ab986c43 upstream. 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 Signed-off-by: Jean Delvare [bwh: Backported to 3.2: adjust context] Signed-off-by: Ben Hutchings Cc: Qiang Huang Signed-off-by: Greg Kroah-Hartman --- drivers/hwmon/lm78.c | 2 ++ drivers/hwmon/sis5595.c | 2 ++ drivers/hwmon/vt8231.c | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) --- a/drivers/hwmon/lm78.c +++ b/drivers/hwmon/lm78.c @@ -94,6 +94,8 @@ static inline u8 FAN_TO_REG(long rpm, in { if (rpm <= 0) return 255; + if (rpm > 1350000) + return 1; return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); } --- a/drivers/hwmon/sis5595.c +++ b/drivers/hwmon/sis5595.c @@ -141,6 +141,8 @@ static inline u8 FAN_TO_REG(long rpm, in { if (rpm <= 0) return 255; + if (rpm > 1350000) + return 1; return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); } --- a/drivers/hwmon/vt8231.c +++ b/drivers/hwmon/vt8231.c @@ -145,7 +145,7 @@ static const u8 regtempmin[] = { 0x3a, 0 */ static inline u8 FAN_TO_REG(long rpm, int div) { - if (rpm == 0) + if (rpm <= 0 || rpm > 1310720) return 0; return SENSORS_LIMIT(1310720 / (rpm * div), 1, 255); } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/