]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
thermal: intel: Adjust ops handling during thermal zone registration
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 5 Feb 2024 21:20:32 +0000 (22:20 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 23 Feb 2024 17:24:48 +0000 (18:24 +0100)
Because thermal zone operations are now stored directly in struct
thermal_zone_device, thermal zone creators can discard the operations
structure after the zone registration is complete, or it can be made
read-only.

Accordingly, make int340x_thermal_zone_add() use a local variable to
represent thermal zone operations, so it is freed automatically upon the
function exit, and make the other Intel thermal drivers use const zone
operations structures.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h
drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c
drivers/thermal/intel/intel_pch_thermal.c
drivers/thermal/intel/intel_quark_dts_thermal.c
drivers/thermal/intel/intel_soc_dts_iosf.c
drivers/thermal/intel/x86_pkg_temp_thermal.c

index 950e91ca5f4254020708f349801bd6fff0871554..1b0a9e9206c4d7fcced2915c835a25089240d6bf 100644 (file)
@@ -61,12 +61,6 @@ static void int340x_thermal_critical(struct thermal_zone_device *zone)
        dev_dbg(&zone->device, "%s: critical temperature reached\n", zone->type);
 }
 
-static struct thermal_zone_device_ops int340x_thermal_zone_ops = {
-       .get_temp       = int340x_thermal_get_zone_temp,
-       .set_trip_temp  = int340x_thermal_set_trip_temp,
-       .critical       = int340x_thermal_critical,
-};
-
 static inline void *int_to_trip_priv(int i)
 {
        return (void *)(long)i;
@@ -126,6 +120,11 @@ static struct thermal_zone_params int340x_thermal_params = {
 struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
                                                     int (*get_temp) (struct thermal_zone_device *, int *))
 {
+       const struct thermal_zone_device_ops zone_ops = {
+               .set_trip_temp = int340x_thermal_set_trip_temp,
+               .critical = int340x_thermal_critical,
+               .get_temp = get_temp ? get_temp : int340x_thermal_get_zone_temp,
+       };
        struct int34x_thermal_zone *int34x_zone;
        struct thermal_trip *zone_trips;
        unsigned long long trip_cnt = 0;
@@ -140,16 +139,6 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
 
        int34x_zone->adev = adev;
 
-       int34x_zone->ops = kmemdup(&int340x_thermal_zone_ops,
-                                  sizeof(int340x_thermal_zone_ops), GFP_KERNEL);
-       if (!int34x_zone->ops) {
-               ret = -ENOMEM;
-               goto err_ops_alloc;
-       }
-
-       if (get_temp)
-               int34x_zone->ops->get_temp = get_temp;
-
        status = acpi_evaluate_integer(adev->handle, "PATC", NULL, &trip_cnt);
        if (ACPI_SUCCESS(status)) {
                int34x_zone->aux_trip_nr = trip_cnt;
@@ -185,7 +174,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
                                                        acpi_device_bid(adev),
                                                        zone_trips, trip_cnt,
                                                        trip_mask, int34x_zone,
-                                                       int34x_zone->ops,
+                                                       &zone_ops,
                                                        &int340x_thermal_params,
                                                        0, 0);
        kfree(zone_trips);
@@ -205,8 +194,6 @@ err_enable:
 err_thermal_zone:
        acpi_lpat_free_conversion_table(int34x_zone->lpat_table);
 err_trips_alloc:
-       kfree(int34x_zone->ops);
-err_ops_alloc:
        kfree(int34x_zone);
        return ERR_PTR(ret);
 }
@@ -216,7 +203,6 @@ void int340x_thermal_zone_remove(struct int34x_thermal_zone *int34x_zone)
 {
        thermal_zone_device_unregister(int34x_zone->zone);
        acpi_lpat_free_conversion_table(int34x_zone->lpat_table);
-       kfree(int34x_zone->ops);
        kfree(int34x_zone);
 }
 EXPORT_SYMBOL_GPL(int340x_thermal_zone_remove);
index 91edc7f83d79633f13128e29cb8e761915cefec6..d504e271009aa1de41872b560741dfafdf8beb9f 100644 (file)
@@ -22,7 +22,6 @@ struct int34x_thermal_zone {
        struct acpi_device *adev;
        int aux_trip_nr;
        struct thermal_zone_device *zone;
-       struct thermal_zone_device_ops *ops;
        void *priv_data;
        struct acpi_lpat_conversion_table *lpat_table;
 };
index bf47f319e3c6e32bddebc925b9c3a66c59dc0c29..8ff7e914ecf8e523cce5d9081b87f1155646bd21 100644 (file)
@@ -233,7 +233,7 @@ static int get_trip_temp(struct proc_thermal_pci *pci_info)
        return temp;
 }
 
-static struct thermal_zone_device_ops tzone_ops = {
+static const struct thermal_zone_device_ops tzone_ops = {
        .get_temp = sys_get_curr_temp,
        .set_trip_temp  = sys_set_trip_temp,
 };
index 76a552870fe0c6bf5c0e802cc61f64a672817077..8bfb221e57e753998f5ec4bfddd198a13797ee47 100644 (file)
@@ -132,7 +132,7 @@ static void pch_critical(struct thermal_zone_device *tzd)
                thermal_zone_device_type(tzd));
 }
 
-static struct thermal_zone_device_ops tzd_ops = {
+static const struct thermal_zone_device_ops tzd_ops = {
        .get_temp = pch_thermal_get_temp,
        .critical = pch_critical,
 };
index 06f6d1468717a6900df91794bf5531f62fe14a97..210b822bc988e883255d4e3f74fd451fdb6bbcfa 100644 (file)
@@ -292,7 +292,7 @@ static int sys_change_mode(struct thermal_zone_device *tzd,
        return ret;
 }
 
-static struct thermal_zone_device_ops tzone_ops = {
+static const struct thermal_zone_device_ops tzone_ops = {
        .get_temp = sys_get_curr_temp,
        .set_trip_temp = sys_set_trip_temp,
        .change_mode = sys_change_mode,
index 096cdd3c3b1fa252dacd3d5c13acc176f133d9fe..c008eb42d82ed86904177864233447a21326ce34 100644 (file)
@@ -168,7 +168,7 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd,
        return 0;
 }
 
-static struct thermal_zone_device_ops tzone_ops = {
+static const struct thermal_zone_device_ops tzone_ops = {
        .get_temp = sys_get_curr_temp,
        .set_trip_temp = sys_set_trip_temp,
 };
index dafd28a39bcc78b8d5e5bf359850e70926caf9ef..20cb21cb97c153861a8b04f0ecfb31034bdc4952 100644 (file)
@@ -166,7 +166,7 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
 }
 
 /* Thermal zone callback registry */
-static struct thermal_zone_device_ops tzone_ops = {
+static const struct thermal_zone_device_ops tzone_ops = {
        .get_temp = sys_get_curr_temp,
        .set_trip_temp = sys_set_trip_temp,
 };