diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-08-29 19:03:45 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-08-29 19:03:45 -0400 |
commit | af3a5fe4ddfe3d426eb025d4c3afd176efea658e (patch) | |
tree | bcc52bb9b029411da0a4b74c9a1a257bb8420758 | |
parent | f3f106dac0458e3010486860baba8fdc2a133e5e (diff) | |
parent | d49dbfade96d5b0863ca8a90122a805edd5ef50a (diff) |
Merge tag 'hwmon-for-linus-v4.19-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon fixes from Guenter Roeck:
- Fix potential Spectre v1 in nct6775
- Add error checking to adt7475 driver
- Fix reading shunt resistor value in ina2xx driver
* tag 'hwmon-for-linus-v4.19-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging:
hwmon: (nct6775) Fix potential Spectre v1
hwmon: (adt7475) Make adt7475_read_word() return errors
hwmon: (adt7475) Potential error pointer dereferences
hwmon: (ina2xx) fix sysfs shunt resistor read access
-rw-r--r-- | Documentation/hwmon/ina2xx | 2 | ||||
-rw-r--r-- | drivers/hwmon/adt7475.c | 25 | ||||
-rw-r--r-- | drivers/hwmon/ina2xx.c | 13 | ||||
-rw-r--r-- | drivers/hwmon/nct6775.c | 2 | ||||
-rw-r--r-- | include/linux/platform_data/ina2xx.h | 2 |
5 files changed, 32 insertions, 12 deletions
diff --git a/Documentation/hwmon/ina2xx b/Documentation/hwmon/ina2xx index 72d16f08e431..b8df81f6d6bc 100644 --- a/Documentation/hwmon/ina2xx +++ b/Documentation/hwmon/ina2xx | |||
@@ -32,7 +32,7 @@ Supported chips: | |||
32 | Datasheet: Publicly available at the Texas Instruments website | 32 | Datasheet: Publicly available at the Texas Instruments website |
33 | http://www.ti.com/ | 33 | http://www.ti.com/ |
34 | 34 | ||
35 | Author: Lothar Felten <l-felten@ti.com> | 35 | Author: Lothar Felten <lothar.felten@gmail.com> |
36 | 36 | ||
37 | Description | 37 | Description |
38 | ----------- | 38 | ----------- |
diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 90837f7c7d0f..f4c7516eb989 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c | |||
@@ -302,14 +302,18 @@ static inline u16 volt2reg(int channel, long volt, u8 bypass_attn) | |||
302 | return clamp_val(reg, 0, 1023) & (0xff << 2); | 302 | return clamp_val(reg, 0, 1023) & (0xff << 2); |
303 | } | 303 | } |
304 | 304 | ||
305 | static u16 adt7475_read_word(struct i2c_client *client, int reg) | 305 | static int adt7475_read_word(struct i2c_client *client, int reg) |
306 | { | 306 | { |
307 | u16 val; | 307 | int val1, val2; |
308 | 308 | ||
309 | val = i2c_smbus_read_byte_data(client, reg); | 309 | val1 = i2c_smbus_read_byte_data(client, reg); |
310 | val |= (i2c_smbus_read_byte_data(client, reg + 1) << 8); | 310 | if (val1 < 0) |
311 | return val1; | ||
312 | val2 = i2c_smbus_read_byte_data(client, reg + 1); | ||
313 | if (val2 < 0) | ||
314 | return val2; | ||
311 | 315 | ||
312 | return val; | 316 | return val1 | (val2 << 8); |
313 | } | 317 | } |
314 | 318 | ||
315 | static void adt7475_write_word(struct i2c_client *client, int reg, u16 val) | 319 | static void adt7475_write_word(struct i2c_client *client, int reg, u16 val) |
@@ -962,13 +966,14 @@ static ssize_t show_pwmfreq(struct device *dev, struct device_attribute *attr, | |||
962 | { | 966 | { |
963 | struct adt7475_data *data = adt7475_update_device(dev); | 967 | struct adt7475_data *data = adt7475_update_device(dev); |
964 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); | 968 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
965 | int i = clamp_val(data->range[sattr->index] & 0xf, 0, | 969 | int idx; |
966 | ARRAY_SIZE(pwmfreq_table) - 1); | ||
967 | 970 | ||
968 | if (IS_ERR(data)) | 971 | if (IS_ERR(data)) |
969 | return PTR_ERR(data); | 972 | return PTR_ERR(data); |
973 | idx = clamp_val(data->range[sattr->index] & 0xf, 0, | ||
974 | ARRAY_SIZE(pwmfreq_table) - 1); | ||
970 | 975 | ||
971 | return sprintf(buf, "%d\n", pwmfreq_table[i]); | 976 | return sprintf(buf, "%d\n", pwmfreq_table[idx]); |
972 | } | 977 | } |
973 | 978 | ||
974 | static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr, | 979 | static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr, |
@@ -1004,6 +1009,10 @@ static ssize_t pwm_use_point2_pwm_at_crit_show(struct device *dev, | |||
1004 | char *buf) | 1009 | char *buf) |
1005 | { | 1010 | { |
1006 | struct adt7475_data *data = adt7475_update_device(dev); | 1011 | struct adt7475_data *data = adt7475_update_device(dev); |
1012 | |||
1013 | if (IS_ERR(data)) | ||
1014 | return PTR_ERR(data); | ||
1015 | |||
1007 | return sprintf(buf, "%d\n", !!(data->config4 & CONFIG4_MAXDUTY)); | 1016 | return sprintf(buf, "%d\n", !!(data->config4 & CONFIG4_MAXDUTY)); |
1008 | } | 1017 | } |
1009 | 1018 | ||
diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c index e9e6aeabbf84..71d3445ba869 100644 --- a/drivers/hwmon/ina2xx.c +++ b/drivers/hwmon/ina2xx.c | |||
@@ -17,7 +17,7 @@ | |||
17 | * Bi-directional Current/Power Monitor with I2C Interface | 17 | * Bi-directional Current/Power Monitor with I2C Interface |
18 | * Datasheet: http://www.ti.com/product/ina230 | 18 | * Datasheet: http://www.ti.com/product/ina230 |
19 | * | 19 | * |
20 | * Copyright (C) 2012 Lothar Felten <l-felten@ti.com> | 20 | * Copyright (C) 2012 Lothar Felten <lothar.felten@gmail.com> |
21 | * Thanks to Jan Volkering | 21 | * Thanks to Jan Volkering |
22 | * | 22 | * |
23 | * This program is free software; you can redistribute it and/or modify | 23 | * This program is free software; you can redistribute it and/or modify |
@@ -329,6 +329,15 @@ static int ina2xx_set_shunt(struct ina2xx_data *data, long val) | |||
329 | return 0; | 329 | return 0; |
330 | } | 330 | } |
331 | 331 | ||
332 | static ssize_t ina2xx_show_shunt(struct device *dev, | ||
333 | struct device_attribute *da, | ||
334 | char *buf) | ||
335 | { | ||
336 | struct ina2xx_data *data = dev_get_drvdata(dev); | ||
337 | |||
338 | return snprintf(buf, PAGE_SIZE, "%li\n", data->rshunt); | ||
339 | } | ||
340 | |||
332 | static ssize_t ina2xx_store_shunt(struct device *dev, | 341 | static ssize_t ina2xx_store_shunt(struct device *dev, |
333 | struct device_attribute *da, | 342 | struct device_attribute *da, |
334 | const char *buf, size_t count) | 343 | const char *buf, size_t count) |
@@ -403,7 +412,7 @@ static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, ina2xx_show_value, NULL, | |||
403 | 412 | ||
404 | /* shunt resistance */ | 413 | /* shunt resistance */ |
405 | static SENSOR_DEVICE_ATTR(shunt_resistor, S_IRUGO | S_IWUSR, | 414 | static SENSOR_DEVICE_ATTR(shunt_resistor, S_IRUGO | S_IWUSR, |
406 | ina2xx_show_value, ina2xx_store_shunt, | 415 | ina2xx_show_shunt, ina2xx_store_shunt, |
407 | INA2XX_CALIBRATION); | 416 | INA2XX_CALIBRATION); |
408 | 417 | ||
409 | /* update interval (ina226 only) */ | 418 | /* update interval (ina226 only) */ |
diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c index c6bd61e4695a..944f5b63aecd 100644 --- a/drivers/hwmon/nct6775.c +++ b/drivers/hwmon/nct6775.c | |||
@@ -63,6 +63,7 @@ | |||
63 | #include <linux/bitops.h> | 63 | #include <linux/bitops.h> |
64 | #include <linux/dmi.h> | 64 | #include <linux/dmi.h> |
65 | #include <linux/io.h> | 65 | #include <linux/io.h> |
66 | #include <linux/nospec.h> | ||
66 | #include "lm75.h" | 67 | #include "lm75.h" |
67 | 68 | ||
68 | #define USE_ALTERNATE | 69 | #define USE_ALTERNATE |
@@ -2689,6 +2690,7 @@ store_pwm_weight_temp_sel(struct device *dev, struct device_attribute *attr, | |||
2689 | return err; | 2690 | return err; |
2690 | if (val > NUM_TEMP) | 2691 | if (val > NUM_TEMP) |
2691 | return -EINVAL; | 2692 | return -EINVAL; |
2693 | val = array_index_nospec(val, NUM_TEMP + 1); | ||
2692 | if (val && (!(data->have_temp & BIT(val - 1)) || | 2694 | if (val && (!(data->have_temp & BIT(val - 1)) || |
2693 | !data->temp_src[val - 1])) | 2695 | !data->temp_src[val - 1])) |
2694 | return -EINVAL; | 2696 | return -EINVAL; |
diff --git a/include/linux/platform_data/ina2xx.h b/include/linux/platform_data/ina2xx.h index 9abc0ca7259b..9f0aa1b48c78 100644 --- a/include/linux/platform_data/ina2xx.h +++ b/include/linux/platform_data/ina2xx.h | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Driver for Texas Instruments INA219, INA226 power monitor chips | 2 | * Driver for Texas Instruments INA219, INA226 power monitor chips |
3 | * | 3 | * |
4 | * Copyright (C) 2012 Lothar Felten <l-felten@ti.com> | 4 | * Copyright (C) 2012 Lothar Felten <lothar.felten@gmail.com> |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License version 2 as | 7 | * it under the terms of the GNU General Public License version 2 as |