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

Configure Feed

Select the types of activity you want to include in your feed.

drm/radeon/dpm: Convert to use devm_hwmon_register_with_groups

Simplify the code and fix race condition seen because
attribute files were created after hwmon device registration.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Guenter Roeck and committed by
Alex Deucher
ec39f64b 55d4e020

+12 -37
+12 -37
drivers/gpu/drm/radeon/radeon_pm.c
··· 537 537 struct device_attribute *attr, 538 538 char *buf) 539 539 { 540 - struct drm_device *ddev = dev_get_drvdata(dev); 541 - struct radeon_device *rdev = ddev->dev_private; 540 + struct radeon_device *rdev = dev_get_drvdata(dev); 542 541 int temp; 543 542 544 543 if (rdev->asic->pm.get_temperature) ··· 565 566 return snprintf(buf, PAGE_SIZE, "%d\n", temp); 566 567 } 567 568 568 - static ssize_t radeon_hwmon_show_name(struct device *dev, 569 - struct device_attribute *attr, 570 - char *buf) 571 - { 572 - return sprintf(buf, "radeon\n"); 573 - } 574 - 575 569 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, radeon_hwmon_show_temp, NULL, 0); 576 570 static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, radeon_hwmon_show_temp_thresh, NULL, 0); 577 571 static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, radeon_hwmon_show_temp_thresh, NULL, 1); 578 - static SENSOR_DEVICE_ATTR(name, S_IRUGO, radeon_hwmon_show_name, NULL, 0); 579 572 580 573 static struct attribute *hwmon_attributes[] = { 581 574 &sensor_dev_attr_temp1_input.dev_attr.attr, 582 575 &sensor_dev_attr_temp1_crit.dev_attr.attr, 583 576 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, 584 - &sensor_dev_attr_name.dev_attr.attr, 585 577 NULL 586 578 }; 587 579 ··· 597 607 .is_visible = hwmon_attributes_visible, 598 608 }; 599 609 610 + static const struct attribute_group *hwmon_groups[] = { 611 + &hwmon_attrgroup, 612 + NULL 613 + }; 614 + 600 615 static int radeon_hwmon_init(struct radeon_device *rdev) 601 616 { 602 617 int err = 0; 603 - 604 - rdev->pm.int_hwmon_dev = NULL; 618 + struct device *hwmon_dev; 605 619 606 620 switch (rdev->pm.int_thermal_type) { 607 621 case THERMAL_TYPE_RV6XX: ··· 618 624 case THERMAL_TYPE_KV: 619 625 if (rdev->asic->pm.get_temperature == NULL) 620 626 return err; 621 - rdev->pm.int_hwmon_dev = hwmon_device_register(rdev->dev); 622 - if (IS_ERR(rdev->pm.int_hwmon_dev)) { 623 - err = PTR_ERR(rdev->pm.int_hwmon_dev); 627 + hwmon_dev = hwmon_device_register_with_groups(rdev->dev, 628 + "radeon", rdev, 629 + hwmon_groups); 630 + if (IS_ERR(hwmon_dev)) { 631 + err = PTR_ERR(hwmon_dev); 624 632 dev_err(rdev->dev, 625 633 "Unable to register hwmon device: %d\n", err); 626 - break; 627 - } 628 - dev_set_drvdata(rdev->pm.int_hwmon_dev, rdev->ddev); 629 - err = sysfs_create_group(&rdev->pm.int_hwmon_dev->kobj, 630 - &hwmon_attrgroup); 631 - if (err) { 632 - dev_err(rdev->dev, 633 - "Unable to create hwmon sysfs file: %d\n", err); 634 - hwmon_device_unregister(rdev->dev); 635 634 } 636 635 break; 637 636 default: ··· 632 645 } 633 646 634 647 return err; 635 - } 636 - 637 - static void radeon_hwmon_fini(struct radeon_device *rdev) 638 - { 639 - if (rdev->pm.int_hwmon_dev) { 640 - sysfs_remove_group(&rdev->pm.int_hwmon_dev->kobj, &hwmon_attrgroup); 641 - hwmon_device_unregister(rdev->pm.int_hwmon_dev); 642 - } 643 648 } 644 649 645 650 static void radeon_dpm_thermal_work_handler(struct work_struct *work) ··· 1316 1337 1317 1338 if (rdev->pm.power_state) 1318 1339 kfree(rdev->pm.power_state); 1319 - 1320 - radeon_hwmon_fini(rdev); 1321 1340 } 1322 1341 1323 1342 static void radeon_pm_fini_dpm(struct radeon_device *rdev) ··· 1335 1358 1336 1359 if (rdev->pm.power_state) 1337 1360 kfree(rdev->pm.power_state); 1338 - 1339 - radeon_hwmon_fini(rdev); 1340 1361 } 1341 1362 1342 1363 void radeon_pm_fini(struct radeon_device *rdev)