Skip to content

Commit fcbf878

Browse files
committed
thermal: intel: Discard trip tables after zone registration
Because the thermal core creates and uses its own copy of the trips table passed to thermal_zone_device_register_with_trips(), it is not necessary to hold on to a local copy of it any more after the given thermal zone has been registered. Accordingly, modify Intel thermal drivers to discard the trips tables passed to thermal_zone_device_register_with_trips() after thermal zone registration, for example by storing them in local variables which are automatically discarded when the zone registration is complete. Also make some additional code simplifications unlocked by the above changes. Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Stanislaw Gruszka <[email protected]> Acked-by: Daniel Lezcano <[email protected]>
1 parent 9686f04 commit fcbf878

File tree

8 files changed

+51
-73
lines changed

8 files changed

+51
-73
lines changed

drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,6 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
179179
for (i = 0; i < trip_cnt; ++i)
180180
zone_trips[i].hysteresis = hyst;
181181

182-
int34x_zone->trips = zone_trips;
183-
184182
int34x_zone->lpat_table = acpi_lpat_get_conversion_table(adev->handle);
185183

186184
int34x_zone->zone = thermal_zone_device_register_with_trips(
@@ -190,6 +188,8 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
190188
int34x_zone->ops,
191189
&int340x_thermal_params,
192190
0, 0);
191+
kfree(zone_trips);
192+
193193
if (IS_ERR(int34x_zone->zone)) {
194194
ret = PTR_ERR(int34x_zone->zone);
195195
goto err_thermal_zone;
@@ -203,7 +203,6 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
203203
err_enable:
204204
thermal_zone_device_unregister(int34x_zone->zone);
205205
err_thermal_zone:
206-
kfree(int34x_zone->trips);
207206
acpi_lpat_free_conversion_table(int34x_zone->lpat_table);
208207
err_trips_alloc:
209208
kfree(int34x_zone->ops);
@@ -217,7 +216,6 @@ void int340x_thermal_zone_remove(struct int34x_thermal_zone *int34x_zone)
217216
{
218217
thermal_zone_device_unregister(int34x_zone->zone);
219218
acpi_lpat_free_conversion_table(int34x_zone->lpat_table);
220-
kfree(int34x_zone->trips);
221219
kfree(int34x_zone->ops);
222220
kfree(int34x_zone);
223221
}

drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ struct active_trip {
2020

2121
struct int34x_thermal_zone {
2222
struct acpi_device *adev;
23-
struct thermal_trip *trips;
2423
int aux_trip_nr;
2524
struct thermal_zone_device *zone;
2625
struct thermal_zone_device_ops *ops;

drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,6 @@ static int get_trip_temp(struct proc_thermal_pci *pci_info)
233233
return temp;
234234
}
235235

236-
static struct thermal_trip psv_trip = {
237-
.type = THERMAL_TRIP_PASSIVE,
238-
};
239-
240236
static struct thermal_zone_device_ops tzone_ops = {
241237
.get_temp = sys_get_curr_temp,
242238
.set_trip_temp = sys_set_trip_temp,
@@ -251,6 +247,9 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_
251247
{
252248
struct proc_thermal_device *proc_priv;
253249
struct proc_thermal_pci *pci_info;
250+
struct thermal_trip psv_trip = {
251+
.type = THERMAL_TRIP_PASSIVE,
252+
};
254253
int irq_flag = 0, irq, ret;
255254
bool msi_irq = false;
256255

drivers/thermal/intel/intel_pch_thermal.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ struct pch_thermal_device {
8484
void __iomem *hw_base;
8585
struct pci_dev *pdev;
8686
struct thermal_zone_device *tzd;
87-
struct thermal_trip trips[PCH_MAX_TRIPS];
8887
bool bios_enabled;
8988
};
9089

@@ -94,7 +93,8 @@ struct pch_thermal_device {
9493
* passive trip temperature using _PSV method. There is no specific
9594
* passive temperature setting in MMIO interface of this PCI device.
9695
*/
97-
static int pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd, int trip)
96+
static int pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd,
97+
struct thermal_trip *trip)
9898
{
9999
struct acpi_device *adev;
100100
int temp;
@@ -106,12 +106,13 @@ static int pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd, int trip)
106106
if (thermal_acpi_passive_trip_temp(adev, &temp) || temp <= 0)
107107
return 0;
108108

109-
ptd->trips[trip].type = THERMAL_TRIP_PASSIVE;
110-
ptd->trips[trip].temperature = temp;
109+
trip->type = THERMAL_TRIP_PASSIVE;
110+
trip->temperature = temp;
111111
return 1;
112112
}
113113
#else
114-
static int pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd, int trip)
114+
static int pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd,
115+
struct thermal_trip *trip)
115116
{
116117
return 0;
117118
}
@@ -159,6 +160,7 @@ static const char *board_names[] = {
159160
static int intel_pch_thermal_probe(struct pci_dev *pdev,
160161
const struct pci_device_id *id)
161162
{
163+
struct thermal_trip ptd_trips[PCH_MAX_TRIPS] = { 0 };
162164
enum pch_board_ids board_id = id->driver_data;
163165
struct pch_thermal_device *ptd;
164166
int nr_trips = 0;
@@ -220,21 +222,21 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev,
220222
trip_temp = readw(ptd->hw_base + WPT_CTT);
221223
trip_temp &= 0x1FF;
222224
if (trip_temp) {
223-
ptd->trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp);
224-
ptd->trips[nr_trips++].type = THERMAL_TRIP_CRITICAL;
225+
ptd_trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp);
226+
ptd_trips[nr_trips++].type = THERMAL_TRIP_CRITICAL;
225227
}
226228

227229
trip_temp = readw(ptd->hw_base + WPT_PHL);
228230
trip_temp &= 0x1FF;
229231
if (trip_temp) {
230-
ptd->trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp);
231-
ptd->trips[nr_trips++].type = THERMAL_TRIP_HOT;
232+
ptd_trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp);
233+
ptd_trips[nr_trips++].type = THERMAL_TRIP_HOT;
232234
}
233235

234-
nr_trips += pch_wpt_add_acpi_psv_trip(ptd, nr_trips);
236+
nr_trips += pch_wpt_add_acpi_psv_trip(ptd, &ptd_trips[nr_trips]);
235237

236238
ptd->tzd = thermal_zone_device_register_with_trips(board_names[board_id],
237-
ptd->trips, nr_trips,
239+
ptd_trips, nr_trips,
238240
0, ptd, &tzd_ops,
239241
NULL, 0, 0);
240242
if (IS_ERR(ptd->tzd)) {

drivers/thermal/intel/intel_quark_dts_thermal.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ struct soc_sensor_entry {
105105
u32 store_ptps;
106106
u32 store_dts_enable;
107107
struct thermal_zone_device *tzone;
108-
struct thermal_trip trips[QRK_MAX_DTS_TRIPS];
109108
};
110109

111110
static struct soc_sensor_entry *soc_dts;
@@ -320,6 +319,7 @@ static void free_soc_dts(struct soc_sensor_entry *aux_entry)
320319

321320
static struct soc_sensor_entry *alloc_soc_dts(void)
322321
{
322+
struct thermal_trip trips[QRK_MAX_DTS_TRIPS] = { 0 };
323323
struct soc_sensor_entry *aux_entry;
324324
int err;
325325
u32 out;
@@ -362,14 +362,14 @@ static struct soc_sensor_entry *alloc_soc_dts(void)
362362
goto err_ret;
363363
}
364364

365-
aux_entry->trips[QRK_DTS_ID_TP_CRITICAL].temperature = get_trip_temp(QRK_DTS_ID_TP_CRITICAL);
366-
aux_entry->trips[QRK_DTS_ID_TP_CRITICAL].type = THERMAL_TRIP_CRITICAL;
365+
trips[QRK_DTS_ID_TP_CRITICAL].temperature = get_trip_temp(QRK_DTS_ID_TP_CRITICAL);
366+
trips[QRK_DTS_ID_TP_CRITICAL].type = THERMAL_TRIP_CRITICAL;
367367

368-
aux_entry->trips[QRK_DTS_ID_TP_HOT].temperature = get_trip_temp(QRK_DTS_ID_TP_HOT);
369-
aux_entry->trips[QRK_DTS_ID_TP_HOT].type = THERMAL_TRIP_HOT;
368+
trips[QRK_DTS_ID_TP_HOT].temperature = get_trip_temp(QRK_DTS_ID_TP_HOT);
369+
trips[QRK_DTS_ID_TP_HOT].type = THERMAL_TRIP_HOT;
370370

371371
aux_entry->tzone = thermal_zone_device_register_with_trips("quark_dts",
372-
aux_entry->trips,
372+
trips,
373373
QRK_MAX_DTS_TRIPS,
374374
wr_mask,
375375
aux_entry, &tzone_ops,

drivers/thermal/intel/intel_soc_dts_iosf.c

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,6 @@ static int update_trip_temp(struct intel_soc_dts_sensors *sensors,
129129
return status;
130130
}
131131

132-
static int configure_trip(struct intel_soc_dts_sensor_entry *dts,
133-
int thres_index, enum thermal_trip_type trip_type,
134-
int temp)
135-
{
136-
int ret;
137-
138-
ret = update_trip_temp(dts->sensors, thres_index, temp);
139-
if (ret)
140-
return ret;
141-
142-
dts->trips[thres_index].temperature = temp;
143-
dts->trips[thres_index].type = trip_type;
144-
145-
return 0;
146-
}
147-
148132
static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
149133
int temp)
150134
{
@@ -218,6 +202,7 @@ static void remove_dts_thermal_zone(struct intel_soc_dts_sensor_entry *dts)
218202
}
219203

220204
static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts,
205+
struct thermal_trip *trips,
221206
bool critical_trip)
222207
{
223208
int writable_trip_cnt = SOC_MAX_DTS_TRIPS;
@@ -254,7 +239,7 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts,
254239
}
255240
dts->trip_mask = trip_mask;
256241
snprintf(name, sizeof(name), "soc_dts%d", id);
257-
dts->tzone = thermal_zone_device_register_with_trips(name, dts->trips,
242+
dts->tzone = thermal_zone_device_register_with_trips(name, trips,
258243
SOC_MAX_DTS_TRIPS,
259244
trip_mask,
260245
dts, &tzone_ops,
@@ -315,14 +300,15 @@ EXPORT_SYMBOL_GPL(intel_soc_dts_iosf_interrupt_handler);
315300

316301
static void dts_trips_reset(struct intel_soc_dts_sensors *sensors, int dts_index)
317302
{
318-
configure_trip(&sensors->soc_dts[dts_index], 0, 0, 0);
319-
configure_trip(&sensors->soc_dts[dts_index], 1, 0, 0);
303+
update_trip_temp(sensors, 0, 0);
304+
update_trip_temp(sensors, 1, 0);
320305
}
321306

322307
struct intel_soc_dts_sensors *
323308
intel_soc_dts_iosf_init(enum intel_soc_dts_interrupt_type intr_type,
324309
bool critical_trip, int crit_offset)
325310
{
311+
struct thermal_trip trips[SOC_MAX_DTS_SENSORS][SOC_MAX_DTS_TRIPS] = { 0 };
326312
struct intel_soc_dts_sensors *sensors;
327313
int tj_max;
328314
int ret;
@@ -350,25 +336,31 @@ intel_soc_dts_iosf_init(enum intel_soc_dts_interrupt_type intr_type,
350336

351337
sensors->soc_dts[i].sensors = sensors;
352338

353-
ret = configure_trip(&sensors->soc_dts[i], 0,
354-
THERMAL_TRIP_PASSIVE, 0);
339+
ret = update_trip_temp(sensors, 0, 0);
355340
if (ret)
356341
goto err_reset_trips;
357342

343+
trips[i][0].type = THERMAL_TRIP_PASSIVE;
344+
trips[i][0].temperature = 0;
345+
358346
if (critical_trip) {
359347
trip_type = THERMAL_TRIP_CRITICAL;
360348
temp = sensors->tj_max - crit_offset;
361349
} else {
362350
trip_type = THERMAL_TRIP_PASSIVE;
363351
temp = 0;
364352
}
365-
ret = configure_trip(&sensors->soc_dts[i], 1, trip_type, temp);
353+
ret = update_trip_temp(sensors, 1, temp);
366354
if (ret)
367355
goto err_reset_trips;
356+
357+
trips[i][1].type = trip_type;
358+
trips[i][1].temperature = temp;
368359
}
369360

370361
for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) {
371-
ret = add_dts_thermal_zone(i, &sensors->soc_dts[i], critical_trip);
362+
ret = add_dts_thermal_zone(i, &sensors->soc_dts[i], trips[i],
363+
critical_trip);
372364
if (ret)
373365
goto err_remove_zone;
374366
}

drivers/thermal/intel/intel_soc_dts_iosf.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ struct intel_soc_dts_sensor_entry {
2929
int id;
3030
u32 store_status;
3131
u32 trip_mask;
32-
struct thermal_trip trips[SOC_MAX_DTS_TRIPS];
3332
struct thermal_zone_device *tzone;
3433
struct intel_soc_dts_sensors *sensors;
3534
};

drivers/thermal/intel/x86_pkg_temp_thermal.c

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ struct zone_device {
5353
u32 msr_pkg_therm_high;
5454
struct delayed_work work;
5555
struct thermal_zone_device *tzone;
56-
struct thermal_trip *trips;
5756
struct cpumask cpumask;
5857
};
5958

@@ -268,17 +267,13 @@ static int pkg_thermal_notify(u64 msr_val)
268267
return 0;
269268
}
270269

271-
static struct thermal_trip *pkg_temp_thermal_trips_init(int cpu, int tj_max, int num_trips)
270+
static int pkg_temp_thermal_trips_init(int cpu, int tj_max,
271+
struct thermal_trip *trips, int num_trips)
272272
{
273-
struct thermal_trip *trips;
274273
unsigned long thres_reg_value;
275274
u32 mask, shift, eax, edx;
276275
int ret, i;
277276

278-
trips = kzalloc(sizeof(*trips) * num_trips, GFP_KERNEL);
279-
if (!trips)
280-
return ERR_PTR(-ENOMEM);
281-
282277
for (i = 0; i < num_trips; i++) {
283278

284279
if (i) {
@@ -291,10 +286,8 @@ static struct thermal_trip *pkg_temp_thermal_trips_init(int cpu, int tj_max, int
291286

292287
ret = rdmsr_on_cpu(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
293288
&eax, &edx);
294-
if (ret < 0) {
295-
kfree(trips);
296-
return ERR_PTR(ret);
297-
}
289+
if (ret < 0)
290+
return ret;
298291

299292
thres_reg_value = (eax & mask) >> shift;
300293

@@ -307,11 +300,12 @@ static struct thermal_trip *pkg_temp_thermal_trips_init(int cpu, int tj_max, int
307300
__func__, cpu, i, trips[i].temperature);
308301
}
309302

310-
return trips;
303+
return 0;
311304
}
312305

313306
static int pkg_temp_thermal_device_add(unsigned int cpu)
314307
{
308+
struct thermal_trip trips[MAX_NUMBER_OF_TRIPS] = { 0 };
315309
int id = topology_logical_die_id(cpu);
316310
u32 eax, ebx, ecx, edx;
317311
struct zone_device *zonedev;
@@ -336,21 +330,19 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
336330
if (!zonedev)
337331
return -ENOMEM;
338332

339-
zonedev->trips = pkg_temp_thermal_trips_init(cpu, tj_max, thres_count);
340-
if (IS_ERR(zonedev->trips)) {
341-
err = PTR_ERR(zonedev->trips);
333+
err = pkg_temp_thermal_trips_init(cpu, tj_max, trips, thres_count);
334+
if (err)
342335
goto out_kfree_zonedev;
343-
}
344336

345337
INIT_DELAYED_WORK(&zonedev->work, pkg_temp_thermal_threshold_work_fn);
346338
zonedev->cpu = cpu;
347339
zonedev->tzone = thermal_zone_device_register_with_trips("x86_pkg_temp",
348-
zonedev->trips, thres_count,
340+
trips, thres_count,
349341
(thres_count == MAX_NUMBER_OF_TRIPS) ? 0x03 : 0x01,
350342
zonedev, &tzone_ops, &pkg_temp_tz_params, 0, 0);
351343
if (IS_ERR(zonedev->tzone)) {
352344
err = PTR_ERR(zonedev->tzone);
353-
goto out_kfree_trips;
345+
goto out_kfree_zonedev;
354346
}
355347
err = thermal_zone_device_enable(zonedev->tzone);
356348
if (err)
@@ -369,8 +361,6 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
369361

370362
out_unregister_tz:
371363
thermal_zone_device_unregister(zonedev->tzone);
372-
out_kfree_trips:
373-
kfree(zonedev->trips);
374364
out_kfree_zonedev:
375365
kfree(zonedev);
376366
return err;
@@ -457,10 +447,9 @@ static int pkg_thermal_cpu_offline(unsigned int cpu)
457447
raw_spin_unlock_irq(&pkg_temp_lock);
458448

459449
/* Final cleanup if this is the last cpu */
460-
if (lastcpu) {
461-
kfree(zonedev->trips);
450+
if (lastcpu)
462451
kfree(zonedev);
463-
}
452+
464453
return 0;
465454
}
466455

0 commit comments

Comments
 (0)