Skip to content

Commit 7b66f43

Browse files
committed
Merge tag 'hwmon-for-v5.15-rc4' of git://git.kernel.org/pub/scm/linux/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
2 parents e25ca04 + dd4d747 commit 7b66f43

File tree

11 files changed

+101
-125
lines changed

11 files changed

+101
-125
lines changed

Documentation/hwmon/k10temp.rst

-17
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,3 @@ On Family 17h and Family 18h CPUs, additional temperature sensors may report
132132
Core Complex Die (CCD) temperatures. Up to 8 such temperatures are reported
133133
as temp{3..10}_input, labeled Tccd{1..8}. Actual support depends on the CPU
134134
variant.
135-
136-
Various Family 17h and 18h CPUs report voltage and current telemetry
137-
information. The following attributes may be reported.
138-
139-
Attribute Label Description
140-
=============== ======= ================
141-
in0_input Vcore Core voltage
142-
in1_input Vsoc SoC voltage
143-
curr1_input Icore Core current
144-
curr2_input Isoc SoC current
145-
=============== ======= ================
146-
147-
Current values are raw (unscaled) as reported by the CPU. Core current is
148-
reported as multiples of 1A / LSB. SoC is reported as multiples of 0.25A
149-
/ LSB. The real current is board specific. Reported currents should be seen
150-
as rough guidance, and should be scaled using sensors3.conf as appropriate
151-
for a given board.

drivers/hwmon/k10temp.c

-6
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,6 @@ static const struct hwmon_channel_info *k10temp_info[] = {
362362
HWMON_T_INPUT | HWMON_T_LABEL,
363363
HWMON_T_INPUT | HWMON_T_LABEL,
364364
HWMON_T_INPUT | HWMON_T_LABEL),
365-
HWMON_CHANNEL_INFO(in,
366-
HWMON_I_INPUT | HWMON_I_LABEL,
367-
HWMON_I_INPUT | HWMON_I_LABEL),
368-
HWMON_CHANNEL_INFO(curr,
369-
HWMON_C_INPUT | HWMON_C_LABEL,
370-
HWMON_C_INPUT | HWMON_C_LABEL),
371365
NULL
372366
};
373367

drivers/hwmon/ltc2947-core.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,12 @@ static int ltc2947_setup(struct ltc2947_data *st)
989989
return ret;
990990

991991
/* check external clock presence */
992-
extclk = devm_clk_get(st->dev, NULL);
993-
if (!IS_ERR(extclk)) {
992+
extclk = devm_clk_get_optional(st->dev, NULL);
993+
if (IS_ERR(extclk))
994+
return dev_err_probe(st->dev, PTR_ERR(extclk),
995+
"Failed to get external clock\n");
996+
997+
if (extclk) {
994998
unsigned long rate_hz;
995999
u8 pre = 0, div, tbctl;
9961000
u64 aux;

drivers/hwmon/mlxreg-fan.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev,
315315
{
316316
struct mlxreg_fan *fan = cdev->devdata;
317317
unsigned long cur_state;
318+
int i, config = 0;
318319
u32 regval;
319-
int i;
320320
int err;
321321

322322
/*
@@ -329,6 +329,12 @@ static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev,
329329
* overwritten.
330330
*/
331331
if (state >= MLXREG_FAN_SPEED_MIN && state <= MLXREG_FAN_SPEED_MAX) {
332+
/*
333+
* This is configuration change, which is only supported through sysfs.
334+
* For configuration non-zero value is to be returned to avoid thermal
335+
* statistics update.
336+
*/
337+
config = 1;
332338
state -= MLXREG_FAN_MAX_STATE;
333339
for (i = 0; i < state; i++)
334340
fan->cooling_levels[i] = state;
@@ -343,7 +349,7 @@ static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev,
343349

344350
cur_state = MLXREG_FAN_PWM_DUTY2STATE(regval);
345351
if (state < cur_state)
346-
return 0;
352+
return config;
347353

348354
state = cur_state;
349355
}
@@ -359,7 +365,7 @@ static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev,
359365
dev_err(fan->dev, "Failed to write PWM duty\n");
360366
return err;
361367
}
362-
return 0;
368+
return config;
363369
}
364370

365371
static const struct thermal_cooling_device_ops mlxreg_fan_cooling_ops = {

drivers/hwmon/occ/common.c

+5-12
Original file line numberDiff line numberDiff line change
@@ -340,18 +340,11 @@ static ssize_t occ_show_temp_10(struct device *dev,
340340
if (val == OCC_TEMP_SENSOR_FAULT)
341341
return -EREMOTEIO;
342342

343-
/*
344-
* VRM doesn't return temperature, only alarm bit. This
345-
* attribute maps to tempX_alarm instead of tempX_input for
346-
* VRM
347-
*/
348-
if (temp->fru_type != OCC_FRU_TYPE_VRM) {
349-
/* sensor not ready */
350-
if (val == 0)
351-
return -EAGAIN;
343+
/* sensor not ready */
344+
if (val == 0)
345+
return -EAGAIN;
352346

353-
val *= 1000;
354-
}
347+
val *= 1000;
355348
break;
356349
case 2:
357350
val = temp->fru_type;
@@ -886,7 +879,7 @@ static int occ_setup_sensor_attrs(struct occ *occ)
886879
0, i);
887880
attr++;
888881

889-
if (sensors->temp.version > 1 &&
882+
if (sensors->temp.version == 2 &&
890883
temp->fru_type == OCC_FRU_TYPE_VRM) {
891884
snprintf(attr->name, sizeof(attr->name),
892885
"temp%d_alarm", s);

drivers/hwmon/pmbus/ibm-cffps.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,14 @@ static ssize_t ibm_cffps_debugfs_read(struct file *file, char __user *buf,
171171
cmd = CFFPS_SN_CMD;
172172
break;
173173
case CFFPS_DEBUGFS_MAX_POWER_OUT:
174-
rc = i2c_smbus_read_word_swapped(psu->client,
175-
CFFPS_MAX_POWER_OUT_CMD);
174+
if (psu->version == cffps1) {
175+
rc = i2c_smbus_read_word_swapped(psu->client,
176+
CFFPS_MAX_POWER_OUT_CMD);
177+
} else {
178+
rc = i2c_smbus_read_word_data(psu->client,
179+
CFFPS_MAX_POWER_OUT_CMD);
180+
}
181+
176182
if (rc < 0)
177183
return rc;
178184

drivers/hwmon/pmbus/mp2975.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
#define MP2975_RAIL2_FUNC (PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | \
5656
PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | \
57-
PMBUS_PHASE_VIRTUAL)
57+
PMBUS_HAVE_POUT | PMBUS_PHASE_VIRTUAL)
5858

5959
struct mp2975_data {
6060
struct pmbus_driver_info info;

drivers/hwmon/tmp421.c

+39-32
Original file line numberDiff line numberDiff line change
@@ -100,71 +100,81 @@ struct tmp421_data {
100100
s16 temp[4];
101101
};
102102

103-
static int temp_from_s16(s16 reg)
103+
static int temp_from_raw(u16 reg, bool extended)
104104
{
105105
/* Mask out status bits */
106106
int temp = reg & ~0xf;
107107

108-
return (temp * 1000 + 128) / 256;
109-
}
110-
111-
static int temp_from_u16(u16 reg)
112-
{
113-
/* Mask out status bits */
114-
int temp = reg & ~0xf;
115-
116-
/* Add offset for extended temperature range. */
117-
temp -= 64 * 256;
108+
if (extended)
109+
temp = temp - 64 * 256;
110+
else
111+
temp = (s16)temp;
118112

119-
return (temp * 1000 + 128) / 256;
113+
return DIV_ROUND_CLOSEST(temp * 1000, 256);
120114
}
121115

122-
static struct tmp421_data *tmp421_update_device(struct device *dev)
116+
static int tmp421_update_device(struct tmp421_data *data)
123117
{
124-
struct tmp421_data *data = dev_get_drvdata(dev);
125118
struct i2c_client *client = data->client;
119+
int ret = 0;
126120
int i;
127121

128122
mutex_lock(&data->update_lock);
129123

130124
if (time_after(jiffies, data->last_updated + (HZ / 2)) ||
131125
!data->valid) {
132-
data->config = i2c_smbus_read_byte_data(client,
133-
TMP421_CONFIG_REG_1);
126+
ret = i2c_smbus_read_byte_data(client, TMP421_CONFIG_REG_1);
127+
if (ret < 0)
128+
goto exit;
129+
data->config = ret;
134130

135131
for (i = 0; i < data->channels; i++) {
136-
data->temp[i] = i2c_smbus_read_byte_data(client,
137-
TMP421_TEMP_MSB[i]) << 8;
138-
data->temp[i] |= i2c_smbus_read_byte_data(client,
139-
TMP421_TEMP_LSB[i]);
132+
ret = i2c_smbus_read_byte_data(client, TMP421_TEMP_MSB[i]);
133+
if (ret < 0)
134+
goto exit;
135+
data->temp[i] = ret << 8;
136+
137+
ret = i2c_smbus_read_byte_data(client, TMP421_TEMP_LSB[i]);
138+
if (ret < 0)
139+
goto exit;
140+
data->temp[i] |= ret;
140141
}
141142
data->last_updated = jiffies;
142143
data->valid = 1;
143144
}
144145

146+
exit:
145147
mutex_unlock(&data->update_lock);
146148

147-
return data;
149+
if (ret < 0) {
150+
data->valid = 0;
151+
return ret;
152+
}
153+
154+
return 0;
148155
}
149156

150157
static int tmp421_read(struct device *dev, enum hwmon_sensor_types type,
151158
u32 attr, int channel, long *val)
152159
{
153-
struct tmp421_data *tmp421 = tmp421_update_device(dev);
160+
struct tmp421_data *tmp421 = dev_get_drvdata(dev);
161+
int ret = 0;
162+
163+
ret = tmp421_update_device(tmp421);
164+
if (ret)
165+
return ret;
154166

155167
switch (attr) {
156168
case hwmon_temp_input:
157-
if (tmp421->config & TMP421_CONFIG_RANGE)
158-
*val = temp_from_u16(tmp421->temp[channel]);
159-
else
160-
*val = temp_from_s16(tmp421->temp[channel]);
169+
*val = temp_from_raw(tmp421->temp[channel],
170+
tmp421->config & TMP421_CONFIG_RANGE);
161171
return 0;
162172
case hwmon_temp_fault:
163173
/*
164-
* The OPEN bit signals a fault. This is bit 0 of the temperature
165-
* register (low byte).
174+
* Any of OPEN or /PVLD bits indicate a hardware mulfunction
175+
* and the conversion result may be incorrect
166176
*/
167-
*val = tmp421->temp[channel] & 0x01;
177+
*val = !!(tmp421->temp[channel] & 0x03);
168178
return 0;
169179
default:
170180
return -EOPNOTSUPP;
@@ -177,9 +187,6 @@ static umode_t tmp421_is_visible(const void *data, enum hwmon_sensor_types type,
177187
{
178188
switch (attr) {
179189
case hwmon_temp_fault:
180-
if (channel == 0)
181-
return 0;
182-
return 0444;
183190
case hwmon_temp_input:
184191
return 0444;
185192
default:

drivers/hwmon/w83791d.c

+11-18
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,6 @@ struct w83791d_data {
273273
char valid; /* !=0 if following fields are valid */
274274
unsigned long last_updated; /* In jiffies */
275275

276-
/* array of 2 pointers to subclients */
277-
struct i2c_client *lm75[2];
278-
279276
/* volts */
280277
u8 in[NUMBER_OF_VIN]; /* Register value */
281278
u8 in_max[NUMBER_OF_VIN]; /* Register value */
@@ -1257,7 +1254,6 @@ static const struct attribute_group w83791d_group_fanpwm45 = {
12571254
static int w83791d_detect_subclients(struct i2c_client *client)
12581255
{
12591256
struct i2c_adapter *adapter = client->adapter;
1260-
struct w83791d_data *data = i2c_get_clientdata(client);
12611257
int address = client->addr;
12621258
int i, id;
12631259
u8 val;
@@ -1280,22 +1276,19 @@ static int w83791d_detect_subclients(struct i2c_client *client)
12801276
}
12811277

12821278
val = w83791d_read(client, W83791D_REG_I2C_SUBADDR);
1283-
if (!(val & 0x08))
1284-
data->lm75[0] = devm_i2c_new_dummy_device(&client->dev, adapter,
1285-
0x48 + (val & 0x7));
1286-
if (!(val & 0x80)) {
1287-
if (!IS_ERR(data->lm75[0]) &&
1288-
((val & 0x7) == ((val >> 4) & 0x7))) {
1289-
dev_err(&client->dev,
1290-
"duplicate addresses 0x%x, "
1291-
"use force_subclient\n",
1292-
data->lm75[0]->addr);
1293-
return -ENODEV;
1294-
}
1295-
data->lm75[1] = devm_i2c_new_dummy_device(&client->dev, adapter,
1296-
0x48 + ((val >> 4) & 0x7));
1279+
1280+
if (!(val & 0x88) && (val & 0x7) == ((val >> 4) & 0x7)) {
1281+
dev_err(&client->dev,
1282+
"duplicate addresses 0x%x, use force_subclient\n", 0x48 + (val & 0x7));
1283+
return -ENODEV;
12971284
}
12981285

1286+
if (!(val & 0x08))
1287+
devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + (val & 0x7));
1288+
1289+
if (!(val & 0x80))
1290+
devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + ((val >> 4) & 0x7));
1291+
12991292
return 0;
13001293
}
13011294

drivers/hwmon/w83792d.c

+11-17
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,6 @@ struct w83792d_data {
264264
char valid; /* !=0 if following fields are valid */
265265
unsigned long last_updated; /* In jiffies */
266266

267-
/* array of 2 pointers to subclients */
268-
struct i2c_client *lm75[2];
269-
270267
u8 in[9]; /* Register value */
271268
u8 in_max[9]; /* Register value */
272269
u8 in_min[9]; /* Register value */
@@ -927,7 +924,6 @@ w83792d_detect_subclients(struct i2c_client *new_client)
927924
int address = new_client->addr;
928925
u8 val;
929926
struct i2c_adapter *adapter = new_client->adapter;
930-
struct w83792d_data *data = i2c_get_clientdata(new_client);
931927

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

948944
val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR);
949-
if (!(val & 0x08))
950-
data->lm75[0] = devm_i2c_new_dummy_device(&new_client->dev, adapter,
951-
0x48 + (val & 0x7));
952-
if (!(val & 0x80)) {
953-
if (!IS_ERR(data->lm75[0]) &&
954-
((val & 0x7) == ((val >> 4) & 0x7))) {
955-
dev_err(&new_client->dev,
956-
"duplicate addresses 0x%x, use force_subclient\n",
957-
data->lm75[0]->addr);
958-
return -ENODEV;
959-
}
960-
data->lm75[1] = devm_i2c_new_dummy_device(&new_client->dev, adapter,
961-
0x48 + ((val >> 4) & 0x7));
945+
946+
if (!(val & 0x88) && (val & 0x7) == ((val >> 4) & 0x7)) {
947+
dev_err(&new_client->dev,
948+
"duplicate addresses 0x%x, use force_subclient\n", 0x48 + (val & 0x7));
949+
return -ENODEV;
962950
}
963951

952+
if (!(val & 0x08))
953+
devm_i2c_new_dummy_device(&new_client->dev, adapter, 0x48 + (val & 0x7));
954+
955+
if (!(val & 0x80))
956+
devm_i2c_new_dummy_device(&new_client->dev, adapter, 0x48 + ((val >> 4) & 0x7));
957+
964958
return 0;
965959
}
966960

0 commit comments

Comments
 (0)