Commit fcbf8780 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki
Browse files

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: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: default avatarStanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
Acked-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
parent 9686f04a
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -179,8 +179,6 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
	for (i = 0; i < trip_cnt; ++i)
		zone_trips[i].hysteresis = hyst;

	int34x_zone->trips = zone_trips;

	int34x_zone->lpat_table = acpi_lpat_get_conversion_table(adev->handle);

	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,
							int34x_zone->ops,
							&int340x_thermal_params,
							0, 0);
	kfree(zone_trips);

	if (IS_ERR(int34x_zone->zone)) {
		ret = PTR_ERR(int34x_zone->zone);
		goto err_thermal_zone;
@@ -203,7 +203,6 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
err_enable:
	thermal_zone_device_unregister(int34x_zone->zone);
err_thermal_zone:
	kfree(int34x_zone->trips);
	acpi_lpat_free_conversion_table(int34x_zone->lpat_table);
err_trips_alloc:
	kfree(int34x_zone->ops);
@@ -217,7 +216,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->trips);
	kfree(int34x_zone->ops);
	kfree(int34x_zone);
}
+0 −1
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ struct active_trip {

struct int34x_thermal_zone {
	struct acpi_device *adev;
	struct thermal_trip *trips;
	int aux_trip_nr;
	struct thermal_zone_device *zone;
	struct thermal_zone_device_ops *ops;
+3 −4
Original line number Diff line number Diff line
@@ -233,10 +233,6 @@ static int get_trip_temp(struct proc_thermal_pci *pci_info)
	return temp;
}

static struct thermal_trip psv_trip = {
	.type = THERMAL_TRIP_PASSIVE,
};

static struct thermal_zone_device_ops tzone_ops = {
	.get_temp = sys_get_curr_temp,
	.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_
{
	struct proc_thermal_device *proc_priv;
	struct proc_thermal_pci *pci_info;
	struct thermal_trip psv_trip = {
		.type = THERMAL_TRIP_PASSIVE,
	};
	int irq_flag = 0, irq, ret;
	bool msi_irq = false;

+13 −11
Original line number Diff line number Diff line
@@ -84,7 +84,6 @@ struct pch_thermal_device {
	void __iomem *hw_base;
	struct pci_dev *pdev;
	struct thermal_zone_device *tzd;
	struct thermal_trip trips[PCH_MAX_TRIPS];
	bool bios_enabled;
};

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

	ptd->trips[trip].type = THERMAL_TRIP_PASSIVE;
	ptd->trips[trip].temperature = temp;
	trip->type = THERMAL_TRIP_PASSIVE;
	trip->temperature = temp;
	return 1;
}
#else
static int pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd, int trip)
static int pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd,
				     struct thermal_trip *trip)
{
	return 0;
}
@@ -159,6 +160,7 @@ static const char *board_names[] = {
static int intel_pch_thermal_probe(struct pci_dev *pdev,
				   const struct pci_device_id *id)
{
	struct thermal_trip ptd_trips[PCH_MAX_TRIPS] = { 0 };
	enum pch_board_ids board_id = id->driver_data;
	struct pch_thermal_device *ptd;
	int nr_trips = 0;
@@ -220,21 +222,21 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev,
	trip_temp = readw(ptd->hw_base + WPT_CTT);
	trip_temp &= 0x1FF;
	if (trip_temp) {
		ptd->trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp);
		ptd->trips[nr_trips++].type = THERMAL_TRIP_CRITICAL;
		ptd_trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp);
		ptd_trips[nr_trips++].type = THERMAL_TRIP_CRITICAL;
	}

	trip_temp = readw(ptd->hw_base + WPT_PHL);
	trip_temp &= 0x1FF;
	if (trip_temp) {
		ptd->trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp);
		ptd->trips[nr_trips++].type = THERMAL_TRIP_HOT;
		ptd_trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp);
		ptd_trips[nr_trips++].type = THERMAL_TRIP_HOT;
	}

	nr_trips += pch_wpt_add_acpi_psv_trip(ptd, nr_trips);
	nr_trips += pch_wpt_add_acpi_psv_trip(ptd, &ptd_trips[nr_trips]);

	ptd->tzd = thermal_zone_device_register_with_trips(board_names[board_id],
							   ptd->trips, nr_trips,
							   ptd_trips, nr_trips,
							   0, ptd, &tzd_ops,
							   NULL, 0, 0);
	if (IS_ERR(ptd->tzd)) {
+6 −6
Original line number Diff line number Diff line
@@ -105,7 +105,6 @@ struct soc_sensor_entry {
	u32 store_ptps;
	u32 store_dts_enable;
	struct thermal_zone_device *tzone;
	struct thermal_trip trips[QRK_MAX_DTS_TRIPS];
};

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

static struct soc_sensor_entry *alloc_soc_dts(void)
{
	struct thermal_trip trips[QRK_MAX_DTS_TRIPS] = { 0 };
	struct soc_sensor_entry *aux_entry;
	int err;
	u32 out;
@@ -362,14 +362,14 @@ static struct soc_sensor_entry *alloc_soc_dts(void)
			goto err_ret;
	}

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

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

	aux_entry->tzone = thermal_zone_device_register_with_trips("quark_dts",
								   aux_entry->trips,
								   trips,
								   QRK_MAX_DTS_TRIPS,
								   wr_mask,
								   aux_entry, &tzone_ops,
Loading