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
This commit is contained in:
commit
af3a5fe4dd
|
@ -32,7 +32,7 @@ Supported chips:
|
|||
Datasheet: Publicly available at the Texas Instruments website
|
||||
http://www.ti.com/
|
||||
|
||||
Author: Lothar Felten <l-felten@ti.com>
|
||||
Author: Lothar Felten <lothar.felten@gmail.com>
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
|
|
@ -302,14 +302,18 @@ static inline u16 volt2reg(int channel, long volt, u8 bypass_attn)
|
|||
return clamp_val(reg, 0, 1023) & (0xff << 2);
|
||||
}
|
||||
|
||||
static u16 adt7475_read_word(struct i2c_client *client, int reg)
|
||||
static int adt7475_read_word(struct i2c_client *client, int reg)
|
||||
{
|
||||
u16 val;
|
||||
int val1, val2;
|
||||
|
||||
val = i2c_smbus_read_byte_data(client, reg);
|
||||
val |= (i2c_smbus_read_byte_data(client, reg + 1) << 8);
|
||||
val1 = i2c_smbus_read_byte_data(client, reg);
|
||||
if (val1 < 0)
|
||||
return val1;
|
||||
val2 = i2c_smbus_read_byte_data(client, reg + 1);
|
||||
if (val2 < 0)
|
||||
return val2;
|
||||
|
||||
return val;
|
||||
return val1 | (val2 << 8);
|
||||
}
|
||||
|
||||
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,
|
|||
{
|
||||
struct adt7475_data *data = adt7475_update_device(dev);
|
||||
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
|
||||
int i = clamp_val(data->range[sattr->index] & 0xf, 0,
|
||||
ARRAY_SIZE(pwmfreq_table) - 1);
|
||||
int idx;
|
||||
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
idx = clamp_val(data->range[sattr->index] & 0xf, 0,
|
||||
ARRAY_SIZE(pwmfreq_table) - 1);
|
||||
|
||||
return sprintf(buf, "%d\n", pwmfreq_table[i]);
|
||||
return sprintf(buf, "%d\n", pwmfreq_table[idx]);
|
||||
}
|
||||
|
||||
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,
|
|||
char *buf)
|
||||
{
|
||||
struct adt7475_data *data = adt7475_update_device(dev);
|
||||
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
|
||||
return sprintf(buf, "%d\n", !!(data->config4 & CONFIG4_MAXDUTY));
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* Bi-directional Current/Power Monitor with I2C Interface
|
||||
* Datasheet: http://www.ti.com/product/ina230
|
||||
*
|
||||
* Copyright (C) 2012 Lothar Felten <l-felten@ti.com>
|
||||
* Copyright (C) 2012 Lothar Felten <lothar.felten@gmail.com>
|
||||
* Thanks to Jan Volkering
|
||||
*
|
||||
* 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)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t ina2xx_show_shunt(struct device *dev,
|
||||
struct device_attribute *da,
|
||||
char *buf)
|
||||
{
|
||||
struct ina2xx_data *data = dev_get_drvdata(dev);
|
||||
|
||||
return snprintf(buf, PAGE_SIZE, "%li\n", data->rshunt);
|
||||
}
|
||||
|
||||
static ssize_t ina2xx_store_shunt(struct device *dev,
|
||||
struct device_attribute *da,
|
||||
const char *buf, size_t count)
|
||||
|
@ -403,7 +412,7 @@ static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, ina2xx_show_value, NULL,
|
|||
|
||||
/* shunt resistance */
|
||||
static SENSOR_DEVICE_ATTR(shunt_resistor, S_IRUGO | S_IWUSR,
|
||||
ina2xx_show_value, ina2xx_store_shunt,
|
||||
ina2xx_show_shunt, ina2xx_store_shunt,
|
||||
INA2XX_CALIBRATION);
|
||||
|
||||
/* update interval (ina226 only) */
|
||||
|
|
|
@ -63,6 +63,7 @@
|
|||
#include <linux/bitops.h>
|
||||
#include <linux/dmi.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/nospec.h>
|
||||
#include "lm75.h"
|
||||
|
||||
#define USE_ALTERNATE
|
||||
|
@ -2689,6 +2690,7 @@ store_pwm_weight_temp_sel(struct device *dev, struct device_attribute *attr,
|
|||
return err;
|
||||
if (val > NUM_TEMP)
|
||||
return -EINVAL;
|
||||
val = array_index_nospec(val, NUM_TEMP + 1);
|
||||
if (val && (!(data->have_temp & BIT(val - 1)) ||
|
||||
!data->temp_src[val - 1]))
|
||||
return -EINVAL;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Driver for Texas Instruments INA219, INA226 power monitor chips
|
||||
*
|
||||
* Copyright (C) 2012 Lothar Felten <l-felten@ti.com>
|
||||
* Copyright (C) 2012 Lothar Felten <lothar.felten@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
|
|
Loading…
Reference in New Issue