public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Linux PM <linux-pm@vger.kernel.org>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Linux ACPI <linux-acpi@vger.kernel.org>,
	Lukasz Luba <lukasz.luba@arm.com>,
	Zhang Rui <rui.zhang@intel.com>,
	Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
	Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	NXP Linux Team <linux-imx@nxp.com>
Subject: [PATCH v2 6/6] thermal: intel: Adjust ops handling during thermal zone registration
Date: Wed, 14 Feb 2024 13:49:41 +0100	[thread overview]
Message-ID: <3213551.5fSG56mABF@kreacher> (raw)
In-Reply-To: <4551531.LvFx2qVVIh@kreacher>

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

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>
---

v1 -> v2:
   * Rebase.
   * Add R-by from Stanislaw.

---
 drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c         |   26 ++--------
 drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h         |    1 
 drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c |    2 
 drivers/thermal/intel/intel_pch_thermal.c                            |    2 
 drivers/thermal/intel/intel_quark_dts_thermal.c                      |    2 
 drivers/thermal/intel/intel_soc_dts_iosf.c                           |    2 
 drivers/thermal/intel/x86_pkg_temp_thermal.c                         |    2 
 7 files changed, 11 insertions(+), 26 deletions(-)

Index: linux-pm/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
===================================================================
--- linux-pm.orig/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
+++ linux-pm/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
@@ -61,12 +61,6 @@ static void int340x_thermal_critical(str
 	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 int340
 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;
@@ -139,16 +138,6 @@ struct int34x_thermal_zone *int340x_ther
 
 	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;
@@ -183,7 +172,7 @@ struct int34x_thermal_zone *int340x_ther
 							acpi_device_bid(adev),
 							zone_trips, trip_cnt,
 							int34x_zone,
-							int34x_zone->ops,
+							&zone_ops,
 							&int340x_thermal_params,
 							0, 0);
 	kfree(zone_trips);
@@ -203,8 +192,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);
 }
@@ -214,7 +201,6 @@ void int340x_thermal_zone_remove(struct
 {
 	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: linux-pm/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h
===================================================================
--- linux-pm.orig/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h
+++ linux-pm/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h
@@ -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: linux-pm/drivers/thermal/intel/intel_pch_thermal.c
===================================================================
--- linux-pm.orig/drivers/thermal/intel/intel_pch_thermal.c
+++ linux-pm/drivers/thermal/intel/intel_pch_thermal.c
@@ -132,7 +132,7 @@ static void pch_critical(struct thermal_
 		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: linux-pm/drivers/thermal/intel/intel_quark_dts_thermal.c
===================================================================
--- linux-pm.orig/drivers/thermal/intel/intel_quark_dts_thermal.c
+++ linux-pm/drivers/thermal/intel/intel_quark_dts_thermal.c
@@ -288,7 +288,7 @@ static int sys_change_mode(struct therma
 	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: linux-pm/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c
===================================================================
--- linux-pm.orig/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c
+++ linux-pm/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c
@@ -233,7 +233,7 @@ static int get_trip_temp(struct proc_the
 	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: linux-pm/drivers/thermal/intel/intel_soc_dts_iosf.c
===================================================================
--- linux-pm.orig/drivers/thermal/intel/intel_soc_dts_iosf.c
+++ linux-pm/drivers/thermal/intel/intel_soc_dts_iosf.c
@@ -168,7 +168,7 @@ static int sys_get_curr_temp(struct ther
 	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: linux-pm/drivers/thermal/intel/x86_pkg_temp_thermal.c
===================================================================
--- linux-pm.orig/drivers/thermal/intel/x86_pkg_temp_thermal.c
+++ linux-pm/drivers/thermal/intel/x86_pkg_temp_thermal.c
@@ -166,7 +166,7 @@ sys_set_trip_temp(struct thermal_zone_de
 }
 
 /* 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,
 };




  parent reply	other threads:[~2024-02-14 12:50 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-14 12:25 [PATCH v2 0/6] thermal: Store trips table and ops in thermal_zone_device Rafael J. Wysocki
2024-02-14 12:28 ` [PATCH v2 1/6] thermal: core: Store zone trips table in struct thermal_zone_device Rafael J. Wysocki
2024-02-22 10:27   ` Daniel Lezcano
2024-02-22 13:10   ` [PATCH v2.1 " Rafael J. Wysocki
2024-02-22 13:38     ` Daniel Lezcano
2024-02-22 13:45       ` Rafael J. Wysocki
2024-02-22 13:52   ` [PATCH v2.2 " Rafael J. Wysocki
2024-02-22 15:39     ` Daniel Lezcano
2024-02-14 12:30 ` [PATCH v2 2/6] thermal: ACPI: Discard trips table after zone registration Rafael J. Wysocki
2024-02-22 10:28   ` Daniel Lezcano
2024-02-14 12:42 ` [PATCH v2 3/6] thermal: intel: Discard trip tables " Rafael J. Wysocki
2024-02-22 10:34   ` Daniel Lezcano
2024-02-14 12:45 ` [PATCH v2 4/6] thermal: core: Store zone ops in struct thermal_zone_device Rafael J. Wysocki
2024-02-22 10:44   ` Daniel Lezcano
2024-02-22 10:47   ` Daniel Lezcano
2024-02-22 10:52     ` Rafael J. Wysocki
2024-02-22 10:58       ` Daniel Lezcano
2024-02-22 11:03         ` Rafael J. Wysocki
2024-02-22 14:05       ` Rafael J. Wysocki
2024-02-14 12:48 ` [PATCH v2 5/6] thermal: ACPI: Constify acpi_thermal_zone_ops Rafael J. Wysocki
2024-02-22 10:48   ` Daniel Lezcano
2024-02-14 12:49 ` Rafael J. Wysocki [this message]
2024-02-22 11:06   ` [PATCH v2 6/6] thermal: intel: Adjust ops handling during thermal zone registration Daniel Lezcano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3213551.5fSG56mABF@kreacher \
    --to=rjw@rjwysocki.net \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=festevam@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=rui.zhang@intel.com \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=srinivas.pandruvada@linux.intel.com \
    --cc=stanislaw.gruszka@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox