aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2013-12-12 02:05:33 -0500
committerJean Delvare <khali@endymion.delvare>2013-12-12 02:05:33 -0500
commit3806b45ba4655147a011df03242cc197ab986c43 (patch)
tree6f16fdaab2125caf51cd1c9b2fb9cd9e1eb3674f /drivers/hwmon
parent33a7ab91d509fa33b4bcd3ce0038cc80298050da (diff)
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 <dan.carpenter@oracle.com> Acked-by: Roger Lucas <vt8231@hiddenengine.co.uk> Cc: stable@vger.kernel.org Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/lm78.c2
-rw-r--r--drivers/hwmon/sis5595.c2
-rw-r--r--drivers/hwmon/vt8231.c2
3 files changed, 5 insertions, 1 deletions
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)
94{ 94{
95 if (rpm <= 0) 95 if (rpm <= 0)
96 return 255; 96 return 255;
97 if (rpm > 1350000)
98 return 1;
97 return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); 99 return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
98} 100}
99 101
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c
index 1404e6319deb..72a889702f0d 100644
--- a/drivers/hwmon/sis5595.c
+++ b/drivers/hwmon/sis5595.c
@@ -141,6 +141,8 @@ static inline u8 FAN_TO_REG(long rpm, int div)
141{ 141{
142 if (rpm <= 0) 142 if (rpm <= 0)
143 return 255; 143 return 255;
144 if (rpm > 1350000)
145 return 1;
144 return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); 146 return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
145} 147}
146 148
diff --git a/drivers/hwmon/vt8231.c b/drivers/hwmon/vt8231.c
index 0e7017841f7d..aee14e2192f8 100644
--- a/drivers/hwmon/vt8231.c
+++ b/drivers/hwmon/vt8231.c
@@ -145,7 +145,7 @@ static const u8 regtempmin[] = { 0x3a, 0x3e, 0x2c, 0x2e, 0x30, 0x32 };
145 */ 145 */
146static inline u8 FAN_TO_REG(long rpm, int div) 146static inline u8 FAN_TO_REG(long rpm, int div)
147{ 147{
148 if (rpm == 0) 148 if (rpm <= 0 || rpm > 1310720)
149 return 0; 149 return 0;
150 return clamp_val(1310720 / (rpm * div), 1, 255); 150 return clamp_val(1310720 / (rpm * div), 1, 255);
151} 151}