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
Unified · Split
| @@ -32,7 +32,7 @@ Supported chips: · 31 unmodified lines | ||
| 32 | 32 | Datasheet: Publicly available at the Texas Instruments website |
| 33 | 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 | 37 | Description |
| 38 | 38 | ----------- |
| @@ -302,14 +302,18 @@ static inline u16 volt2reg(int channel, long volt, u8 bypass_attn) · 301 unmodified lines | ||
| 302 | 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); | |
| 310 | − val |= (i2c_smbus_read_byte_data(client, reg + 1) << 8); | |
| 309 | + val1 = i2c_smbus_read_byte_data(client, reg); | |
| 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 | 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, · 646 unmodified lines | ||
| 962 | 966 | { |
| 963 | 967 | struct adt7475_data *data = adt7475_update_device(dev); |
| 964 | 968 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 965 | − int i = clamp_val(data->range[sattr->index] & 0xf, 0, | |
| 966 | − ARRAY_SIZE(pwmfreq_table) - 1); | |
| 969 | + int idx; | |
| 967 | 970 | |
| 968 | 971 | if (IS_ERR(data)) |
| 969 | 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 | 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, · 29 unmodified lines | ||
| 1004 | 1009 | char *buf) |
| 1005 | 1010 | { |
| 1006 | 1011 | struct adt7475_data *data = adt7475_update_device(dev); |
| 1012 | + | |
| 1013 | + if (IS_ERR(data)) | |
| 1014 | + return PTR_ERR(data); | |
| 1015 | + | |
| 1007 | 1016 | return sprintf(buf, "%d\n", !!(data->config4 & CONFIG4_MAXDUTY)); |
| 1008 | 1017 | } |
| 1009 | 1018 | |
| @@ -17,7 +17,7 @@ · 16 unmodified lines | ||
| 17 | 17 | * Bi-directional Current/Power Monitor with I2C Interface |
| 18 | 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 | 21 | * Thanks to Jan Volkering |
| 22 | 22 | * |
| 23 | 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) · 305 unmodified lines | ||
| 329 | 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 | 341 | static ssize_t ina2xx_store_shunt(struct device *dev, |
| 333 | 342 | struct device_attribute *da, |
| 334 | 343 | const char *buf, size_t count) |
| @@ -403,7 +412,7 @@ static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, ina2xx_show_value, NULL, · 68 unmodified lines | ||
| 403 | 412 | |
| 404 | 413 | /* shunt resistance */ |
| 405 | 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 | 416 | INA2XX_CALIBRATION); |
| 408 | 417 | |
| 409 | 418 | /* update interval (ina226 only) */ |
| @@ -63,6 +63,7 @@ · 62 unmodified lines | ||
| 63 | 63 | #include <linux/bitops.h> |
| 64 | 64 | #include <linux/dmi.h> |
| 65 | 65 | #include <linux/io.h> |
| 66 | +#include <linux/nospec.h> | |
| 66 | 67 | #include "lm75.h" |
| 67 | 68 | |
| 68 | 69 | #define USE_ALTERNATE |
| @@ -2689,6 +2690,7 @@ store_pwm_weight_temp_sel(struct device *dev, struct device_attribute *attr, · 2620 unmodified lines | ||
| 2689 | 2690 | return err; |
| 2690 | 2691 | if (val > NUM_TEMP) |
| 2691 | 2692 | return -EINVAL; |
| 2693 | + val = array_index_nospec(val, NUM_TEMP + 1); | |
| 2692 | 2694 | if (val && (!(data->have_temp & BIT(val - 1)) || |
| 2693 | 2695 | !data->temp_src[val - 1])) |
| 2694 | 2696 | return -EINVAL; |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /* |
| 2 | 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 | 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | 7 | * it under the terms of the GNU General Public License version 2 as |