History

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

Linus Torvalds committed 8 years ago

Commit af3a5fe2 parents f3f106d d49dbfa5 files · +32 −12Browse files

Unified · Split

5 files
  1. Documentation/hwmon/ina2xx +1 −1
  2. drivers/hwmon/adt7475.c +17 −8
  3. drivers/hwmon/ina2xx.c +11 −2
  4. drivers/hwmon/nct6775.c +2 −0
  5. include/linux/platform_data/ina2xx.h +1 −1
Documentation/hwmon/ina2xx+1−1
@@ -32,7 +32,7 @@ Supported chips: · 31 unmodified lines
3232 Datasheet: Publicly available at the Texas Instruments website
3333 http://www.ti.com/
3434
35−Author: Lothar Felten <l-felten@ti.com>
35+Author: Lothar Felten <lothar.felten@gmail.com>
3636
3737 Description
3838 -----------
drivers/hwmon/adt7475.c+17−8
@@ -302,14 +302,18 @@ static inline u16 volt2reg(int channel, long volt, u8 bypass_attn) · 301 unmodified lines
302302 return clamp_val(reg, 0, 1023) & (0xff << 2);
303303 }
304304
305−static u16 adt7475_read_word(struct i2c_client *client, int reg)
305+static int adt7475_read_word(struct i2c_client *client, int reg)
306306 {
307− u16 val;
307+ int val1, val2;
308308
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;
311315
312− return val;
316+ return val1 | (val2 << 8);
313317 }
314318
315319 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
962966 {
963967 struct adt7475_data *data = adt7475_update_device(dev);
964968 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;
967970
968971 if (IS_ERR(data))
969972 return PTR_ERR(data);
973+ idx = clamp_val(data->range[sattr->index] & 0xf, 0,
974+ ARRAY_SIZE(pwmfreq_table) - 1);
970975
971− return sprintf(buf, "%d\n", pwmfreq_table[i]);
976+ return sprintf(buf, "%d\n", pwmfreq_table[idx]);
972977 }
973978
974979 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
10041009 char *buf)
10051010 {
10061011 struct adt7475_data *data = adt7475_update_device(dev);
1012+
1013+ if (IS_ERR(data))
1014+ return PTR_ERR(data);
1015+
10071016 return sprintf(buf, "%d\n", !!(data->config4 & CONFIG4_MAXDUTY));
10081017 }
10091018
drivers/hwmon/ina2xx.c+11−2
@@ -17,7 +17,7 @@ · 16 unmodified lines
1717 * Bi-directional Current/Power Monitor with I2C Interface
1818 * Datasheet: http://www.ti.com/product/ina230
1919 *
20− * Copyright (C) 2012 Lothar Felten <l-felten@ti.com>
20+ * Copyright (C) 2012 Lothar Felten <lothar.felten@gmail.com>
2121 * Thanks to Jan Volkering
2222 *
2323 * 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
329329 return 0;
330330 }
331331
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+
332341 static ssize_t ina2xx_store_shunt(struct device *dev,
333342 struct device_attribute *da,
334343 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
403412
404413 /* shunt resistance */
405414 static SENSOR_DEVICE_ATTR(shunt_resistor, S_IRUGO | S_IWUSR,
406− ina2xx_show_value, ina2xx_store_shunt,
415+ ina2xx_show_shunt, ina2xx_store_shunt,
407416 INA2XX_CALIBRATION);
408417
409418 /* update interval (ina226 only) */
drivers/hwmon/nct6775.c+2−0
@@ -63,6 +63,7 @@ · 62 unmodified lines
6363 #include <linux/bitops.h>
6464 #include <linux/dmi.h>
6565 #include <linux/io.h>
66+#include <linux/nospec.h>
6667 #include "lm75.h"
6768
6869 #define USE_ALTERNATE
@@ -2689,6 +2690,7 @@ store_pwm_weight_temp_sel(struct device *dev, struct device_attribute *attr, · 2620 unmodified lines
26892690 return err;
26902691 if (val > NUM_TEMP)
26912692 return -EINVAL;
2693+ val = array_index_nospec(val, NUM_TEMP + 1);
26922694 if (val && (!(data->have_temp & BIT(val - 1)) ||
26932695 !data->temp_src[val - 1]))
26942696 return -EINVAL;
include/linux/platform_data/ina2xx.h+1−1
@@ -1,7 +1,7 @@
11 /*
22 * Driver for Texas Instruments INA219, INA226 power monitor chips
33 *
4− * Copyright (C) 2012 Lothar Felten <l-felten@ti.com>
4+ * Copyright (C) 2012 Lothar Felten <lothar.felten@gmail.com>
55 *
66 * This program is free software; you can redistribute it and/or modify
77 * it under the terms of the GNU General Public License version 2 as