Skip to content

Commit 2be86a8

Browse files
committed
Merge tag 'hwmon-for-v7.1-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon fixes from Guenter Roeck: - adm1266: Various fixes from Abdurrahman Hussain The fixed issues were reported by Sashiko as part of a code review of a functional change in the driver. - lenovo-ec-sensors: Convert to devm_request_region() to fix release_region cleanup, and fix EC "MCHP" signature validation logic, from Kean Ren * tag 'hwmon-for-v7.1-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: hwmon: (pmbus/adm1266) serialize sequencer_state debugfs read with pmbus_lock hwmon: (pmbus/adm1266) serialize NVMEM blackbox read with pmbus_lock hwmon: (pmbus/adm1266) serialize GPIO PMBus accesses with pmbus_lock hwmon: (pmbus/adm1266) register the nvmem device after pmbus_do_probe() hwmon: (pmbus/adm1266) register the gpio_chip after pmbus_do_probe() hwmon: (pmbus/adm1266) reject short block-read responses in the GPIO accessors hwmon: (pmbus/adm1266) don't clobber GPIO bits before PDIO read in get_multiple hwmon: (pmbus/adm1266) cap PDIO scan in get_multiple at ADM1266_PDIO_NR hwmon: (pmbus/adm1266) bounce blackbox records through a protocol-sized buffer hwmon: (pmbus/adm1266) include adapter number in GPIO line label hwmon: (pmbus/adm1266) include PEC byte in pmbus_block_xfer read buffer hwmon: (pmbus/adm1266) reject implausible blackbox record_count hwmon: (pmbus/adm1266) widen blackbox-info buffer to I2C_SMBUS_BLOCK_MAX hwmon: (pmbus/adm1266) seed timestamp from the real-time clock hwmon: (lenovo-ec-sensors): Fix EC "MCHP" signature validation logic hwmon: (lenovo-ec-sensors): Convert to devm_request_region()
2 parents 53676e4 + 4e4af55 commit 2be86a8

2 files changed

Lines changed: 40 additions & 26 deletions

File tree

drivers/hwmon/lenovo-ec-sensors.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,8 @@ static int lenovo_ec_probe(struct platform_device *pdev)
519519
if (!ec_data)
520520
return -ENOMEM;
521521

522-
if (!request_region(IO_REGION_START, IO_REGION_LENGTH, "LNV-WKS")) {
523-
pr_err(":request fail\n");
522+
if (!devm_request_region(dev, IO_REGION_START, IO_REGION_LENGTH, "LNV-WKS")) {
523+
dev_err(dev, "Failed to request I/O region\n");
524524
return -EIO;
525525
}
526526

@@ -537,13 +537,11 @@ static int lenovo_ec_probe(struct platform_device *pdev)
537537
outw_p(MCHP_SING_IDX, MCHP_EMI0_EC_ADDRESS);
538538
mutex_unlock(&ec_data->mec_mutex);
539539

540-
if ((inb_p(MCHP_EMI0_EC_DATA_BYTE0) != 'M') &&
541-
(inb_p(MCHP_EMI0_EC_DATA_BYTE1) != 'C') &&
542-
(inb_p(MCHP_EMI0_EC_DATA_BYTE2) != 'H') &&
543-
(inb_p(MCHP_EMI0_EC_DATA_BYTE3) != 'P')) {
544-
release_region(IO_REGION_START, IO_REGION_LENGTH);
540+
if ((inb_p(MCHP_EMI0_EC_DATA_BYTE0) != 'M') ||
541+
(inb_p(MCHP_EMI0_EC_DATA_BYTE1) != 'C') ||
542+
(inb_p(MCHP_EMI0_EC_DATA_BYTE2) != 'H') ||
543+
(inb_p(MCHP_EMI0_EC_DATA_BYTE3) != 'P'))
545544
return -ENODEV;
546-
}
547545

548546
dmi_id = dmi_first_match(thinkstation_dmi_table);
549547

@@ -577,7 +575,6 @@ static int lenovo_ec_probe(struct platform_device *pdev)
577575
lenovo_ec_chip_info.info = lenovo_ec_hwmon_info_p8;
578576
break;
579577
default:
580-
release_region(IO_REGION_START, IO_REGION_LENGTH);
581578
return -ENODEV;
582579
}
583580

@@ -606,18 +603,15 @@ static int __init lenovo_ec_init(void)
606603
platform_create_bundle(&lenovo_ec_sensors_platform_driver,
607604
lenovo_ec_probe, NULL, 0, NULL, 0);
608605

609-
if (IS_ERR(lenovo_ec_sensors_platform_device)) {
610-
release_region(IO_REGION_START, IO_REGION_LENGTH);
606+
if (IS_ERR(lenovo_ec_sensors_platform_device))
611607
return PTR_ERR(lenovo_ec_sensors_platform_device);
612-
}
613608

614609
return 0;
615610
}
616611
module_init(lenovo_ec_init);
617612

618613
static void __exit lenovo_ec_exit(void)
619614
{
620-
release_region(IO_REGION_START, IO_REGION_LENGTH);
621615
platform_device_unregister(lenovo_ec_sensors_platform_device);
622616
platform_driver_unregister(&lenovo_ec_sensors_platform_driver);
623617
}

drivers/hwmon/pmbus/adm1266.c

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
#define ADM1266_BLACKBOX_OFFSET 0
4848
#define ADM1266_BLACKBOX_SIZE 64
49+
#define ADM1266_BLACKBOX_MAX_RECORDS 32
4950

5051
#define ADM1266_PMBUS_BLOCK_MAX 255
5152

@@ -60,7 +61,7 @@ struct adm1266_data {
6061
u8 *dev_mem;
6162
struct mutex buf_mutex;
6263
u8 write_buf[ADM1266_PMBUS_BLOCK_MAX + 1] ____cacheline_aligned;
63-
u8 read_buf[ADM1266_PMBUS_BLOCK_MAX + 1] ____cacheline_aligned;
64+
u8 read_buf[ADM1266_PMBUS_BLOCK_MAX + 2] ____cacheline_aligned;
6465
};
6566

6667
static const struct nvmem_cell_info adm1266_nvmem_cells[] = {
@@ -172,9 +173,13 @@ static int adm1266_gpio_get(struct gpio_chip *chip, unsigned int offset)
172173
else
173174
pmbus_cmd = ADM1266_PDIO_STATUS;
174175

176+
guard(pmbus_lock)(data->client);
177+
175178
ret = i2c_smbus_read_block_data(data->client, pmbus_cmd, read_buf);
176179
if (ret < 0)
177180
return ret;
181+
if (ret < 2)
182+
return -EIO;
178183

179184
pins_status = read_buf[0] + (read_buf[1] << 8);
180185
if (offset < ADM1266_GPIO_NR)
@@ -192,9 +197,13 @@ static int adm1266_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask
192197
unsigned int gpio_nr;
193198
int ret;
194199

200+
guard(pmbus_lock)(data->client);
201+
195202
ret = i2c_smbus_read_block_data(data->client, ADM1266_GPIO_STATUS, read_buf);
196203
if (ret < 0)
197204
return ret;
205+
if (ret < 2)
206+
return -EIO;
198207

199208
status = read_buf[0] + (read_buf[1] << 8);
200209

@@ -207,11 +216,12 @@ static int adm1266_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask
207216
ret = i2c_smbus_read_block_data(data->client, ADM1266_PDIO_STATUS, read_buf);
208217
if (ret < 0)
209218
return ret;
219+
if (ret < 2)
220+
return -EIO;
210221

211222
status = read_buf[0] + (read_buf[1] << 8);
212223

213-
*bits = 0;
214-
for_each_set_bit_from(gpio_nr, mask, ADM1266_GPIO_NR + ADM1266_PDIO_STATUS) {
224+
for_each_set_bit_from(gpio_nr, mask, ADM1266_GPIO_NR + ADM1266_PDIO_NR) {
215225
if (test_bit(gpio_nr - ADM1266_GPIO_NR, &status))
216226
set_bit(gpio_nr, bits);
217227
}
@@ -230,6 +240,8 @@ static void adm1266_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
230240
int ret;
231241
int i;
232242

243+
guard(pmbus_lock)(data->client);
244+
233245
for (i = 0; i < ADM1266_GPIO_NR; i++) {
234246
write_cmd = adm1266_gpio_mapping[i][1];
235247
ret = adm1266_pmbus_block_xfer(data, ADM1266_GPIO_CONFIG, 1, &write_cmd, read_buf);
@@ -290,8 +302,9 @@ static int adm1266_config_gpio(struct adm1266_data *data)
290302
int i;
291303

292304
for (i = 0; i < ARRAY_SIZE(data->gpio_names); i++) {
293-
gpio_name = devm_kasprintf(&data->client->dev, GFP_KERNEL, "adm1266-%x-%s",
294-
data->client->addr, adm1266_names[i]);
305+
gpio_name = devm_kasprintf(&data->client->dev, GFP_KERNEL, "adm1266-%d-%x-%s",
306+
data->client->adapter->nr, data->client->addr,
307+
adm1266_names[i]);
295308
if (!gpio_name)
296309
return -ENOMEM;
297310

@@ -322,6 +335,7 @@ static int adm1266_state_read(struct seq_file *s, void *pdata)
322335
struct i2c_client *client = to_i2c_client(dev);
323336
int ret;
324337

338+
guard(pmbus_lock)(client);
325339
ret = i2c_smbus_read_word_data(client, ADM1266_READ_STATE);
326340
if (ret < 0)
327341
return ret;
@@ -347,9 +361,10 @@ static void adm1266_init_debugfs(struct adm1266_data *data)
347361

348362
static int adm1266_nvmem_read_blackbox(struct adm1266_data *data, u8 *read_buff)
349363
{
364+
u8 record[ADM1266_PMBUS_BLOCK_MAX];
350365
int record_count;
351366
char index;
352-
u8 buf[5];
367+
u8 buf[I2C_SMBUS_BLOCK_MAX];
353368
int ret;
354369

355370
ret = i2c_smbus_read_block_data(data->client, ADM1266_BLACKBOX_INFO, buf);
@@ -360,15 +375,18 @@ static int adm1266_nvmem_read_blackbox(struct adm1266_data *data, u8 *read_buff)
360375
return -EIO;
361376

362377
record_count = buf[3];
378+
if (record_count > ADM1266_BLACKBOX_MAX_RECORDS)
379+
return -EIO;
363380

364381
for (index = 0; index < record_count; index++) {
365-
ret = adm1266_pmbus_block_xfer(data, ADM1266_READ_BLACKBOX, 1, &index, read_buff);
382+
ret = adm1266_pmbus_block_xfer(data, ADM1266_READ_BLACKBOX, 1, &index, record);
366383
if (ret < 0)
367384
return ret;
368385

369386
if (ret != ADM1266_BLACKBOX_SIZE)
370387
return -EIO;
371388

389+
memcpy(read_buff, record, ADM1266_BLACKBOX_SIZE);
372390
read_buff += ADM1266_BLACKBOX_SIZE;
373391
}
374392

@@ -383,6 +401,8 @@ static int adm1266_nvmem_read(void *priv, unsigned int offset, void *val, size_t
383401
if (offset + bytes > data->nvmem_config.size)
384402
return -EINVAL;
385403

404+
guard(pmbus_lock)(data->client);
405+
386406
if (offset == 0) {
387407
memset(data->dev_mem, 0, data->nvmem_config.size);
388408

@@ -432,7 +452,7 @@ static int adm1266_set_rtc(struct adm1266_data *data)
432452
char write_buf[6];
433453
int i;
434454

435-
kt = ktime_get_seconds();
455+
kt = ktime_get_real_seconds();
436456

437457
memset(write_buf, 0, sizeof(write_buf));
438458

@@ -462,20 +482,20 @@ static int adm1266_probe(struct i2c_client *client)
462482
crc8_populate_msb(pmbus_crc_table, 0x7);
463483
mutex_init(&data->buf_mutex);
464484

465-
ret = adm1266_config_gpio(data);
485+
ret = adm1266_set_rtc(data);
466486
if (ret < 0)
467487
return ret;
468488

469-
ret = adm1266_set_rtc(data);
470-
if (ret < 0)
489+
ret = pmbus_do_probe(client, &data->info);
490+
if (ret)
471491
return ret;
472492

473493
ret = adm1266_config_nvmem(data);
474494
if (ret < 0)
475495
return ret;
476496

477-
ret = pmbus_do_probe(client, &data->info);
478-
if (ret)
497+
ret = adm1266_config_gpio(data);
498+
if (ret < 0)
479499
return ret;
480500

481501
adm1266_init_debugfs(data);

0 commit comments

Comments
 (0)