mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1 0/2] thermal: testing: Fix two issues related to cleanup
@ 2026-06-17 16:08 Rafael J. Wysocki
  2026-06-17 16:09 ` [PATCH v1 1/2] thermal: testing: zone: Use debugfs_create_file() Rafael J. Wysocki
  2026-06-17 16:10 ` [PATCH v1 2/2] thermal: testing: Flush work items during cleanup Rafael J. Wysocki
  0 siblings, 2 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2026-06-17 16:08 UTC (permalink / raw)
  To: Linux PM; +Cc: LKML, Lukasz Luba, Daniel Lezcano

Hi,

This series fixes two issues in the thermal testing facility, one related to
thermal zone template removal and one related to module unload cleanup.

Thanks!




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v1 1/2] thermal: testing: zone: Use debugfs_create_file()
  2026-06-17 16:08 [PATCH v1 0/2] thermal: testing: Fix two issues related to cleanup Rafael J. Wysocki
@ 2026-06-17 16:09 ` Rafael J. Wysocki
  2026-06-17 16:10 ` [PATCH v1 2/2] thermal: testing: Flush work items during cleanup Rafael J. Wysocki
  1 sibling, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2026-06-17 16:09 UTC (permalink / raw)
  To: Linux PM; +Cc: LKML, Lukasz Luba, Daniel Lezcano

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

Use debugfs_create_file() for creating debugfs files related to thermal
zone templates so that their file operations are properly synchronized
with thermal zone template removal.

Fixes: f6a034f2df42 ("thermal: Introduce a debugfs-based testing facility")
Link: https://sashiko.dev/#/patchset/20260605185212.2491144-1-sam.moelius%40trailofbits.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/thermal/testing/zone.c |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

--- a/drivers/thermal/testing/zone.c
+++ b/drivers/thermal/testing/zone.c
@@ -171,11 +171,11 @@ static void tt_add_tz_work_fn(struct wor
 		return;
 	}
 
-	debugfs_create_file_unsafe("temp", 0600, tt_zone->d_tt_zone, tt_zone,
-				   &tt_zone_tz_temp_attr);
+	debugfs_create_file("temp", 0600, tt_zone->d_tt_zone, tt_zone,
+			    &tt_zone_tz_temp_attr);
 
-	debugfs_create_file_unsafe("init_temp", 0600, tt_zone->d_tt_zone,
-				   &tt_zone->temp, &tt_int_attr);
+	debugfs_create_file("init_temp", 0600, tt_zone->d_tt_zone,
+			    &tt_zone->temp, &tt_int_attr);
 
 	guard(mutex)(&tt_thermal_zones_lock);
 
@@ -315,12 +315,12 @@ static void tt_zone_add_trip_work_fn(str
 	kfree(tt_work);
 
 	snprintf(d_name, TT_MAX_FILE_NAME_LENGTH, "trip_%d_temp", tt_trip->id);
-	debugfs_create_file_unsafe(d_name, 0600, tt_zone->d_tt_zone,
-				   &tt_trip->trip.temperature, &tt_int_attr);
+	debugfs_create_file(d_name, 0600, tt_zone->d_tt_zone,
+			    &tt_trip->trip.temperature, &tt_int_attr);
 
 	snprintf(d_name, TT_MAX_FILE_NAME_LENGTH, "trip_%d_hyst", tt_trip->id);
-	debugfs_create_file_unsafe(d_name, 0600, tt_zone->d_tt_zone,
-				   &tt_trip->trip.hysteresis, &tt_unsigned_int_attr);
+	debugfs_create_file(d_name, 0600, tt_zone->d_tt_zone,
+			    &tt_trip->trip.hysteresis, &tt_unsigned_int_attr);
 
 	tt_put_tt_zone(tt_zone);
 }




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v1 2/2] thermal: testing: Flush work items during cleanup
  2026-06-17 16:08 [PATCH v1 0/2] thermal: testing: Fix two issues related to cleanup Rafael J. Wysocki
  2026-06-17 16:09 ` [PATCH v1 1/2] thermal: testing: zone: Use debugfs_create_file() Rafael J. Wysocki
@ 2026-06-17 16:10 ` Rafael J. Wysocki
  1 sibling, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2026-06-17 16:10 UTC (permalink / raw)
  To: Linux PM; +Cc: LKML, Lukasz Luba, Daniel Lezcano

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

To prevent freed module code from being executed during the thermal
testing module unload, make it add a dedicated workqueue for thermal
testing work items and flush it in thermal_testing_exit().

Fixes: f6a034f2df42 ("thermal: Introduce a debugfs-based testing facility")
Link: https://sashiko.dev/#/patchset/20260605185212.2491144-1-sam.moelius%40trailofbits.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/thermal/testing/command.c         |   16 +++++++++++++---
 drivers/thermal/testing/thermal_testing.h |    8 ++++++++
 drivers/thermal/testing/zone.c            |    7 +++----
 3 files changed, 24 insertions(+), 7 deletions(-)

--- a/drivers/thermal/testing/command.c
+++ b/drivers/thermal/testing/command.c
@@ -86,6 +86,8 @@
 
 #include "thermal_testing.h"
 
+struct workqueue_struct *tt_wq __ro_after_init;
+
 struct dentry *d_testing;
 
 #define TT_COMMAND_SIZE		16
@@ -203,10 +205,17 @@ static const struct file_operations tt_c
 
 static int __init thermal_testing_init(void)
 {
+	tt_wq = alloc_workqueue("thermal_testing", WQ_UNBOUND, 0);
+	if (!tt_wq)
+		return -ENOMEM;
+
 	d_testing = debugfs_create_dir("thermal-testing", NULL);
-	if (!IS_ERR(d_testing))
-		debugfs_create_file("command", 0200, d_testing, NULL,
-				    &tt_command_fops);
+	if (IS_ERR(d_testing)) {
+		destroy_workqueue(tt_wq);
+		return PTR_ERR(d_testing);
+	}
+
+	debugfs_create_file("command", 0200, d_testing, NULL, &tt_command_fops);
 
 	return 0;
 }
@@ -215,6 +224,7 @@ module_init(thermal_testing_init);
 static void __exit thermal_testing_exit(void)
 {
 	debugfs_remove(d_testing);
+	flush_workqueue(tt_wq);
 	tt_zone_cleanup();
 }
 module_exit(thermal_testing_exit);
--- a/drivers/thermal/testing/thermal_testing.h
+++ b/drivers/thermal/testing/thermal_testing.h
@@ -1,4 +1,12 @@
 /* SPDX-License-Identifier: GPL-2.0 */
+#include <linux/workqueue.h>
+
+extern struct workqueue_struct *tt_wq;
+
+static inline void tt_queue_work(struct work_struct *work)
+{
+	queue_work(tt_wq, work);
+}
 
 extern struct dentry *d_testing;
 
--- a/drivers/thermal/testing/zone.c
+++ b/drivers/thermal/testing/zone.c
@@ -13,7 +13,6 @@
 #include <linux/idr.h>
 #include <linux/list.h>
 #include <linux/thermal.h>
-#include <linux/workqueue.h>
 
 #include "thermal_testing.h"
 
@@ -207,7 +206,7 @@ int tt_add_tz(void)
 
 	INIT_WORK(&tt_work->work, tt_add_tz_work_fn);
 	tt_work->tt_zone = no_free_ptr(tt_zone);
-	schedule_work(&(no_free_ptr(tt_work)->work));
+	tt_queue_work(&(no_free_ptr(tt_work)->work));
 
 	return 0;
 }
@@ -269,7 +268,7 @@ int tt_del_tz(const char *arg)
 
 	INIT_WORK(&tt_work->work, tt_del_tz_work_fn);
 	tt_work->tt_zone = tt_zone;
-	schedule_work(&(no_free_ptr(tt_work)->work));
+	tt_queue_work(&(no_free_ptr(tt_work)->work));
 
 	return 0;
 }
@@ -358,7 +357,7 @@ int tt_zone_add_trip(const char *arg)
 	INIT_WORK(&tt_work->work, tt_zone_add_trip_work_fn);
 	tt_work->tt_zone = no_free_ptr(tt_zone);
 	tt_work->tt_trip = no_free_ptr(tt_trip);
-	schedule_work(&(no_free_ptr(tt_work)->work));
+	tt_queue_work(&(no_free_ptr(tt_work)->work));
 
 	return 0;
 }




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-17 16:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-17 16:08 [PATCH v1 0/2] thermal: testing: Fix two issues related to cleanup Rafael J. Wysocki
2026-06-17 16:09 ` [PATCH v1 1/2] thermal: testing: zone: Use debugfs_create_file() Rafael J. Wysocki
2026-06-17 16:10 ` [PATCH v1 2/2] thermal: testing: Flush work items during cleanup Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®