Skip to content

Commit

Permalink
Merge tag 'hwmon-for-v5.15-rc4' of git://git.kernel.org/pub/scm/linux…
Browse files Browse the repository at this point in the history
…/kernel/git/groeck/linux-staging

Pull hwmon fixes from Guenter Roeck:

 - Fixed various potential NULL pointer accesses in w8379* drivers

 - Improved error handling, fault reporting, and fixed rounding in
   thmp421 driver

 - Fixed error handling in ltc2947 driver

 - Added missing attribute to pmbus/mp2975 driver

 - Fixed attribute values in pbus/ibm-cffps, occ, and mlxreg-fan
   drivers

 - Removed unused residual code from k10temp driver

* tag 'hwmon-for-v5.15-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging:
  hwmon: (w83793) Fix NULL pointer dereference by removing unnecessary structure field
  hwmon: (w83792d) Fix NULL pointer dereference by removing unnecessary structure field
  hwmon: (w83791d) Fix NULL pointer dereference by removing unnecessary structure field
  hwmon: (pmbus/mp2975) Add missed POUT attribute for page 1 mp2975 controller
  hwmon: (pmbus/ibm-cffps) max_power_out swap changes
  hwmon: (occ) Fix P10 VRM temp sensors
  hwmon: (ltc2947) Properly handle errors when looking for the external clock
  hwmon: (tmp421) fix rounding for negative values
  hwmon: (tmp421) report /PVLD condition as fault
  hwmon: (tmp421) handle I2C errors
  hwmon: (mlxreg-fan) Return non-zero value when fan current state is enforced from sysfs
  hwmon: (k10temp) Remove residues of current and voltage
  • Loading branch information
torvalds committed Oct 3, 2021
2 parents e25ca04 + dd4d747 commit 7b66f43
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 125 deletions.
17 changes: 0 additions & 17 deletions Documentation/hwmon/k10temp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,3 @@ On Family 17h and Family 18h CPUs, additional temperature sensors may report
Core Complex Die (CCD) temperatures. Up to 8 such temperatures are reported
as temp{3..10}_input, labeled Tccd{1..8}. Actual support depends on the CPU
variant.

Various Family 17h and 18h CPUs report voltage and current telemetry
information. The following attributes may be reported.

Attribute Label Description
=============== ======= ================
in0_input Vcore Core voltage
in1_input Vsoc SoC voltage
curr1_input Icore Core current
curr2_input Isoc SoC current
=============== ======= ================

Current values are raw (unscaled) as reported by the CPU. Core current is
reported as multiples of 1A / LSB. SoC is reported as multiples of 0.25A
/ LSB. The real current is board specific. Reported currents should be seen
as rough guidance, and should be scaled using sensors3.conf as appropriate
for a given board.
6 changes: 0 additions & 6 deletions drivers/hwmon/k10temp.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,6 @@ static const struct hwmon_channel_info *k10temp_info[] = {
HWMON_T_INPUT | HWMON_T_LABEL,
HWMON_T_INPUT | HWMON_T_LABEL,
HWMON_T_INPUT | HWMON_T_LABEL),
HWMON_CHANNEL_INFO(in,
HWMON_I_INPUT | HWMON_I_LABEL,
HWMON_I_INPUT | HWMON_I_LABEL),
HWMON_CHANNEL_INFO(curr,
HWMON_C_INPUT | HWMON_C_LABEL,
HWMON_C_INPUT | HWMON_C_LABEL),
NULL
};

Expand Down
8 changes: 6 additions & 2 deletions drivers/hwmon/ltc2947-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -989,8 +989,12 @@ static int ltc2947_setup(struct ltc2947_data *st)
return ret;

/* check external clock presence */
extclk = devm_clk_get(st->dev, NULL);
if (!IS_ERR(extclk)) {
extclk = devm_clk_get_optional(st->dev, NULL);
if (IS_ERR(extclk))
return dev_err_probe(st->dev, PTR_ERR(extclk),
"Failed to get external clock\n");

if (extclk) {
unsigned long rate_hz;
u8 pre = 0, div, tbctl;
u64 aux;
Expand Down
12 changes: 9 additions & 3 deletions drivers/hwmon/mlxreg-fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev,
{
struct mlxreg_fan *fan = cdev->devdata;
unsigned long cur_state;
int i, config = 0;
u32 regval;
int i;
int err;

/*
Expand All @@ -329,6 +329,12 @@ static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev,
* overwritten.
*/
if (state >= MLXREG_FAN_SPEED_MIN && state <= MLXREG_FAN_SPEED_MAX) {
/*
* This is configuration change, which is only supported through sysfs.
* For configuration non-zero value is to be returned to avoid thermal
* statistics update.
*/
config = 1;
state -= MLXREG_FAN_MAX_STATE;
for (i = 0; i < state; i++)
fan->cooling_levels[i] = state;
Expand All @@ -343,7 +349,7 @@ static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev,

cur_state = MLXREG_FAN_PWM_DUTY2STATE(regval);
if (state < cur_state)
return 0;
return config;

state = cur_state;
}
Expand All @@ -359,7 +365,7 @@ static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev,
dev_err(fan->dev, "Failed to write PWM duty\n");
return err;
}
return 0;
return config;
}

static const struct thermal_cooling_device_ops mlxreg_fan_cooling_ops = {
Expand Down
17 changes: 5 additions & 12 deletions drivers/hwmon/occ/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,11 @@ static ssize_t occ_show_temp_10(struct device *dev,
if (val == OCC_TEMP_SENSOR_FAULT)
return -EREMOTEIO;

/*
* VRM doesn't return temperature, only alarm bit. This
* attribute maps to tempX_alarm instead of tempX_input for
* VRM
*/
if (temp->fru_type != OCC_FRU_TYPE_VRM) {
/* sensor not ready */
if (val == 0)
return -EAGAIN;
/* sensor not ready */
if (val == 0)
return -EAGAIN;

val *= 1000;
}
val *= 1000;
break;
case 2:
val = temp->fru_type;
Expand Down Expand Up @@ -886,7 +879,7 @@ static int occ_setup_sensor_attrs(struct occ *occ)
0, i);
attr++;

if (sensors->temp.version > 1 &&
if (sensors->temp.version == 2 &&
temp->fru_type == OCC_FRU_TYPE_VRM) {
snprintf(attr->name, sizeof(attr->name),
"temp%d_alarm", s);
Expand Down
10 changes: 8 additions & 2 deletions drivers/hwmon/pmbus/ibm-cffps.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,14 @@ static ssize_t ibm_cffps_debugfs_read(struct file *file, char __user *buf,
cmd = CFFPS_SN_CMD;
break;
case CFFPS_DEBUGFS_MAX_POWER_OUT:
rc = i2c_smbus_read_word_swapped(psu->client,
CFFPS_MAX_POWER_OUT_CMD);
if (psu->version == cffps1) {
rc = i2c_smbus_read_word_swapped(psu->client,
CFFPS_MAX_POWER_OUT_CMD);
} else {
rc = i2c_smbus_read_word_data(psu->client,
CFFPS_MAX_POWER_OUT_CMD);
}

if (rc < 0)
return rc;

Expand Down
2 changes: 1 addition & 1 deletion drivers/hwmon/pmbus/mp2975.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

#define MP2975_RAIL2_FUNC (PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | \
PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | \
PMBUS_PHASE_VIRTUAL)
PMBUS_HAVE_POUT | PMBUS_PHASE_VIRTUAL)

struct mp2975_data {
struct pmbus_driver_info info;
Expand Down
71 changes: 39 additions & 32 deletions drivers/hwmon/tmp421.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,71 +100,81 @@ struct tmp421_data {
s16 temp[4];
};

static int temp_from_s16(s16 reg)
static int temp_from_raw(u16 reg, bool extended)
{
/* Mask out status bits */
int temp = reg & ~0xf;

return (temp * 1000 + 128) / 256;
}

static int temp_from_u16(u16 reg)
{
/* Mask out status bits */
int temp = reg & ~0xf;

/* Add offset for extended temperature range. */
temp -= 64 * 256;
if (extended)
temp = temp - 64 * 256;
else
temp = (s16)temp;

return (temp * 1000 + 128) / 256;
return DIV_ROUND_CLOSEST(temp * 1000, 256);
}

static struct tmp421_data *tmp421_update_device(struct device *dev)
static int tmp421_update_device(struct tmp421_data *data)
{
struct tmp421_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
int ret = 0;
int i;

mutex_lock(&data->update_lock);

if (time_after(jiffies, data->last_updated + (HZ / 2)) ||
!data->valid) {
data->config = i2c_smbus_read_byte_data(client,
TMP421_CONFIG_REG_1);
ret = i2c_smbus_read_byte_data(client, TMP421_CONFIG_REG_1);
if (ret < 0)
goto exit;
data->config = ret;

for (i = 0; i < data->channels; i++) {
data->temp[i] = i2c_smbus_read_byte_data(client,
TMP421_TEMP_MSB[i]) << 8;
data->temp[i] |= i2c_smbus_read_byte_data(client,
TMP421_TEMP_LSB[i]);
ret = i2c_smbus_read_byte_data(client, TMP421_TEMP_MSB[i]);
if (ret < 0)
goto exit;
data->temp[i] = ret << 8;

ret = i2c_smbus_read_byte_data(client, TMP421_TEMP_LSB[i]);
if (ret < 0)
goto exit;
data->temp[i] |= ret;
}
data->last_updated = jiffies;
data->valid = 1;
}

exit:
mutex_unlock(&data->update_lock);

return data;
if (ret < 0) {
data->valid = 0;
return ret;
}

return 0;
}

static int tmp421_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
struct tmp421_data *tmp421 = tmp421_update_device(dev);
struct tmp421_data *tmp421 = dev_get_drvdata(dev);
int ret = 0;

ret = tmp421_update_device(tmp421);
if (ret)
return ret;

switch (attr) {
case hwmon_temp_input:
if (tmp421->config & TMP421_CONFIG_RANGE)
*val = temp_from_u16(tmp421->temp[channel]);
else
*val = temp_from_s16(tmp421->temp[channel]);
*val = temp_from_raw(tmp421->temp[channel],
tmp421->config & TMP421_CONFIG_RANGE);
return 0;
case hwmon_temp_fault:
/*
* The OPEN bit signals a fault. This is bit 0 of the temperature
* register (low byte).
* Any of OPEN or /PVLD bits indicate a hardware mulfunction
* and the conversion result may be incorrect
*/
*val = tmp421->temp[channel] & 0x01;
*val = !!(tmp421->temp[channel] & 0x03);
return 0;
default:
return -EOPNOTSUPP;
Expand All @@ -177,9 +187,6 @@ static umode_t tmp421_is_visible(const void *data, enum hwmon_sensor_types type,
{
switch (attr) {
case hwmon_temp_fault:
if (channel == 0)
return 0;
return 0444;
case hwmon_temp_input:
return 0444;
default:
Expand Down
29 changes: 11 additions & 18 deletions drivers/hwmon/w83791d.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,6 @@ struct w83791d_data {
char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */

/* array of 2 pointers to subclients */
struct i2c_client *lm75[2];

/* volts */
u8 in[NUMBER_OF_VIN]; /* Register value */
u8 in_max[NUMBER_OF_VIN]; /* Register value */
Expand Down Expand Up @@ -1257,7 +1254,6 @@ static const struct attribute_group w83791d_group_fanpwm45 = {
static int w83791d_detect_subclients(struct i2c_client *client)
{
struct i2c_adapter *adapter = client->adapter;
struct w83791d_data *data = i2c_get_clientdata(client);
int address = client->addr;
int i, id;
u8 val;
Expand All @@ -1280,22 +1276,19 @@ static int w83791d_detect_subclients(struct i2c_client *client)
}

val = w83791d_read(client, W83791D_REG_I2C_SUBADDR);
if (!(val & 0x08))
data->lm75[0] = devm_i2c_new_dummy_device(&client->dev, adapter,
0x48 + (val & 0x7));
if (!(val & 0x80)) {
if (!IS_ERR(data->lm75[0]) &&
((val & 0x7) == ((val >> 4) & 0x7))) {
dev_err(&client->dev,
"duplicate addresses 0x%x, "
"use force_subclient\n",
data->lm75[0]->addr);
return -ENODEV;
}
data->lm75[1] = devm_i2c_new_dummy_device(&client->dev, adapter,
0x48 + ((val >> 4) & 0x7));

if (!(val & 0x88) && (val & 0x7) == ((val >> 4) & 0x7)) {
dev_err(&client->dev,
"duplicate addresses 0x%x, use force_subclient\n", 0x48 + (val & 0x7));
return -ENODEV;
}

if (!(val & 0x08))
devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + (val & 0x7));

if (!(val & 0x80))
devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + ((val >> 4) & 0x7));

return 0;
}

Expand Down
28 changes: 11 additions & 17 deletions drivers/hwmon/w83792d.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,6 @@ struct w83792d_data {
char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */

/* array of 2 pointers to subclients */
struct i2c_client *lm75[2];

u8 in[9]; /* Register value */
u8 in_max[9]; /* Register value */
u8 in_min[9]; /* Register value */
Expand Down Expand Up @@ -927,7 +924,6 @@ w83792d_detect_subclients(struct i2c_client *new_client)
int address = new_client->addr;
u8 val;
struct i2c_adapter *adapter = new_client->adapter;
struct w83792d_data *data = i2c_get_clientdata(new_client);

id = i2c_adapter_id(adapter);
if (force_subclients[0] == id && force_subclients[1] == address) {
Expand All @@ -946,21 +942,19 @@ w83792d_detect_subclients(struct i2c_client *new_client)
}

val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR);
if (!(val & 0x08))
data->lm75[0] = devm_i2c_new_dummy_device(&new_client->dev, adapter,
0x48 + (val & 0x7));
if (!(val & 0x80)) {
if (!IS_ERR(data->lm75[0]) &&
((val & 0x7) == ((val >> 4) & 0x7))) {
dev_err(&new_client->dev,
"duplicate addresses 0x%x, use force_subclient\n",
data->lm75[0]->addr);
return -ENODEV;
}
data->lm75[1] = devm_i2c_new_dummy_device(&new_client->dev, adapter,
0x48 + ((val >> 4) & 0x7));

if (!(val & 0x88) && (val & 0x7) == ((val >> 4) & 0x7)) {
dev_err(&new_client->dev,
"duplicate addresses 0x%x, use force_subclient\n", 0x48 + (val & 0x7));
return -ENODEV;
}

if (!(val & 0x08))
devm_i2c_new_dummy_device(&new_client->dev, adapter, 0x48 + (val & 0x7));

if (!(val & 0x80))
devm_i2c_new_dummy_device(&new_client->dev, adapter, 0x48 + ((val >> 4) & 0x7));

return 0;
}

Expand Down
Loading

0 comments on commit 7b66f43

Please sign in to comment.