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

+102 -126
-17
Documentation/hwmon/k10temp.rst
··· 132 132 Core Complex Die (CCD) temperatures. Up to 8 such temperatures are reported 133 133 as temp{3..10}_input, labeled Tccd{1..8}. Actual support depends on the CPU 134 134 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.
-6
drivers/hwmon/k10temp.c
··· 362 362 HWMON_T_INPUT | HWMON_T_LABEL, 363 363 HWMON_T_INPUT | HWMON_T_LABEL, 364 364 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), 371 365 NULL 372 366 }; 373 367
+6 -2
drivers/hwmon/ltc2947-core.c
··· 989 989 return ret; 990 990 991 991 /* 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) { 994 998 unsigned long rate_hz; 995 999 u8 pre = 0, div, tbctl; 996 1000 u64 aux;
+9 -3
drivers/hwmon/mlxreg-fan.c
··· 315 315 { 316 316 struct mlxreg_fan *fan = cdev->devdata; 317 317 unsigned long cur_state; 318 + int i, config = 0; 318 319 u32 regval; 319 - int i; 320 320 int err; 321 321 322 322 /* ··· 329 329 * overwritten. 330 330 */ 331 331 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; 332 338 state -= MLXREG_FAN_MAX_STATE; 333 339 for (i = 0; i < state; i++) 334 340 fan->cooling_levels[i] = state; ··· 349 343 350 344 cur_state = MLXREG_FAN_PWM_DUTY2STATE(regval); 351 345 if (state < cur_state) 352 - return 0; 346 + return config; 353 347 354 348 state = cur_state; 355 349 } ··· 365 359 dev_err(fan->dev, "Failed to write PWM duty\n"); 366 360 return err; 367 361 } 368 - return 0; 362 + return config; 369 363 } 370 364 371 365 static const struct thermal_cooling_device_ops mlxreg_fan_cooling_ops = {
+5 -12
drivers/hwmon/occ/common.c
··· 340 340 if (val == OCC_TEMP_SENSOR_FAULT) 341 341 return -EREMOTEIO; 342 342 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; 352 346 353 - val *= 1000; 354 - } 347 + val *= 1000; 355 348 break; 356 349 case 2: 357 350 val = temp->fru_type; ··· 879 886 0, i); 880 887 attr++; 881 888 882 - if (sensors->temp.version > 1 && 889 + if (sensors->temp.version == 2 && 883 890 temp->fru_type == OCC_FRU_TYPE_VRM) { 884 891 snprintf(attr->name, sizeof(attr->name), 885 892 "temp%d_alarm", s);
+8 -2
drivers/hwmon/pmbus/ibm-cffps.c
··· 171 171 cmd = CFFPS_SN_CMD; 172 172 break; 173 173 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 + 176 182 if (rc < 0) 177 183 return rc; 178 184
+1 -1
drivers/hwmon/pmbus/mp2975.c
··· 54 54 55 55 #define MP2975_RAIL2_FUNC (PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | \ 56 56 PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | \ 57 - PMBUS_PHASE_VIRTUAL) 57 + PMBUS_HAVE_POUT | PMBUS_PHASE_VIRTUAL) 58 58 59 59 struct mp2975_data { 60 60 struct pmbus_driver_info info;
+40 -33
drivers/hwmon/tmp421.c
··· 100 100 s16 temp[4]; 101 101 }; 102 102 103 - static int temp_from_s16(s16 reg) 103 + static int temp_from_raw(u16 reg, bool extended) 104 104 { 105 105 /* Mask out status bits */ 106 106 int temp = reg & ~0xf; 107 107 108 - return (temp * 1000 + 128) / 256; 108 + if (extended) 109 + temp = temp - 64 * 256; 110 + else 111 + temp = (s16)temp; 112 + 113 + return DIV_ROUND_CLOSEST(temp * 1000, 256); 109 114 } 110 115 111 - static int temp_from_u16(u16 reg) 116 + static int tmp421_update_device(struct tmp421_data *data) 112 117 { 113 - /* Mask out status bits */ 114 - int temp = reg & ~0xf; 115 - 116 - /* Add offset for extended temperature range. */ 117 - temp -= 64 * 256; 118 - 119 - return (temp * 1000 + 128) / 256; 120 - } 121 - 122 - static struct tmp421_data *tmp421_update_device(struct device *dev) 123 - { 124 - struct tmp421_data *data = dev_get_drvdata(dev); 125 118 struct i2c_client *client = data->client; 119 + int ret = 0; 126 120 int i; 127 121 128 122 mutex_lock(&data->update_lock); 129 123 130 124 if (time_after(jiffies, data->last_updated + (HZ / 2)) || 131 125 !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; 134 130 135 131 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; 140 141 } 141 142 data->last_updated = jiffies; 142 143 data->valid = 1; 143 144 } 144 145 146 + exit: 145 147 mutex_unlock(&data->update_lock); 146 148 147 - return data; 149 + if (ret < 0) { 150 + data->valid = 0; 151 + return ret; 152 + } 153 + 154 + return 0; 148 155 } 149 156 150 157 static int tmp421_read(struct device *dev, enum hwmon_sensor_types type, 151 158 u32 attr, int channel, long *val) 152 159 { 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; 154 166 155 167 switch (attr) { 156 168 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); 161 171 return 0; 162 172 case hwmon_temp_fault: 163 173 /* 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 166 176 */ 167 - *val = tmp421->temp[channel] & 0x01; 177 + *val = !!(tmp421->temp[channel] & 0x03); 168 178 return 0; 169 179 default: 170 180 return -EOPNOTSUPP; ··· 187 177 { 188 178 switch (attr) { 189 179 case hwmon_temp_fault: 190 - if (channel == 0) 191 - return 0; 192 - return 0444; 193 180 case hwmon_temp_input: 194 181 return 0444; 195 182 default:
+11 -18
drivers/hwmon/w83791d.c
··· 273 273 char valid; /* !=0 if following fields are valid */ 274 274 unsigned long last_updated; /* In jiffies */ 275 275 276 - /* array of 2 pointers to subclients */ 277 - struct i2c_client *lm75[2]; 278 - 279 276 /* volts */ 280 277 u8 in[NUMBER_OF_VIN]; /* Register value */ 281 278 u8 in_max[NUMBER_OF_VIN]; /* Register value */ ··· 1254 1257 static int w83791d_detect_subclients(struct i2c_client *client) 1255 1258 { 1256 1259 struct i2c_adapter *adapter = client->adapter; 1257 - struct w83791d_data *data = i2c_get_clientdata(client); 1258 1260 int address = client->addr; 1259 1261 int i, id; 1260 1262 u8 val; ··· 1276 1280 } 1277 1281 1278 1282 val = w83791d_read(client, W83791D_REG_I2C_SUBADDR); 1279 - if (!(val & 0x08)) 1280 - data->lm75[0] = devm_i2c_new_dummy_device(&client->dev, adapter, 1281 - 0x48 + (val & 0x7)); 1282 - if (!(val & 0x80)) { 1283 - if (!IS_ERR(data->lm75[0]) && 1284 - ((val & 0x7) == ((val >> 4) & 0x7))) { 1285 - dev_err(&client->dev, 1286 - "duplicate addresses 0x%x, " 1287 - "use force_subclient\n", 1288 - data->lm75[0]->addr); 1289 - return -ENODEV; 1290 - } 1291 - data->lm75[1] = devm_i2c_new_dummy_device(&client->dev, adapter, 1292 - 0x48 + ((val >> 4) & 0x7)); 1283 + 1284 + if (!(val & 0x88) && (val & 0x7) == ((val >> 4) & 0x7)) { 1285 + dev_err(&client->dev, 1286 + "duplicate addresses 0x%x, use force_subclient\n", 0x48 + (val & 0x7)); 1287 + return -ENODEV; 1293 1288 } 1289 + 1290 + if (!(val & 0x08)) 1291 + devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + (val & 0x7)); 1292 + 1293 + if (!(val & 0x80)) 1294 + devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + ((val >> 4) & 0x7)); 1294 1295 1295 1296 return 0; 1296 1297 }
+11 -17
drivers/hwmon/w83792d.c
··· 264 264 char valid; /* !=0 if following fields are valid */ 265 265 unsigned long last_updated; /* In jiffies */ 266 266 267 - /* array of 2 pointers to subclients */ 268 - struct i2c_client *lm75[2]; 269 - 270 267 u8 in[9]; /* Register value */ 271 268 u8 in_max[9]; /* Register value */ 272 269 u8 in_min[9]; /* Register value */ ··· 924 927 int address = new_client->addr; 925 928 u8 val; 926 929 struct i2c_adapter *adapter = new_client->adapter; 927 - struct w83792d_data *data = i2c_get_clientdata(new_client); 928 930 929 931 id = i2c_adapter_id(adapter); 930 932 if (force_subclients[0] == id && force_subclients[1] == address) { ··· 942 946 } 943 947 944 948 val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR); 945 - if (!(val & 0x08)) 946 - data->lm75[0] = devm_i2c_new_dummy_device(&new_client->dev, adapter, 947 - 0x48 + (val & 0x7)); 948 - if (!(val & 0x80)) { 949 - if (!IS_ERR(data->lm75[0]) && 950 - ((val & 0x7) == ((val >> 4) & 0x7))) { 951 - dev_err(&new_client->dev, 952 - "duplicate addresses 0x%x, use force_subclient\n", 953 - data->lm75[0]->addr); 954 - return -ENODEV; 955 - } 956 - data->lm75[1] = devm_i2c_new_dummy_device(&new_client->dev, adapter, 957 - 0x48 + ((val >> 4) & 0x7)); 949 + 950 + if (!(val & 0x88) && (val & 0x7) == ((val >> 4) & 0x7)) { 951 + dev_err(&new_client->dev, 952 + "duplicate addresses 0x%x, use force_subclient\n", 0x48 + (val & 0x7)); 953 + return -ENODEV; 958 954 } 955 + 956 + if (!(val & 0x08)) 957 + devm_i2c_new_dummy_device(&new_client->dev, adapter, 0x48 + (val & 0x7)); 958 + 959 + if (!(val & 0x80)) 960 + devm_i2c_new_dummy_device(&new_client->dev, adapter, 0x48 + ((val >> 4) & 0x7)); 959 961 960 962 return 0; 961 963 }
+11 -15
drivers/hwmon/w83793.c
··· 202 202 } 203 203 204 204 struct w83793_data { 205 - struct i2c_client *lm75[2]; 206 205 struct device *hwmon_dev; 207 206 struct mutex update_lock; 208 207 char valid; /* !=0 if following fields are valid */ ··· 1565 1566 int address = client->addr; 1566 1567 u8 tmp; 1567 1568 struct i2c_adapter *adapter = client->adapter; 1568 - struct w83793_data *data = i2c_get_clientdata(client); 1569 1569 1570 1570 id = i2c_adapter_id(adapter); 1571 1571 if (force_subclients[0] == id && force_subclients[1] == address) { ··· 1584 1586 } 1585 1587 1586 1588 tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR); 1587 - if (!(tmp & 0x08)) 1588 - data->lm75[0] = devm_i2c_new_dummy_device(&client->dev, adapter, 1589 - 0x48 + (tmp & 0x7)); 1590 - if (!(tmp & 0x80)) { 1591 - if (!IS_ERR(data->lm75[0]) 1592 - && ((tmp & 0x7) == ((tmp >> 4) & 0x7))) { 1593 - dev_err(&client->dev, 1594 - "duplicate addresses 0x%x, " 1595 - "use force_subclients\n", data->lm75[0]->addr); 1596 - return -ENODEV; 1597 - } 1598 - data->lm75[1] = devm_i2c_new_dummy_device(&client->dev, adapter, 1599 - 0x48 + ((tmp >> 4) & 0x7)); 1589 + 1590 + if (!(tmp & 0x88) && (tmp & 0x7) == ((tmp >> 4) & 0x7)) { 1591 + dev_err(&client->dev, 1592 + "duplicate addresses 0x%x, use force_subclient\n", 0x48 + (tmp & 0x7)); 1593 + return -ENODEV; 1600 1594 } 1595 + 1596 + if (!(tmp & 0x08)) 1597 + devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + (tmp & 0x7)); 1598 + 1599 + if (!(tmp & 0x80)) 1600 + devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + ((tmp >> 4) & 0x7)); 1601 1601 1602 1602 return 0; 1603 1603 }