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 2/6] thermal: ACPI: Discard trips table after zone registration
Date: Wed, 14 Feb 2024 13:30:23 +0100 [thread overview]
Message-ID: <13457348.uLZWGnKmhe@kreacher> (raw)
In-Reply-To: <4551531.LvFx2qVVIh@kreacher>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
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 the ACPI thermal driver to store the trips table
passed to thermal_zone_device_register_with_trips() in a local variable
which is automatically discarded when acpi_thermal_add() returns to
its caller.
Also make some additional code simplifications unlocked by the above
change.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
---
v1 -> v2: Add R-by from Stanislaw.
---
drivers/acpi/thermal.c | 57 +++++++++++++++++--------------------------------
1 file changed, 20 insertions(+), 37 deletions(-)
Index: linux-pm/drivers/acpi/thermal.c
===================================================================
--- linux-pm.orig/drivers/acpi/thermal.c
+++ linux-pm/drivers/acpi/thermal.c
@@ -47,6 +47,8 @@
#define ACPI_THERMAL_TRIP_PASSIVE (-1)
+#define ACPI_THERMAL_MAX_NR_TRIPS (ACPI_THERMAL_MAX_ACTIVE + 3)
+
/*
* This exception is thrown out in two cases:
* 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
@@ -112,7 +114,6 @@ struct acpi_thermal {
unsigned long polling_frequency;
volatile u8 zombie;
struct acpi_thermal_trips trips;
- struct thermal_trip *trip_table;
struct thermal_zone_device *thermal_zone;
int kelvin_offset; /* in millidegrees */
struct work_struct thermal_check_work;
@@ -451,26 +452,19 @@ fail:
return false;
}
-static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
+static void acpi_thermal_get_trip_points(struct acpi_thermal *tz)
{
- unsigned int count = 0;
int i;
- if (acpi_thermal_init_trip(tz, ACPI_THERMAL_TRIP_PASSIVE))
- count++;
+ acpi_thermal_init_trip(tz, ACPI_THERMAL_TRIP_PASSIVE);
for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
- if (acpi_thermal_init_trip(tz, i))
- count++;
- else
+ if (!acpi_thermal_init_trip(tz, i))
break;
-
}
while (++i < ACPI_THERMAL_MAX_ACTIVE)
tz->trips.active[i].trip.temp_dk = THERMAL_TEMP_INVALID;
-
- return count;
}
/* sys I/F for generic thermal sysfs support */
@@ -662,13 +656,14 @@ static void acpi_thermal_zone_sysfs_remo
}
static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz,
+ const struct thermal_trip *trip_table,
unsigned int trip_count,
int passive_delay)
{
int result;
tz->thermal_zone = thermal_zone_device_register_with_trips("acpitz",
- tz->trip_table,
+ trip_table,
trip_count,
tz,
&acpi_thermal_zone_ops,
@@ -823,10 +818,10 @@ static void acpi_thermal_free_thermal_zo
static int acpi_thermal_add(struct acpi_device *device)
{
+ struct thermal_trip trip_table[ACPI_THERMAL_MAX_NR_TRIPS] = { 0 };
struct acpi_thermal_trip *acpi_trip;
struct thermal_trip *trip;
struct acpi_thermal *tz;
- unsigned int trip_count;
int crit_temp, hot_temp;
int passive_delay = 0;
int result;
@@ -848,21 +843,10 @@ static int acpi_thermal_add(struct acpi_
acpi_thermal_aml_dependency_fix(tz);
/* Get trip points [_CRT, _PSV, etc.] (required). */
- trip_count = acpi_thermal_get_trip_points(tz);
+ acpi_thermal_get_trip_points(tz);
crit_temp = acpi_thermal_get_critical_trip(tz);
- if (crit_temp != THERMAL_TEMP_INVALID)
- trip_count++;
-
hot_temp = acpi_thermal_get_hot_trip(tz);
- if (hot_temp != THERMAL_TEMP_INVALID)
- trip_count++;
-
- if (!trip_count) {
- pr_warn(FW_BUG "No valid trip points!\n");
- result = -ENODEV;
- goto free_memory;
- }
/* Get temperature [_TMP] (required). */
result = acpi_thermal_get_temperature(tz);
@@ -881,13 +865,7 @@ static int acpi_thermal_add(struct acpi_
acpi_thermal_guess_offset(tz, crit_temp);
- trip = kcalloc(trip_count, sizeof(*trip), GFP_KERNEL);
- if (!trip) {
- result = -ENOMEM;
- goto free_memory;
- }
-
- tz->trip_table = trip;
+ trip = trip_table;
if (crit_temp != THERMAL_TEMP_INVALID) {
trip->type = THERMAL_TRIP_CRITICAL;
@@ -923,9 +901,17 @@ static int acpi_thermal_add(struct acpi_
trip++;
}
- result = acpi_thermal_register_thermal_zone(tz, trip_count, passive_delay);
+ if (trip == trip_table) {
+ pr_warn(FW_BUG "No valid trip points!\n");
+ result = -ENODEV;
+ goto free_memory;
+ }
+
+ result = acpi_thermal_register_thermal_zone(tz, trip_table,
+ trip - trip_table,
+ passive_delay);
if (result)
- goto free_trips;
+ goto free_memory;
refcount_set(&tz->thermal_check_count, 3);
mutex_init(&tz->thermal_check_lock);
@@ -944,8 +930,6 @@ static int acpi_thermal_add(struct acpi_
flush_wq:
flush_workqueue(acpi_thermal_pm_queue);
acpi_thermal_unregister_thermal_zone(tz);
-free_trips:
- kfree(tz->trip_table);
free_memory:
acpi_thermal_free_thermal_zone(tz);
@@ -966,7 +950,6 @@ static void acpi_thermal_remove(struct a
flush_workqueue(acpi_thermal_pm_queue);
acpi_thermal_unregister_thermal_zone(tz);
- kfree(tz->trip_table);
acpi_thermal_free_thermal_zone(tz);
}
next prev 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 ` Rafael J. Wysocki [this message]
2024-02-22 10:28 ` [PATCH v2 2/6] thermal: ACPI: Discard trips table after zone registration 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 ` [PATCH v2 6/6] thermal: intel: Adjust ops handling during thermal zone registration Rafael J. Wysocki
2024-02-22 11:06 ` 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=13457348.uLZWGnKmhe@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.