aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-08-14 11:55:13 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-08-14 11:55:13 -0400
commit82f05a08e27755835c948b7a45b86fac9e114e1d (patch)
tree2fa6a102f3611c2aecb48e2845e83e86d560719f /drivers/hwmon
parentae36e95cf81c98b111b84317adeb358aaffa80e2 (diff)
parent6ddd855c13bcd324a2d9756134e6b57c659cfde6 (diff)
Merge tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon fixes from Guenter Roeck: "Several bug fixes in various drivers, plus a minor cleanup in the tmp103 driver" * tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: hwmon: (tmp103) Remove duplicate test for I2C_FUNC_SMBUS_BYTE_DATA functionality hwmon: (w83793) Fix vrm write operation hwmon: (w83791d) Fix vrm write operation hwmon: (w83627hf) Fix vrm write operation hwmon: (vt1211) Fix vrm write operation hwmon: (pc87360) Fix vrm write operation hwmon: (lm87) Fix vrm write operation hwmon: (asb100) Fix vrm write operation hwmon: (adm1026) Fix vrm write operation hwmon: (adm1025) Fix vrm write operation hwmon: (hih6130) Fix missing hih6130->write_length setting hwmon: (dme1737) Prevent overflow problem when writing large limits hwmon: (emc6w201) Fix temperature limit range hwmon: (ads1015) Fix out-of-bounds array access hwmon: (lm92) Prevent overflow problem when writing large limits
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/adm1025.c3
-rw-r--r--drivers/hwmon/adm1026.c3
-rw-r--r--drivers/hwmon/ads1015.c2
-rw-r--r--drivers/hwmon/asb100.c4
-rw-r--r--drivers/hwmon/dme1737.c33
-rw-r--r--drivers/hwmon/emc6w201.c4
-rw-r--r--drivers/hwmon/hih6130.c3
-rw-r--r--drivers/hwmon/lm87.c4
-rw-r--r--drivers/hwmon/lm92.c13
-rw-r--r--drivers/hwmon/pc87360.c3
-rw-r--r--drivers/hwmon/tmp103.c7
-rw-r--r--drivers/hwmon/vt1211.c3
-rw-r--r--drivers/hwmon/w83627hf.c3
-rw-r--r--drivers/hwmon/w83791d.c3
-rw-r--r--drivers/hwmon/w83793.c3
15 files changed, 60 insertions, 31 deletions
diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c
index d3d0e8cf27b4..d6c767ace916 100644
--- a/drivers/hwmon/adm1025.c
+++ b/drivers/hwmon/adm1025.c
@@ -382,6 +382,9 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
382 if (err) 382 if (err)
383 return err; 383 return err;
384 384
385 if (val > 255)
386 return -EINVAL;
387
385 data->vrm = val; 388 data->vrm = val;
386 return count; 389 return count;
387} 390}
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c
index ca8430f92564..e67b9a50ac7c 100644
--- a/drivers/hwmon/adm1026.c
+++ b/drivers/hwmon/adm1026.c
@@ -1085,6 +1085,9 @@ static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
1085 if (err) 1085 if (err)
1086 return err; 1086 return err;
1087 1087
1088 if (val > 255)
1089 return -EINVAL;
1090
1088 data->vrm = val; 1091 data->vrm = val;
1089 return count; 1092 return count;
1090} 1093}
diff --git a/drivers/hwmon/ads1015.c b/drivers/hwmon/ads1015.c
index 22e0c926989d..126516414c11 100644
--- a/drivers/hwmon/ads1015.c
+++ b/drivers/hwmon/ads1015.c
@@ -212,6 +212,7 @@ static int ads1015_get_channels_config_of(struct i2c_client *client)
212 dev_err(&client->dev, 212 dev_err(&client->dev,
213 "invalid gain on %s\n", 213 "invalid gain on %s\n",
214 node->full_name); 214 node->full_name);
215 return -EINVAL;
215 } 216 }
216 } 217 }
217 218
@@ -222,6 +223,7 @@ static int ads1015_get_channels_config_of(struct i2c_client *client)
222 dev_err(&client->dev, 223 dev_err(&client->dev,
223 "invalid data_rate on %s\n", 224 "invalid data_rate on %s\n",
224 node->full_name); 225 node->full_name);
226 return -EINVAL;
225 } 227 }
226 } 228 }
227 229
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c
index f96063680e58..272fcc837ecc 100644
--- a/drivers/hwmon/asb100.c
+++ b/drivers/hwmon/asb100.c
@@ -510,6 +510,10 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
510 err = kstrtoul(buf, 10, &val); 510 err = kstrtoul(buf, 10, &val);
511 if (err) 511 if (err)
512 return err; 512 return err;
513
514 if (val > 255)
515 return -EINVAL;
516
513 data->vrm = val; 517 data->vrm = val;
514 return count; 518 return count;
515} 519}
diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c
index 4ae3fff13f44..bea0a344fab5 100644
--- a/drivers/hwmon/dme1737.c
+++ b/drivers/hwmon/dme1737.c
@@ -247,8 +247,8 @@ struct dme1737_data {
247 u8 pwm_acz[3]; 247 u8 pwm_acz[3];
248 u8 pwm_freq[6]; 248 u8 pwm_freq[6];
249 u8 pwm_rr[2]; 249 u8 pwm_rr[2];
250 u8 zone_low[3]; 250 s8 zone_low[3];
251 u8 zone_abs[3]; 251 s8 zone_abs[3];
252 u8 zone_hyst[2]; 252 u8 zone_hyst[2];
253 u32 alarms; 253 u32 alarms;
254}; 254};
@@ -277,7 +277,7 @@ static inline int IN_FROM_REG(int reg, int nominal, int res)
277 return (reg * nominal + (3 << (res - 3))) / (3 << (res - 2)); 277 return (reg * nominal + (3 << (res - 3))) / (3 << (res - 2));
278} 278}
279 279
280static inline int IN_TO_REG(int val, int nominal) 280static inline int IN_TO_REG(long val, int nominal)
281{ 281{
282 return clamp_val((val * 192 + nominal / 2) / nominal, 0, 255); 282 return clamp_val((val * 192 + nominal / 2) / nominal, 0, 255);
283} 283}
@@ -293,7 +293,7 @@ static inline int TEMP_FROM_REG(int reg, int res)
293 return (reg * 1000) >> (res - 8); 293 return (reg * 1000) >> (res - 8);
294} 294}
295 295
296static inline int TEMP_TO_REG(int val) 296static inline int TEMP_TO_REG(long val)
297{ 297{
298 return clamp_val((val < 0 ? val - 500 : val + 500) / 1000, -128, 127); 298 return clamp_val((val < 0 ? val - 500 : val + 500) / 1000, -128, 127);
299} 299}
@@ -308,7 +308,7 @@ static inline int TEMP_RANGE_FROM_REG(int reg)
308 return TEMP_RANGE[(reg >> 4) & 0x0f]; 308 return TEMP_RANGE[(reg >> 4) & 0x0f];
309} 309}
310 310
311static int TEMP_RANGE_TO_REG(int val, int reg) 311static int TEMP_RANGE_TO_REG(long val, int reg)
312{ 312{
313 int i; 313 int i;
314 314
@@ -331,7 +331,7 @@ static inline int TEMP_HYST_FROM_REG(int reg, int ix)
331 return (((ix == 1) ? reg : reg >> 4) & 0x0f) * 1000; 331 return (((ix == 1) ? reg : reg >> 4) & 0x0f) * 1000;
332} 332}
333 333
334static inline int TEMP_HYST_TO_REG(int val, int ix, int reg) 334static inline int TEMP_HYST_TO_REG(long val, int ix, int reg)
335{ 335{
336 int hyst = clamp_val((val + 500) / 1000, 0, 15); 336 int hyst = clamp_val((val + 500) / 1000, 0, 15);
337 337
@@ -347,7 +347,7 @@ static inline int FAN_FROM_REG(int reg, int tpc)
347 return (reg == 0 || reg == 0xffff) ? 0 : 90000 * 60 / reg; 347 return (reg == 0 || reg == 0xffff) ? 0 : 90000 * 60 / reg;
348} 348}
349 349
350static inline int FAN_TO_REG(int val, int tpc) 350static inline int FAN_TO_REG(long val, int tpc)
351{ 351{
352 if (tpc) { 352 if (tpc) {
353 return clamp_val(val / tpc, 0, 0xffff); 353 return clamp_val(val / tpc, 0, 0xffff);
@@ -379,7 +379,7 @@ static inline int FAN_TYPE_FROM_REG(int reg)
379 return (edge > 0) ? 1 << (edge - 1) : 0; 379 return (edge > 0) ? 1 << (edge - 1) : 0;
380} 380}
381 381
382static inline int FAN_TYPE_TO_REG(int val, int reg) 382static inline int FAN_TYPE_TO_REG(long val, int reg)
383{ 383{
384 int edge = (val == 4) ? 3 : val; 384 int edge = (val == 4) ? 3 : val;
385 385
@@ -402,7 +402,7 @@ static int FAN_MAX_FROM_REG(int reg)
402 return 1000 + i * 500; 402 return 1000 + i * 500;
403} 403}
404 404
405static int FAN_MAX_TO_REG(int val) 405static int FAN_MAX_TO_REG(long val)
406{ 406{
407 int i; 407 int i;
408 408
@@ -460,7 +460,7 @@ static inline int PWM_ACZ_FROM_REG(int reg)
460 return acz[(reg >> 5) & 0x07]; 460 return acz[(reg >> 5) & 0x07];
461} 461}
462 462
463static inline int PWM_ACZ_TO_REG(int val, int reg) 463static inline int PWM_ACZ_TO_REG(long val, int reg)
464{ 464{
465 int acz = (val == 4) ? 2 : val - 1; 465 int acz = (val == 4) ? 2 : val - 1;
466 466
@@ -476,7 +476,7 @@ static inline int PWM_FREQ_FROM_REG(int reg)
476 return PWM_FREQ[reg & 0x0f]; 476 return PWM_FREQ[reg & 0x0f];
477} 477}
478 478
479static int PWM_FREQ_TO_REG(int val, int reg) 479static int PWM_FREQ_TO_REG(long val, int reg)
480{ 480{
481 int i; 481 int i;
482 482
@@ -510,7 +510,7 @@ static inline int PWM_RR_FROM_REG(int reg, int ix)
510 return (rr & 0x08) ? PWM_RR[rr & 0x07] : 0; 510 return (rr & 0x08) ? PWM_RR[rr & 0x07] : 0;
511} 511}
512 512
513static int PWM_RR_TO_REG(int val, int ix, int reg) 513static int PWM_RR_TO_REG(long val, int ix, int reg)
514{ 514{
515 int i; 515 int i;
516 516
@@ -528,7 +528,7 @@ static inline int PWM_RR_EN_FROM_REG(int reg, int ix)
528 return PWM_RR_FROM_REG(reg, ix) ? 1 : 0; 528 return PWM_RR_FROM_REG(reg, ix) ? 1 : 0;
529} 529}
530 530
531static inline int PWM_RR_EN_TO_REG(int val, int ix, int reg) 531static inline int PWM_RR_EN_TO_REG(long val, int ix, int reg)
532{ 532{
533 int en = (ix == 1) ? 0x80 : 0x08; 533 int en = (ix == 1) ? 0x80 : 0x08;
534 534
@@ -1481,13 +1481,16 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
1481 const char *buf, size_t count) 1481 const char *buf, size_t count)
1482{ 1482{
1483 struct dme1737_data *data = dev_get_drvdata(dev); 1483 struct dme1737_data *data = dev_get_drvdata(dev);
1484 long val; 1484 unsigned long val;
1485 int err; 1485 int err;
1486 1486
1487 err = kstrtol(buf, 10, &val); 1487 err = kstrtoul(buf, 10, &val);
1488 if (err) 1488 if (err)
1489 return err; 1489 return err;
1490 1490
1491 if (val > 255)
1492 return -EINVAL;
1493
1491 data->vrm = val; 1494 data->vrm = val;
1492 return count; 1495 return count;
1493} 1496}
diff --git a/drivers/hwmon/emc6w201.c b/drivers/hwmon/emc6w201.c
index e87da902f3ae..ada90716448d 100644
--- a/drivers/hwmon/emc6w201.c
+++ b/drivers/hwmon/emc6w201.c
@@ -252,12 +252,12 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
252 if (err < 0) 252 if (err < 0)
253 return err; 253 return err;
254 254
255 val /= 1000; 255 val = DIV_ROUND_CLOSEST(val, 1000);
256 reg = (sf == min) ? EMC6W201_REG_TEMP_LOW(nr) 256 reg = (sf == min) ? EMC6W201_REG_TEMP_LOW(nr)
257 : EMC6W201_REG_TEMP_HIGH(nr); 257 : EMC6W201_REG_TEMP_HIGH(nr);
258 258
259 mutex_lock(&data->update_lock); 259 mutex_lock(&data->update_lock);
260 data->temp[sf][nr] = clamp_val(val, -127, 128); 260 data->temp[sf][nr] = clamp_val(val, -127, 127);
261 err = emc6w201_write8(client, reg, data->temp[sf][nr]); 261 err = emc6w201_write8(client, reg, data->temp[sf][nr]);
262 mutex_unlock(&data->update_lock); 262 mutex_unlock(&data->update_lock);
263 263
diff --git a/drivers/hwmon/hih6130.c b/drivers/hwmon/hih6130.c
index 0e01c4e13e33..7b73d2002d3e 100644
--- a/drivers/hwmon/hih6130.c
+++ b/drivers/hwmon/hih6130.c
@@ -238,6 +238,9 @@ static int hih6130_probe(struct i2c_client *client,
238 hih6130->client = client; 238 hih6130->client = client;
239 mutex_init(&hih6130->lock); 239 mutex_init(&hih6130->lock);
240 240
241 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_QUICK))
242 hih6130->write_length = 1;
243
241 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, 244 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
242 hih6130, 245 hih6130,
243 hih6130_groups); 246 hih6130_groups);
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
index ba1d83d48056..a5e295826aea 100644
--- a/drivers/hwmon/lm87.c
+++ b/drivers/hwmon/lm87.c
@@ -617,6 +617,10 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
617 err = kstrtoul(buf, 10, &val); 617 err = kstrtoul(buf, 10, &val);
618 if (err) 618 if (err)
619 return err; 619 return err;
620
621 if (val > 255)
622 return -EINVAL;
623
620 data->vrm = val; 624 data->vrm = val;
621 return count; 625 return count;
622} 626}
diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c
index d2060e245ff5..cfaf70b9cba7 100644
--- a/drivers/hwmon/lm92.c
+++ b/drivers/hwmon/lm92.c
@@ -74,12 +74,9 @@ static inline int TEMP_FROM_REG(s16 reg)
74 return reg / 8 * 625 / 10; 74 return reg / 8 * 625 / 10;
75} 75}
76 76
77static inline s16 TEMP_TO_REG(int val) 77static inline s16 TEMP_TO_REG(long val)
78{ 78{
79 if (val <= -60000) 79 val = clamp_val(val, -60000, 160000);
80 return -60000 * 10 / 625 * 8;
81 if (val >= 160000)
82 return 160000 * 10 / 625 * 8;
83 return val * 10 / 625 * 8; 80 return val * 10 / 625 * 8;
84} 81}
85 82
@@ -206,10 +203,12 @@ static ssize_t set_temp_hyst(struct device *dev,
206 if (err) 203 if (err)
207 return err; 204 return err;
208 205
206 val = clamp_val(val, -120000, 220000);
209 mutex_lock(&data->update_lock); 207 mutex_lock(&data->update_lock);
210 data->temp[t_hyst] = TEMP_FROM_REG(data->temp[attr->index]) - val; 208 data->temp[t_hyst] =
209 TEMP_TO_REG(TEMP_FROM_REG(data->temp[attr->index]) - val);
211 i2c_smbus_write_word_swapped(client, LM92_REG_TEMP_HYST, 210 i2c_smbus_write_word_swapped(client, LM92_REG_TEMP_HYST,
212 TEMP_TO_REG(data->temp[t_hyst])); 211 data->temp[t_hyst]);
213 mutex_unlock(&data->update_lock); 212 mutex_unlock(&data->update_lock);
214 return count; 213 return count;
215} 214}
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c
index 988181e4cfcd..145f674c1d87 100644
--- a/drivers/hwmon/pc87360.c
+++ b/drivers/hwmon/pc87360.c
@@ -615,6 +615,9 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
615 if (err) 615 if (err)
616 return err; 616 return err;
617 617
618 if (val > 255)
619 return -EINVAL;
620
618 data->vrm = val; 621 data->vrm = val;
619 return count; 622 return count;
620} 623}
diff --git a/drivers/hwmon/tmp103.c b/drivers/hwmon/tmp103.c
index c74d2da389d9..e42964f07f67 100644
--- a/drivers/hwmon/tmp103.c
+++ b/drivers/hwmon/tmp103.c
@@ -131,13 +131,6 @@ static int tmp103_probe(struct i2c_client *client,
131 struct regmap *regmap; 131 struct regmap *regmap;
132 int ret; 132 int ret;
133 133
134 if (!i2c_check_functionality(client->adapter,
135 I2C_FUNC_SMBUS_BYTE_DATA)) {
136 dev_err(&client->dev,
137 "adapter doesn't support SMBus byte transactions\n");
138 return -ENODEV;
139 }
140
141 regmap = devm_regmap_init_i2c(client, &tmp103_regmap_config); 134 regmap = devm_regmap_init_i2c(client, &tmp103_regmap_config);
142 if (IS_ERR(regmap)) { 135 if (IS_ERR(regmap)) {
143 dev_err(dev, "failed to allocate register map\n"); 136 dev_err(dev, "failed to allocate register map\n");
diff --git a/drivers/hwmon/vt1211.c b/drivers/hwmon/vt1211.c
index 344b22ec2553..3ea57c3504e2 100644
--- a/drivers/hwmon/vt1211.c
+++ b/drivers/hwmon/vt1211.c
@@ -879,6 +879,9 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
879 if (err) 879 if (err)
880 return err; 880 return err;
881 881
882 if (val > 255)
883 return -EINVAL;
884
882 data->vrm = val; 885 data->vrm = val;
883 886
884 return count; 887 return count;
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index c1726be3654c..2f55973a8c4c 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -820,6 +820,9 @@ store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf
820 err = kstrtoul(buf, 10, &val); 820 err = kstrtoul(buf, 10, &val);
821 if (err) 821 if (err)
822 return err; 822 return err;
823
824 if (val > 255)
825 return -EINVAL;
823 data->vrm = val; 826 data->vrm = val;
824 827
825 return count; 828 return count;
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
index cb3765fec98c..001df856913f 100644
--- a/drivers/hwmon/w83791d.c
+++ b/drivers/hwmon/w83791d.c
@@ -1181,6 +1181,9 @@ static ssize_t store_vrm_reg(struct device *dev,
1181 if (err) 1181 if (err)
1182 return err; 1182 return err;
1183 1183
1184 if (val > 255)
1185 return -EINVAL;
1186
1184 data->vrm = val; 1187 data->vrm = val;
1185 return count; 1188 return count;
1186} 1189}
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index 9d63d71214ca..816aa6caf5d5 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -353,6 +353,9 @@ store_vrm(struct device *dev, struct device_attribute *attr,
353 if (err) 353 if (err)
354 return err; 354 return err;
355 355
356 if (val > 255)
357 return -EINVAL;
358
356 data->vrm = val; 359 data->vrm = val;
357 return count; 360 return count;
358} 361}