Skip to content

Commit 62dd178

Browse files
committed
thermal: intel: Adjust ops handling during thermal zone registration
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>
1 parent 75fb871 commit 62dd178

File tree

7 files changed

+11
-26
lines changed

7 files changed

+11
-26
lines changed

drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,6 @@ static void int340x_thermal_critical(struct thermal_zone_device *zone)
6161
dev_dbg(&zone->device, "%s: critical temperature reached\n", zone->type);
6262
}
6363

64-
static struct thermal_zone_device_ops int340x_thermal_zone_ops = {
65-
.get_temp = int340x_thermal_get_zone_temp,
66-
.set_trip_temp = int340x_thermal_set_trip_temp,
67-
.critical = int340x_thermal_critical,
68-
};
69-
7064
static inline void *int_to_trip_priv(int i)
7165
{
7266
return (void *)(long)i;
@@ -126,6 +120,11 @@ static struct thermal_zone_params int340x_thermal_params = {
126120
struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
127121
int (*get_temp) (struct thermal_zone_device *, int *))
128122
{
123+
const struct thermal_zone_device_ops zone_ops = {
124+
.set_trip_temp = int340x_thermal_set_trip_temp,
125+
.critical = int340x_thermal_critical,
126+
.get_temp = get_temp ? get_temp : int340x_thermal_get_zone_temp,
127+
};
129128
struct int34x_thermal_zone *int34x_zone;
130129
struct thermal_trip *zone_trips;
131130
unsigned long long trip_cnt = 0;
@@ -140,16 +139,6 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
140139

141140
int34x_zone->adev = adev;
142141

143-
int34x_zone->ops = kmemdup(&int340x_thermal_zone_ops,
144-
sizeof(int340x_thermal_zone_ops), GFP_KERNEL);
145-
if (!int34x_zone->ops) {
146-
ret = -ENOMEM;
147-
goto err_ops_alloc;
148-
}
149-
150-
if (get_temp)
151-
int34x_zone->ops->get_temp = get_temp;
152-
153142
status = acpi_evaluate_integer(adev->handle, "PATC", NULL, &trip_cnt);
154143
if (ACPI_SUCCESS(status)) {
155144
int34x_zone->aux_trip_nr = trip_cnt;
@@ -185,7 +174,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
185174
acpi_device_bid(adev),
186175
zone_trips, trip_cnt,
187176
trip_mask, int34x_zone,
188-
int34x_zone->ops,
177+
&zone_ops,
189178
&int340x_thermal_params,
190179
0, 0);
191180
kfree(zone_trips);
@@ -205,8 +194,6 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
205194
err_thermal_zone:
206195
acpi_lpat_free_conversion_table(int34x_zone->lpat_table);
207196
err_trips_alloc:
208-
kfree(int34x_zone->ops);
209-
err_ops_alloc:
210197
kfree(int34x_zone);
211198
return ERR_PTR(ret);
212199
}
@@ -216,7 +203,6 @@ void int340x_thermal_zone_remove(struct int34x_thermal_zone *int34x_zone)
216203
{
217204
thermal_zone_device_unregister(int34x_zone->zone);
218205
acpi_lpat_free_conversion_table(int34x_zone->lpat_table);
219-
kfree(int34x_zone->ops);
220206
kfree(int34x_zone);
221207
}
222208
EXPORT_SYMBOL_GPL(int340x_thermal_zone_remove);

drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ struct int34x_thermal_zone {
2222
struct acpi_device *adev;
2323
int aux_trip_nr;
2424
struct thermal_zone_device *zone;
25-
struct thermal_zone_device_ops *ops;
2625
void *priv_data;
2726
struct acpi_lpat_conversion_table *lpat_table;
2827
};

drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static int get_trip_temp(struct proc_thermal_pci *pci_info)
233233
return temp;
234234
}
235235

236-
static struct thermal_zone_device_ops tzone_ops = {
236+
static const struct thermal_zone_device_ops tzone_ops = {
237237
.get_temp = sys_get_curr_temp,
238238
.set_trip_temp = sys_set_trip_temp,
239239
};

drivers/thermal/intel/intel_pch_thermal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static void pch_critical(struct thermal_zone_device *tzd)
132132
thermal_zone_device_type(tzd));
133133
}
134134

135-
static struct thermal_zone_device_ops tzd_ops = {
135+
static const struct thermal_zone_device_ops tzd_ops = {
136136
.get_temp = pch_thermal_get_temp,
137137
.critical = pch_critical,
138138
};

drivers/thermal/intel/intel_quark_dts_thermal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ static int sys_change_mode(struct thermal_zone_device *tzd,
292292
return ret;
293293
}
294294

295-
static struct thermal_zone_device_ops tzone_ops = {
295+
static const struct thermal_zone_device_ops tzone_ops = {
296296
.get_temp = sys_get_curr_temp,
297297
.set_trip_temp = sys_set_trip_temp,
298298
.change_mode = sys_change_mode,

drivers/thermal/intel/intel_soc_dts_iosf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd,
168168
return 0;
169169
}
170170

171-
static struct thermal_zone_device_ops tzone_ops = {
171+
static const struct thermal_zone_device_ops tzone_ops = {
172172
.get_temp = sys_get_curr_temp,
173173
.set_trip_temp = sys_set_trip_temp,
174174
};

drivers/thermal/intel/x86_pkg_temp_thermal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
166166
}
167167

168168
/* Thermal zone callback registry */
169-
static struct thermal_zone_device_ops tzone_ops = {
169+
static const struct thermal_zone_device_ops tzone_ops = {
170170
.get_temp = sys_get_curr_temp,
171171
.set_trip_temp = sys_set_trip_temp,
172172
};

0 commit comments

Comments
 (0)