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.

ACPI: thermal: Convert the driver to a platform one

While binding drivers directly to struct acpi_device objects allows
basic functionality to be provided, at least in the majority of cases,
there are some problems with it, related to general consistency, sysfs
layout, power management operation ordering, and code cleanliness.

Overall, it is better to bind drivers to platform devices than to their
ACPI companions, so convert the ACPI thermal zone driver to a platform
one.

While this is not expected to alter functionality, it changes sysfs
layout and so it will be visible to user space.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: lihuisong@huawei.com
Link: https://patch.msgid.link/2249483.irdbgypaU6@rafael.j.wysocki

+19 -29
+19 -29
drivers/acpi/thermal.c
··· 25 25 #include <linux/kmod.h> 26 26 #include <linux/reboot.h> 27 27 #include <linux/device.h> 28 + #include <linux/platform_device.h> 28 29 #include <linux/thermal.h> 29 30 #include <linux/acpi.h> 30 31 #include <linux/workqueue.h> ··· 777 776 kfree(tz); 778 777 } 779 778 780 - static int acpi_thermal_add(struct acpi_device *device) 779 + static int acpi_thermal_probe(struct platform_device *pdev) 781 780 { 782 781 struct thermal_trip trip_table[ACPI_THERMAL_MAX_NR_TRIPS] = { 0 }; 782 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 783 783 struct acpi_thermal_trip *acpi_trip; 784 784 struct thermal_trip *trip; 785 785 struct acpi_thermal *tz; ··· 796 794 if (!tz) 797 795 return -ENOMEM; 798 796 797 + platform_set_drvdata(pdev, tz); 798 + 799 799 tz->device = device; 800 800 strscpy(tz->name, device->pnp.bus_id); 801 801 strscpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME); 802 802 strscpy(acpi_device_class(device), ACPI_THERMAL_CLASS); 803 - device->driver_data = tz; 804 803 805 804 acpi_thermal_aml_dependency_fix(tz); 806 805 ··· 898 895 return result; 899 896 } 900 897 901 - static void acpi_thermal_remove(struct acpi_device *device) 898 + static void acpi_thermal_remove(struct platform_device *pdev) 902 899 { 903 - struct acpi_thermal *tz; 900 + struct acpi_thermal *tz = platform_get_drvdata(pdev); 904 901 905 - if (!device || !acpi_driver_data(device)) 906 - return; 907 - 908 - tz = acpi_driver_data(device); 909 - 910 - acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY, 902 + acpi_dev_remove_notify_handler(tz->device, ACPI_DEVICE_NOTIFY, 911 903 acpi_thermal_notify); 912 904 913 905 flush_workqueue(acpi_thermal_pm_queue); ··· 920 922 921 923 static int acpi_thermal_resume(struct device *dev) 922 924 { 923 - struct acpi_thermal *tz; 925 + struct acpi_thermal *tz = dev_get_drvdata(dev); 924 926 int i, j; 925 - 926 - if (!dev) 927 - return -EINVAL; 928 - 929 - tz = acpi_driver_data(to_acpi_device(dev)); 930 - if (!tz) 931 - return -EINVAL; 932 927 933 928 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { 934 929 struct acpi_thermal_trip *acpi_trip = &tz->trips.active[i].trip; ··· 949 958 }; 950 959 MODULE_DEVICE_TABLE(acpi, thermal_device_ids); 951 960 952 - static struct acpi_driver acpi_thermal_driver = { 953 - .name = "thermal", 954 - .class = ACPI_THERMAL_CLASS, 955 - .ids = thermal_device_ids, 956 - .ops = { 957 - .add = acpi_thermal_add, 958 - .remove = acpi_thermal_remove, 959 - }, 960 - .drv.pm = &acpi_thermal_pm, 961 + static struct platform_driver acpi_thermal_driver = { 962 + .probe = acpi_thermal_probe, 963 + .remove = acpi_thermal_remove, 964 + .driver = { 965 + .name = "acpi-thermal", 966 + .acpi_match_table = thermal_device_ids, 967 + .pm = &acpi_thermal_pm, 968 + }, 961 969 }; 962 970 963 971 static int thermal_act(const struct dmi_system_id *d) ··· 1054 1064 if (!acpi_thermal_pm_queue) 1055 1065 return -ENODEV; 1056 1066 1057 - result = acpi_bus_register_driver(&acpi_thermal_driver); 1067 + result = platform_driver_register(&acpi_thermal_driver); 1058 1068 if (result < 0) { 1059 1069 destroy_workqueue(acpi_thermal_pm_queue); 1060 1070 return -ENODEV; ··· 1065 1075 1066 1076 static void __exit acpi_thermal_exit(void) 1067 1077 { 1068 - acpi_bus_unregister_driver(&acpi_thermal_driver); 1078 + platform_driver_unregister(&acpi_thermal_driver); 1069 1079 destroy_workqueue(acpi_thermal_pm_queue); 1070 1080 } 1071 1081