lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220316210946.6935-2-benl@squareup.com>
Date:   Wed, 16 Mar 2022 14:09:44 -0700
From:   Benjamin Li <benl@...areup.com>
To:     Daniel Lezcano <daniel.lezcano@...aro.org>,
        Amit Kucheria <amitk@...nel.org>,
        Thara Gopinath <thara.gopinath@...aro.org>
Cc:     Bjorn Andersson <bjorn.andersson@...aro.org>,
        Zac Crosby <zac@...areup.com>, Benjamin Li <benl@...areup.com>,
        Andy Gross <agross@...nel.org>,
        "Rafael J. Wysocki" <rafael@...nel.org>,
        Zhang Rui <rui.zhang@...el.com>, linux-pm@...r.kernel.org,
        linux-arm-msm@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH 1/2] thermal: thermal_of: add pass-through change_mode to ops struct

Add an optional change_mode method to the ops struct, allowing thermal_of-
based drivers to properly implement disabling of sensors/IRQs. Previously
thermal_core would just disable the polling timer when a zone is disabled,
as thermal_of drivers could not provide a change_mode implementation.

This meant thermal_of drivers supporting interrupt-based updates had to
keep sensors/IRQs enabled at all times, and needed to resort to reading
tzd->mode in their IRQ handler or get_temp implementation to actually stop
updating. This is a waste of resources in IRQ handlers to ignore updates,
and for sensors that can power down it's a waste of power.

Signed-off-by: Benjamin Li <benl@...areup.com>
---
 drivers/thermal/thermal_of.c | 14 ++++++++++++++
 include/linux/thermal.h      |  2 ++
 2 files changed, 16 insertions(+)

diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index 9233f7e74454..a69ec39780a7 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -106,6 +106,17 @@ static int of_thermal_set_trips(struct thermal_zone_device *tz,
 	return data->ops->set_trips(data->sensor_data, low, high);
 }
 
+static int of_thermal_change_mode(struct thermal_zone_device *tz,
+				enum thermal_device_mode mode)
+{
+	struct __thermal_zone *data = tz->devdata;
+
+	if (!data->ops || !data->ops->change_mode)
+		return -EINVAL;
+
+	return data->ops->change_mode(data->sensor_data, mode);
+}
+
 /**
  * of_thermal_get_ntrips - function to export number of available trip
  *			   points.
@@ -405,6 +416,9 @@ thermal_zone_of_add_sensor(struct device_node *zone,
 	if (ops->set_trips)
 		tzd->ops->set_trips = of_thermal_set_trips;
 
+	if (ops->change_mode)
+		tzd->ops->change_mode = of_thermal_change_mode;
+
 	if (ops->set_emul_temp)
 		tzd->ops->set_emul_temp = of_thermal_set_emul_temp;
 
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index c314893970b3..469a1664f1ed 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -295,6 +295,7 @@ struct thermal_zone_params {
  * @set_trips: a pointer to a function that sets a temperature window. When
  *	       this window is left the driver must inform the thermal core via
  *	       thermal_zone_device_update.
+ * @change_mode: a pointer to a function that enables/disables reporting.
  * @set_emul_temp: a pointer to a function that sets sensor emulated
  *		   temperature.
  * @set_trip_temp: a pointer to a function that sets the trip temperature on
@@ -304,6 +305,7 @@ struct thermal_zone_of_device_ops {
 	int (*get_temp)(void *, int *);
 	int (*get_trend)(void *, int, enum thermal_trend *);
 	int (*set_trips)(void *, int, int);
+	int (*change_mode)(void *, enum thermal_device_mode);
 	int (*set_emul_temp)(void *, int);
 	int (*set_trip_temp)(void *, int, int);
 };
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ