Skip to content

Commit 0d2d586

Browse files
dlezcanoDaniel Lezcano
authored andcommitted
thermal/intel/int340x: Replace parameter to simplify
In the process of replacing the get_trip_* ops by the generic trip points, the current code has an 'override' property to add another indirection to a different ops. Rework this approach to prevent this indirection and make the code ready for the generic trip points conversion. Actually the get_temp() is different regarding the platform, so it is pointless to add a new set of ops but just create dynamically the ops at init time. Signed-off-by: Daniel Lezcano <[email protected]> Reviewed-by: Srinivas Pandruvada <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9ddcb80 commit 0d2d586

File tree

3 files changed

+20
-27
lines changed

3 files changed

+20
-27
lines changed

drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ static int int340x_thermal_get_zone_temp(struct thermal_zone_device *zone,
1818
unsigned long long tmp;
1919
acpi_status status;
2020

21-
if (d->override_ops && d->override_ops->get_temp)
22-
return d->override_ops->get_temp(zone, temp);
23-
2421
status = acpi_evaluate_integer(d->adev->handle, "_TMP", NULL, &tmp);
2522
if (ACPI_FAILURE(status))
2623
return -EIO;
@@ -46,9 +43,6 @@ static int int340x_thermal_get_trip_temp(struct thermal_zone_device *zone,
4643
struct int34x_thermal_zone *d = zone->devdata;
4744
int i;
4845

49-
if (d->override_ops && d->override_ops->get_trip_temp)
50-
return d->override_ops->get_trip_temp(zone, trip, temp);
51-
5246
if (trip < d->aux_trip_nr)
5347
*temp = d->aux_trips[trip];
5448
else if (trip == d->crt_trip_id)
@@ -79,9 +73,6 @@ static int int340x_thermal_get_trip_type(struct thermal_zone_device *zone,
7973
struct int34x_thermal_zone *d = zone->devdata;
8074
int i;
8175

82-
if (d->override_ops && d->override_ops->get_trip_type)
83-
return d->override_ops->get_trip_type(zone, trip, type);
84-
8576
if (trip < d->aux_trip_nr)
8677
*type = THERMAL_TRIP_PASSIVE;
8778
else if (trip == d->crt_trip_id)
@@ -112,9 +103,6 @@ static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone,
112103
acpi_status status;
113104
char name[10];
114105

115-
if (d->override_ops && d->override_ops->set_trip_temp)
116-
return d->override_ops->set_trip_temp(zone, trip, temp);
117-
118106
snprintf(name, sizeof(name), "PAT%d", trip);
119107
status = acpi_execute_simple_method(d->adev->handle, name,
120108
millicelsius_to_deci_kelvin(temp));
@@ -134,9 +122,6 @@ static int int340x_thermal_get_trip_hyst(struct thermal_zone_device *zone,
134122
acpi_status status;
135123
unsigned long long hyst;
136124

137-
if (d->override_ops && d->override_ops->get_trip_hyst)
138-
return d->override_ops->get_trip_hyst(zone, trip, temp);
139-
140125
status = acpi_evaluate_integer(d->adev->handle, "GTSH", NULL, &hyst);
141126
if (ACPI_FAILURE(status))
142127
*temp = 0;
@@ -217,7 +202,7 @@ static struct thermal_zone_params int340x_thermal_params = {
217202
};
218203

219204
struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
220-
struct thermal_zone_device_ops *override_ops)
205+
int (*get_temp) (struct thermal_zone_device *, int *))
221206
{
222207
struct int34x_thermal_zone *int34x_thermal_zone;
223208
acpi_status status;
@@ -231,7 +216,16 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
231216
return ERR_PTR(-ENOMEM);
232217

233218
int34x_thermal_zone->adev = adev;
234-
int34x_thermal_zone->override_ops = override_ops;
219+
220+
int34x_thermal_zone->ops = kmemdup(&int340x_thermal_zone_ops,
221+
sizeof(int340x_thermal_zone_ops), GFP_KERNEL);
222+
if (!int34x_thermal_zone->ops) {
223+
ret = -ENOMEM;
224+
goto err_ops_alloc;
225+
}
226+
227+
if (get_temp)
228+
int34x_thermal_zone->ops->get_temp = get_temp;
235229

236230
status = acpi_evaluate_integer(adev->handle, "PATC", NULL, &trip_cnt);
237231
if (ACPI_FAILURE(status))
@@ -262,7 +256,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
262256
acpi_device_bid(adev),
263257
trip_cnt,
264258
trip_mask, int34x_thermal_zone,
265-
&int340x_thermal_zone_ops,
259+
int34x_thermal_zone->ops,
266260
&int340x_thermal_params,
267261
0, 0);
268262
if (IS_ERR(int34x_thermal_zone->zone)) {
@@ -281,6 +275,8 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
281275
acpi_lpat_free_conversion_table(int34x_thermal_zone->lpat_table);
282276
kfree(int34x_thermal_zone->aux_trips);
283277
err_trip_alloc:
278+
kfree(int34x_thermal_zone->ops);
279+
err_ops_alloc:
284280
kfree(int34x_thermal_zone);
285281
return ERR_PTR(ret);
286282
}
@@ -292,6 +288,7 @@ void int340x_thermal_zone_remove(struct int34x_thermal_zone
292288
thermal_zone_device_unregister(int34x_thermal_zone->zone);
293289
acpi_lpat_free_conversion_table(int34x_thermal_zone->lpat_table);
294290
kfree(int34x_thermal_zone->aux_trips);
291+
kfree(int34x_thermal_zone->ops);
295292
kfree(int34x_thermal_zone);
296293
}
297294
EXPORT_SYMBOL_GPL(int340x_thermal_zone_remove);

drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ struct int34x_thermal_zone {
2929
int hot_temp;
3030
int hot_trip_id;
3131
struct thermal_zone_device *zone;
32-
struct thermal_zone_device_ops *override_ops;
32+
struct thermal_zone_device_ops *ops;
3333
void *priv_data;
3434
struct acpi_lpat_conversion_table *lpat_table;
3535
};
3636

3737
struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *,
38-
struct thermal_zone_device_ops *override_ops);
38+
int (*get_temp) (struct thermal_zone_device *, int *));
3939
void int340x_thermal_zone_remove(struct int34x_thermal_zone *);
4040
int int340x_thermal_read_trips(struct int34x_thermal_zone *int34x_zone);
4141

drivers/thermal/intel/int340x_thermal/processor_thermal_device.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,6 @@ static int proc_thermal_get_zone_temp(struct thermal_zone_device *zone,
207207
return ret;
208208
}
209209

210-
static struct thermal_zone_device_ops proc_thermal_local_ops = {
211-
.get_temp = proc_thermal_get_zone_temp,
212-
};
213-
214210
static int proc_thermal_read_ppcc(struct proc_thermal_device *proc_priv)
215211
{
216212
int i;
@@ -285,7 +281,7 @@ int proc_thermal_add(struct device *dev, struct proc_thermal_device *proc_priv)
285281
struct acpi_device *adev;
286282
acpi_status status;
287283
unsigned long long tmp;
288-
struct thermal_zone_device_ops *ops = NULL;
284+
int (*get_temp) (struct thermal_zone_device *, int *) = NULL;
289285
int ret;
290286

291287
adev = ACPI_COMPANION(dev);
@@ -304,10 +300,10 @@ int proc_thermal_add(struct device *dev, struct proc_thermal_device *proc_priv)
304300
/* there is no _TMP method, add local method */
305301
stored_tjmax = get_tjmax();
306302
if (stored_tjmax > 0)
307-
ops = &proc_thermal_local_ops;
303+
get_temp = proc_thermal_get_zone_temp;
308304
}
309305

310-
proc_priv->int340x_zone = int340x_thermal_zone_add(adev, ops);
306+
proc_priv->int340x_zone = int340x_thermal_zone_add(adev, get_temp);
311307
if (IS_ERR(proc_priv->int340x_zone)) {
312308
return PTR_ERR(proc_priv->int340x_zone);
313309
} else

0 commit comments

Comments
 (0)