RE: [PATCH 3.2 140/185] hwmon: Prevent some divide by zeros in FAN_TO_REG()

2013-12-30 Thread vt8231
Hi Ben,

The VT8231 patch looks OK to me.  Thanks for your help.

Best regards,

Roger

-Original Message-
From: Ben Hutchings [mailto:b...@decadent.org.uk] 
Sent: 29 December 2013 02:09
To: linux-kernel@vger.kernel.org; sta...@vger.kernel.org
Cc: a...@linux-foundation.org; Roger Lucas; Dan Carpenter; Jean Delvare
Subject: [PATCH 3.2 140/185] hwmon: Prevent some divide by zeros in
FAN_TO_REG()

3.2.54-rc1 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 
---
 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
@@ -90,6 +90,8 @@ static inline u8 FAN_TO_REG(long rpm, in
 {
if (rpm <= 0)
return 255;
+   if (rpm > 135)
+   return 1;
return SENSORS_LIMIT((135 + rpm * div / 2) / (rpm * div), 1,
254);
 }
 
--- a/drivers/hwmon/sis5595.c
+++ b/drivers/hwmon/sis5595.c
@@ -133,6 +133,8 @@ static inline u8 FAN_TO_REG(long rpm, in
 {
if (rpm <= 0)
return 255;
+   if (rpm > 135)
+   return 1;
return SENSORS_LIMIT((135 + rpm * div / 2) / (rpm * div), 1,
254);
 }
 
--- a/drivers/hwmon/vt8231.c
+++ b/drivers/hwmon/vt8231.c
@@ -139,7 +139,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 majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3.2 140/185] hwmon: Prevent some divide by zeros in FAN_TO_REG()

2013-12-28 Thread Ben Hutchings
3.2.54-rc1 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 
---
 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
@@ -90,6 +90,8 @@ static inline u8 FAN_TO_REG(long rpm, in
 {
if (rpm <= 0)
return 255;
+   if (rpm > 135)
+   return 1;
return SENSORS_LIMIT((135 + rpm * div / 2) / (rpm * div), 1, 254);
 }
 
--- a/drivers/hwmon/sis5595.c
+++ b/drivers/hwmon/sis5595.c
@@ -133,6 +133,8 @@ static inline u8 FAN_TO_REG(long rpm, in
 {
if (rpm <= 0)
return 255;
+   if (rpm > 135)
+   return 1;
return SENSORS_LIMIT((135 + rpm * div / 2) / (rpm * div), 1, 254);
 }
 
--- a/drivers/hwmon/vt8231.c
+++ b/drivers/hwmon/vt8231.c
@@ -139,7 +139,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 majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/