Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (ntc_thermistor) Use devm_hwmon_device_register_with_groups

Simplify code, reduce code size, and drop remove function as no longer
needed.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>

+9 -48
+9 -48
drivers/hwmon/ntc_thermistor.c
··· 253 253 }; 254 254 255 255 struct ntc_data { 256 - struct device *hwmon_dev; 257 256 struct ntc_thermistor_platform_data *pdata; 258 257 const struct ntc_compensation *comp; 259 258 int n_comp; 260 - char name[PLATFORM_NAME_SIZE]; 261 259 }; 262 260 263 261 #if defined(CONFIG_OF) && IS_ENABLED(CONFIG_IIO) ··· 506 508 return -EINVAL; 507 509 } 508 510 509 - static int ntc_read_temp(void *dev, int *temp) 511 + static int ntc_read_temp(void *data, int *temp) 510 512 { 511 - struct ntc_data *data = dev_get_drvdata(dev); 512 513 int ohm; 513 514 514 515 ohm = ntc_thermistor_get_ohm(data); ··· 517 520 *temp = get_temp_mc(data, ohm); 518 521 519 522 return 0; 520 - } 521 - 522 - static ssize_t ntc_show_name(struct device *dev, 523 - struct device_attribute *attr, char *buf) 524 - { 525 - struct ntc_data *data = dev_get_drvdata(dev); 526 - 527 - return sprintf(buf, "%s\n", data->name); 528 523 } 529 524 530 525 static ssize_t ntc_show_type(struct device *dev, ··· 540 551 541 552 static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO, ntc_show_type, NULL, 0); 542 553 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, ntc_show_temp, NULL, 0); 543 - static DEVICE_ATTR(name, S_IRUGO, ntc_show_name, NULL); 544 554 545 - static struct attribute *ntc_attributes[] = { 546 - &dev_attr_name.attr, 555 + static struct attribute *ntc_attrs[] = { 547 556 &sensor_dev_attr_temp1_type.dev_attr.attr, 548 557 &sensor_dev_attr_temp1_input.dev_attr.attr, 549 558 NULL, 550 559 }; 551 - 552 - static const struct attribute_group ntc_attr_group = { 553 - .attrs = ntc_attributes, 554 - }; 560 + ATTRIBUTE_GROUPS(ntc); 555 561 556 562 static const struct thermal_zone_of_device_ops ntc_of_thermal_ops = { 557 563 .get_temp = ntc_read_temp, ··· 560 576 of_match_device(of_match_ptr(ntc_match), dev); 561 577 const struct platform_device_id *pdev_id; 562 578 struct ntc_thermistor_platform_data *pdata; 579 + struct device *hwmon_dev; 563 580 struct ntc_data *data; 564 - int ret; 565 581 566 582 pdata = ntc_thermistor_parse_dt(dev); 567 583 if (IS_ERR(pdata)) ··· 605 621 pdev_id = of_id ? of_id->data : platform_get_device_id(pdev); 606 622 607 623 data->pdata = pdata; 608 - strlcpy(data->name, pdev_id->name, sizeof(data->name)); 609 624 610 625 switch (pdev_id->driver_data) { 611 626 case TYPE_NCPXXWB473: ··· 633 650 return -EINVAL; 634 651 } 635 652 636 - platform_set_drvdata(pdev, data); 637 - 638 - ret = sysfs_create_group(&dev->kobj, &ntc_attr_group); 639 - if (ret) { 640 - dev_err(dev, "unable to create sysfs files\n"); 641 - return ret; 642 - } 643 - 644 - data->hwmon_dev = hwmon_device_register(dev); 645 - if (IS_ERR(data->hwmon_dev)) { 653 + hwmon_dev = devm_hwmon_device_register_with_groups(dev, pdev_id->name, 654 + data, ntc_groups); 655 + if (IS_ERR(hwmon_dev)) { 646 656 dev_err(dev, "unable to register as hwmon device.\n"); 647 - ret = PTR_ERR(data->hwmon_dev); 648 - goto err_after_sysfs; 657 + return PTR_ERR(hwmon_dev); 649 658 } 650 659 651 660 dev_info(dev, "Thermistor type: %s successfully probed.\n", 652 661 pdev_id->name); 653 662 654 - tz = devm_thermal_zone_of_sensor_register(dev, 0, dev, 663 + tz = devm_thermal_zone_of_sensor_register(dev, 0, data, 655 664 &ntc_of_thermal_ops); 656 665 if (IS_ERR(tz)) 657 666 dev_dbg(dev, "Failed to register to thermal fw.\n"); 658 - 659 - return 0; 660 - err_after_sysfs: 661 - sysfs_remove_group(&dev->kobj, &ntc_attr_group); 662 - return ret; 663 - } 664 - 665 - static int ntc_thermistor_remove(struct platform_device *pdev) 666 - { 667 - struct ntc_data *data = platform_get_drvdata(pdev); 668 - 669 - hwmon_device_unregister(data->hwmon_dev); 670 - sysfs_remove_group(&pdev->dev.kobj, &ntc_attr_group); 671 667 672 668 return 0; 673 669 } ··· 657 695 .of_match_table = of_match_ptr(ntc_match), 658 696 }, 659 697 .probe = ntc_thermistor_probe, 660 - .remove = ntc_thermistor_remove, 661 698 .id_table = ntc_thermistor_id, 662 699 }; 663 700