Skip to contentSkip to conversation

thermal: Fix Critical and High issues reported by Sashiko

PATCH Applied Lee Jones 6 participants 21 messages Dec 3 – Dec 4

Subsystems (7)
lore
Share & tools
lore

Lee Jones

author
#0 lore raw

cover thermal: Fix Critical and High issues reported by Sashiko

These issues were reported by Sashiko.

Cc "Niklas Söderlund" <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Amit Kucheria <[email protected]>
Cc Aubrey Li <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc Eduardo Valentin <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Frank Li <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Jacob Pan <[email protected]>
Cc Jez Ng <[email protected]>
Cc Kuninori Morimoto <[email protected]>
Cc Len Brown <[email protected]>
Cc Lina Iyer <[email protected]>
Cc Lukasz Luba <[email protected]>
Cc Magnus Damm <[email protected]>
Cc Matthew Garrett <[email protected]>
Cc Neil Horman <[email protected]>
Cc Peng Fan <[email protected]>
Cc Pengfei Li <[email protected]>
Cc Pengutronix Kernel Team <[email protected]>
Cc Priyansh Jain <[email protected]>
Cc Rajendra Nayak <[email protected]>
Cc Ricardo Neri <[email protected]>
Cc Rob Herring <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Thara Gopinath <[email protected]>
Cc Zhang Rui <[email protected]>

Lee Jones (10):
thermal: intel: hfi: Pass byte size to alloc_pages_exact() and
free_pages_exact()
thermal: intel: hfi: Publish hfi_instance only after successful
initialisation
thermal: int3400: Clean up ODVP attributes after unregistering thermal
zone
thermal/drivers/qcom/tsens-v1: Validate sensor count before legacy
calibration
thermal/drivers/qcom/tsens: Bound sensor initialisation by num_sensors thermal/drivers/rcar: Free IRQs before cancelling delayed work on
remove
thermal/drivers/imx91: Acquire runtime PM reference in

    imx91_tmu_get_temp()
  tools/thermal/tmon: Open log file with O_NOFOLLOW before validating
    and truncating
  thermal/drivers/qcom/tsens: Drop __init from ops init callbacks
  thermal/drivers/imx91: Use pm_runtime_resume_and_get() in
    imx91_tmu_change_mode()
 drivers/thermal/imx91_thermal.c               |  9 ++-
 .../intel/int340x_thermal/int3400_thermal.c   |  3 +-
 drivers/thermal/intel/intel_hfi.c             | 15 ++--
 drivers/thermal/qcom/tsens-v0_1.c             | 73 ++++++++-----------
 drivers/thermal/qcom/tsens-v1.c               | 60 ++++++---------
 drivers/thermal/qcom/tsens-v2.c               |  2 +-
 drivers/thermal/qcom/tsens.c                  |  2 +-
 drivers/thermal/renesas/rcar_thermal.c        | 18 ++++-
 tools/thermal/tmon/tmon.c                     | 36 ++++++---
 9 files changed, 110 insertions(+), 108 deletions(-)
Signature · 1 line
2.56.1.911.g883d8bcb20-goog
author
#1 lore raw

PATCH 1/10 thermal: intel: hfi: Pass byte size to alloc_pages_exact() and free_pages_exact()

intel_hfi_online() passes hfi_features.nr_table_pages (a page count) to alloc_pages_exact() and free_pages_exact() instead of the table size in bytes. When CPUID leaf 6 enumerates more than one HFI table page, only a single page is allocated, allowing hardware writes via MSR_IA32_HW_FEEDBACK_PTR to corrupt adjacent physical memory and intel_hfi_process_event() to read out of bounds.

Convert the page count to bytes using hfi_features.nr_table_pages << PAGE_SHIFT, matching the local_table allocation.

Fixes 2d74e6319abe ("thermal: intel: hfi: Handle CPU hotplug events")
---
 drivers/thermal/intel/intel_hfi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/thermal/intel/intel_hfi.c +3 -2
index 8ff094eccbaf..19355679c1df 100644
@@ -470,7 +470,7 @@ void intel_hfi_online(unsigned int cpu)
 	 * even after having been reprogrammed. Keep using the same pages. Do
 	 * not free them.
 	 */
-	hfi_instance->hw_table = alloc_pages_exact(hfi_features.nr_table_pages,
+	hfi_instance->hw_table = alloc_pages_exact(hfi_features.nr_table_pages << PAGE_SHIFT,
 						   GFP_KERNEL | __GFP_ZERO);
 	if (!hfi_instance->hw_table)
 		goto unlock;
@@ -508,7 +508,8 @@ void intel_hfi_online(unsigned int cpu)
 	return;
 
 free_hw_table:
-	free_pages_exact(hfi_instance->hw_table, hfi_features.nr_table_pages);
+	free_pages_exact(hfi_instance->hw_table,
+			 hfi_features.nr_table_pages << PAGE_SHIFT);
 	goto unlock;
 }
 
Signature · 1 line
2.56.1.911.g883d8bcb20-goog
maintainer Applied
#2 lore raw

Re: [PATCH 01/10] thermal: intel: hfi: Pass byte size to alloc_pages_exact() and free_pages_exact()

Quoted 33 lines · Lee Jones

intel_hfi_online() passes hfi_features.nr_table_pages (a page count) to alloc_pages_exact() and free_pages_exact() instead of the table size in bytes. When CPUID leaf 6 enumerates more than one HFI table page, only a single page is allocated, allowing hardware writes via MSR_IA32_HW_FEEDBACK_PTR to corrupt adjacent physical memory and intel_hfi_process_event() to read out of bounds.

Convert the page count to bytes using hfi_features.nr_table_pages << PAGE_SHIFT, matching the local_table allocation.

Fixes 2d74e6319abe ("thermal: intel: hfi: Handle CPU hotplug events")
---
 drivers/thermal/intel/intel_hfi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/thermal/intel/intel_hfi.c +1 -1
index 8ff094eccbaf..19355679c1df 100644
@@ -470,7 +470,7 @@ void intel_hfi_online(unsigned int cpu)
         * even after having been reprogrammed. Keep using the same pages. Do
         * not free them.
         */
-       hfi_instance->hw_table = alloc_pages_exact(hfi_features.nr_table_pages,
+       hfi_instance->hw_table = alloc_pages_exact(hfi_features.nr_table_pages << PAGE_SHIFT,
                                                   GFP_KERNEL | __GFP_ZERO);
        if (!hfi_instance->hw_table)
                goto unlock;

drivers/thermal/intel/intel_hfi.c void intel_hfi_online(unsigned int cpu)

Quoted 10 lines
drivers/thermal/intel/intel_hfi.c +2 -2
@@ -508,7 +508,8 @@ void intel_hfi_online(unsigned int cpu)
        return;
 
 free_hw_table:
-       free_pages_exact(hfi_instance->hw_table, hfi_features.nr_table_pages);
+       free_pages_exact(hfi_instance->hw_table,
+                        hfi_features.nr_table_pages << PAGE_SHIFT);
        goto unlock;
 }
 
--

Applied as 7.4-rc material, thanks!

author
#3 lore raw

PATCH 2/10 thermal: intel: hfi: Publish hfi_instance only after successful initialisation

In reply to Lee Jones

intel_hfi_online() stores hfi_instance in per-CPU hfi_cpu_info before allocating hw_table and local_table, and fails to clear hfi_instance->hw_table after free_pages_exact() when local_table allocation fails. Because the thermal LVT is still unmasked, intel_hfi_process_event() and hfi_syscore_resume() can then dereference NULL or freed pointers.

Defer publishing info->hfi_instance until the instance has been fully initialised, clear hfi_instance->hw_table after freeing it on error, and check hfi_instance for NULL in hfi_syscore_resume().

Fixes 2d74e6319abe ("thermal: intel: hfi: Handle CPU hotplug events")
---
 drivers/thermal/intel/intel_hfi.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/thermal/intel/intel_hfi.c +4 -6
index 19355679c1df..79d06b510fdc 100644
@@ -435,10 +435,7 @@ void intel_hfi_online(unsigned int cpu)
 	if (!hfi_instances)
 		return;
 
-	/*
-	 * Link @cpu to the HFI instance of its package. It does not
-	 * matter whether the instance has been initialized.
-	 */
+	/* Find the HFI instance of @cpu's package. */
 	info = &per_cpu(hfi_cpu_info, cpu);
 	pkg_id = topology_logical_package_id(cpu);
 	hfi_instance = info->hfi_instance;
@@ -447,7 +444,6 @@ void intel_hfi_online(unsigned int cpu)
 			return;
 
 		hfi_instance = &hfi_instances[pkg_id];
-		info->hfi_instance = hfi_instance;
 	}
 
 	init_hfi_cpu_index(info);
@@ -491,6 +487,7 @@ void intel_hfi_online(unsigned int cpu)
 	raw_spin_lock_init(&hfi_instance->event_lock);
 
 enable:
+	info->hfi_instance = hfi_instance;
 	cpumask_set_cpu(cpu, hfi_instance->cpus);
 
 	/*
@@ -510,6 +507,7 @@ void intel_hfi_online(unsigned int cpu)
 free_hw_table:
 	free_pages_exact(hfi_instance->hw_table,
 			 hfi_features.nr_table_pages << PAGE_SHIFT);
+	hfi_instance->hw_table = NULL;
 	goto unlock;
 }
 
@@ -621,7 +619,7 @@ static void hfi_syscore_resume(void *data)
 	struct hfi_instance *hfi_instance = info->hfi_instance;
 
 	/* No locking needed. There is no concurrency with CPU online. */
-	if (hfi_clients_nr > 0)
+	if (hfi_instance && hfi_clients_nr > 0)
 		hfi_enable_instance(hfi_instance);
 }
 
Signature · 1 line
2.56.1.911.g883d8bcb20-goog
#4 lore raw

Re: [PATCH 02/10] thermal: intel: hfi: Publish hfi_instance only after successful initialisation

Quoted 8 lines · Lee Jones

intel_hfi_online() stores hfi_instance in per-CPU hfi_cpu_info before allocating hw_table and local_table, and fails to clear hfi_instance->hw_table after free_pages_exact() when local_table allocation fails. Because the thermal LVT is still unmasked, intel_hfi_process_event() and hfi_syscore_resume() can then dereference NULL or freed pointers.

Quoted 8 lines

Defer publishing info->hfi_instance until the instance has been fully initialised, clear hfi_instance->hw_table after freeing it on error, and check hfi_instance for NULL in hfi_syscore_resume().

Fixes 2d74e6319abe ("thermal: intel: hfi: Handle CPU hotplug events")

Sashiko complains about this one:

https://sashiko.dev/#/patchset/20261203195529.3063246-1-lee%40kernel.org

and legitimately so AFAICS.

Quoted 56 lines
---
 drivers/thermal/intel/intel_hfi.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/thermal/intel/intel_hfi.c +4 -7
index 19355679c1df..79d06b510fdc 100644
@@ -435,10 +435,7 @@ void intel_hfi_online(unsigned int cpu)
        if (!hfi_instances)
                return;
 
-       /*
-        * Link @cpu to the HFI instance of its package. It does not
-        * matter whether the instance has been initialized.
-        */
+       /* Find the HFI instance of @cpu's package. */
        info = &per_cpu(hfi_cpu_info, cpu);
        pkg_id = topology_logical_package_id(cpu);
        hfi_instance = info->hfi_instance;
@@ -447,7 +444,6 @@ void intel_hfi_online(unsigned int cpu)
                        return;
 
                hfi_instance = &hfi_instances[pkg_id];
-               info->hfi_instance = hfi_instance;
        }
 
        init_hfi_cpu_index(info);
@@ -491,6 +487,7 @@ void intel_hfi_online(unsigned int cpu)
        raw_spin_lock_init(&hfi_instance->event_lock);
 
 enable:
+       info->hfi_instance = hfi_instance;
        cpumask_set_cpu(cpu, hfi_instance->cpus);
 
        /*
@@ -510,6 +507,7 @@ void intel_hfi_online(unsigned int cpu)
 free_hw_table:
        free_pages_exact(hfi_instance->hw_table,
                         hfi_features.nr_table_pages << PAGE_SHIFT);
+       hfi_instance->hw_table = NULL;
        goto unlock;
 }
 
@@ -621,7 +619,7 @@ static void hfi_syscore_resume(void *data)
        struct hfi_instance *hfi_instance = info->hfi_instance;
 
        /* No locking needed. There is no concurrency with CPU online. */
-       if (hfi_clients_nr > 0)
+       if (hfi_instance && hfi_clients_nr > 0)
                hfi_enable_instance(hfi_instance);
 }
 
--

2.56.1.911.g883d8bcb20-goog

author
#5 lore raw

PATCH 3/10 thermal: int3400: Clean up ODVP attributes after unregistering thermal zone

In reply to Lee Jones

int3400_thermal_remove() calls cleanup_odvp() before thermal_zone_device_unregister(). A concurrent sysfs mode write can still invoke int3400_thermal_change_mode() -> evaluate_odvp(), recreating the odvpN sysfs attributes before priv is freed and leaving dangling attributes that trigger a use-after-free in odvp_show().

Move cleanup_odvp() after thermal_zone_device_unregister(), matching the probe error path.

Fixes 006f006f1e5c ("thermal/int340x_thermal: Export OEM vendor variables")
---
 drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/thermal/intel/int340x_thermal/int3400_thermal.c +1 -2
index 5d70301d4a3d..7cd533414973 100644
@@ -668,8 +668,6 @@ static void int3400_thermal_remove(struct platform_device *pdev)
 			priv->adev->handle, ACPI_DEVICE_NOTIFY,
 			int3400_notify);
 
-	cleanup_odvp(priv);
-
 	if (!priv->rel_misc_dev_res)
 		acpi_thermal_rel_misc_device_remove(priv->adev->handle);
 
@@ -678,6 +676,7 @@ static void int3400_thermal_remove(struct platform_device *pdev)
 	sysfs_remove_group(&pdev->dev.kobj, &uuid_attribute_group);
 	sysfs_remove_group(&pdev->dev.kobj, &imok_attribute_group);
 	thermal_zone_device_unregister(priv->thermal);
+	cleanup_odvp(priv);
 	kfree(priv->data_vault);
 	kfree(priv->trts);
 	kfree(priv->arts);
Signature · 1 line
2.56.1.911.g883d8bcb20-goog
maintainer Applied
#6 lore raw

Re: [PATCH 03/10] thermal: int3400: Clean up ODVP attributes after unregistering thermal zone

Quoted 32 lines · Lee Jones

int3400_thermal_remove() calls cleanup_odvp() before thermal_zone_device_unregister(). A concurrent sysfs mode write can still invoke int3400_thermal_change_mode() -> evaluate_odvp(), recreating the odvpN sysfs attributes before priv is freed and leaving dangling attributes that trigger a use-after-free in odvp_show().

Move cleanup_odvp() after thermal_zone_device_unregister(), matching the probe error path.

Fixes 006f006f1e5c ("thermal/int340x_thermal: Export OEM vendor variables")
---
 drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/thermal/intel/int340x_thermal/int3400_thermal.c +0 -2
index 5d70301d4a3d..7cd533414973 100644
@@ -668,8 +668,6 @@ static void int3400_thermal_remove(struct platform_device *pdev)
                        priv->adev->handle, ACPI_DEVICE_NOTIFY,
                        int3400_notify);
 
-       cleanup_odvp(priv);
-
        if (!priv->rel_misc_dev_res)
                acpi_thermal_rel_misc_device_remove(priv->adev->handle);
 

drivers/thermal/intel/int340x_thermal/int3400_thermal.c static void int3400_thermal_remove(struct platform_device *pdev)

Quoted 8 lines
drivers/thermal/intel/int340x_thermal/int3400_thermal.c +1 -1
@@ -678,6 +676,7 @@ static void int3400_thermal_remove(struct platform_device *pdev)
        sysfs_remove_group(&pdev->dev.kobj, &uuid_attribute_group);
        sysfs_remove_group(&pdev->dev.kobj, &imok_attribute_group);
        thermal_zone_device_unregister(priv->thermal);
+       cleanup_odvp(priv);
        kfree(priv->data_vault);
        kfree(priv->trts);
        kfree(priv->arts);
--

Applied as 7.4-rc material, thanks!

author
#7 lore raw

PATCH 4/10 thermal/drivers/qcom/tsens-v1: Validate sensor count before legacy calibration

In reply to Lee Jones

data_tsens_v1 allows up to 11 sensors via tsens_v1_feat.max_sensors, whereas calibrate_v1() passes 10-element stack arrays p1[10] and p2[10] and the 10-entry tsens_qcs404_nvmem table to tsens_read_calibration_legacy() and compute_intercept_slope(). With 11 sensors configured, both read past tsens_qcs404_nvmem.sp and overflow p1 and p2 on the stack.

Reject legacy calibration in calibrate_v1() when priv->num_sensors exceeds ARRAY_SIZE(p1).

Fixes e8c24c6f5d1c ("drivers: thermal: tsens: Add generic support for TSENS v1 IP")
---
 drivers/thermal/qcom/tsens-v1.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/thermal/qcom/tsens-v1.c +5 -2
index 7bda8e6087c4..12fe0fbefad4 100644
@@ -49,8 +49,11 @@ static int calibrate_v1(struct tsens_priv *priv)
 	int mode, ret;
 
 	ret = tsens_calibrate_common(priv);
-	if (!ret)
-		return 0;
+	if (!ret || ret == -EPROBE_DEFER)
+		return ret;
+
+	if (priv->num_sensors > ARRAY_SIZE(p1))
+		return -EINVAL;
 
 	qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
 	if (IS_ERR(qfprom_cdata))
Signature · 1 line
2.56.1.911.g883d8bcb20-goog
author
#8 lore raw

PATCH 5/10 thermal/drivers/qcom/tsens: Bound sensor initialisation by num_sensors

In reply to Lee Jones

tsens_probe() allocates priv->sensor[] with priv->num_sensors entries, which may be smaller than the SoC default when #qcom,sensors is set in Device Tree. The per-SoC init helpers for 8226, 8909, 8939, 9607, 8952, and 8956 index priv->sensor[] with hardcoded constants up to the SoC maximum, writing past the end of the heap allocation when fewer sensors are configured.

Replace the hardcoded assignments with static lookup tables and bound each loop by priv->num_sensors.

Fixes 6d7c70d1cd65 ("thermal: qcom: tsens: Allow number of sensors to come from DT")
---
 drivers/thermal/qcom/tsens-v0_1.c | 67 ++++++++++++-------------------
 drivers/thermal/qcom/tsens-v1.c   | 49 +++++++---------------
 2 files changed, 41 insertions(+), 75 deletions(-)
drivers/thermal/qcom/tsens-v0_1.c +26 -41
index 32d2d3e33287..468da9e513e2 100644
@@ -209,69 +209,54 @@ static int calibrate_8974(struct tsens_priv *priv)
 
 static int __init init_8226(struct tsens_priv *priv)
 {
-	priv->sensor[0].slope = 2901;
-	priv->sensor[1].slope = 2846;
-	priv->sensor[2].slope = 3038;
-	priv->sensor[3].slope = 2955;
-	priv->sensor[4].slope = 2901;
-	priv->sensor[5].slope = 2846;
+	static const u32 slopes[] = { 2901, 2846, 3038, 2955, 2901, 2846 };
+
+	for (unsigned int i = 0; i < priv->num_sensors && i < ARRAY_SIZE(slopes); i++)
+		priv->sensor[i].slope = slopes[i];
 
 	return init_common(priv);
 }
 
 static int __init init_8909(struct tsens_priv *priv)
 {
-	int i;
+	static const int p1_offsets[] = { 0, -10, 0, -9, -8 };
+	static const int p2_offsets[] = { 0, -6, 0, -9, -10 };
 
-	for (i = 0; i < priv->num_sensors; ++i)
+	for (unsigned int i = 0; i < priv->num_sensors; ++i)
 		priv->sensor[i].slope = 3000;
 
-	priv->sensor[0].p1_calib_offset = 0;
-	priv->sensor[0].p2_calib_offset = 0;
-	priv->sensor[1].p1_calib_offset = -10;
-	priv->sensor[1].p2_calib_offset = -6;
-	priv->sensor[2].p1_calib_offset = 0;
-	priv->sensor[2].p2_calib_offset = 0;
-	priv->sensor[3].p1_calib_offset = -9;
-	priv->sensor[3].p2_calib_offset = -9;
-	priv->sensor[4].p1_calib_offset = -8;
-	priv->sensor[4].p2_calib_offset = -10;
+	for (unsigned int i = 0; i < priv->num_sensors && i < ARRAY_SIZE(p1_offsets); i++) {
+		priv->sensor[i].p1_calib_offset = p1_offsets[i];
+		priv->sensor[i].p2_calib_offset = p2_offsets[i];
+	}
 
 	return init_common(priv);
 }
 
-static int __init init_8939(struct tsens_priv *priv) {
-	priv->sensor[0].slope = 2911;
-	priv->sensor[1].slope = 2789;
-	priv->sensor[2].slope = 2906;
-	priv->sensor[3].slope = 2763;
-	priv->sensor[4].slope = 2922;
-	priv->sensor[5].slope = 2867;
-	priv->sensor[6].slope = 2833;
-	priv->sensor[7].slope = 2838;
-	priv->sensor[8].slope = 2840;
-	/* priv->sensor[9].slope = 2852; */
+static int __init init_8939(struct tsens_priv *priv)
+{
+	static const u32 slopes[] = {
+		2911, 2789, 2906, 2763, 2922, 2867, 2833, 2838, 2840,
+	};
+
+	for (unsigned int i = 0; i < priv->num_sensors && i < ARRAY_SIZE(slopes); i++)
+		priv->sensor[i].slope = slopes[i];
 
 	return init_common(priv);
 }
 
 static int __init init_9607(struct tsens_priv *priv)
 {
-	int i;
+	static const int p1_offsets[] = { 1, -4, 4, -3, -4 };
+	static const int p2_offsets[] = { 1, -2, 8, -5, -4 };
 
-	for (i = 0; i < priv->num_sensors; ++i)
+	for (unsigned int i = 0; i < priv->num_sensors; ++i)
 		priv->sensor[i].slope = 3000;
 
-	priv->sensor[0].p1_calib_offset = 1;
-	priv->sensor[0].p2_calib_offset = 1;
-	priv->sensor[1].p1_calib_offset = -4;
-	priv->sensor[1].p2_calib_offset = -2;
-	priv->sensor[2].p1_calib_offset = 4;
-	priv->sensor[2].p2_calib_offset = 8;
-	priv->sensor[3].p1_calib_offset = -3;
-	priv->sensor[3].p2_calib_offset = -5;
-	priv->sensor[4].p1_calib_offset = -4;
-	priv->sensor[4].p2_calib_offset = -4;
+	for (unsigned int i = 0; i < priv->num_sensors && i < ARRAY_SIZE(p1_offsets); i++) {
+		priv->sensor[i].p1_calib_offset = p1_offsets[i];
+		priv->sensor[i].p2_calib_offset = p2_offsets[i];
+	}
 
 	return init_common(priv);
 }
drivers/thermal/qcom/tsens-v1.c +15 -34

59 lines not on this page · raw message

Signature · 1 line
2.56.1.911.g883d8bcb20-goog
author
#9 lore raw

PATCH 6/10 thermal/drivers/rcar: Free IRQs before cancelling delayed work on remove

In reply to Lee Jones

rcar_thermal_probe() requests shared IRQs via devm_request_irq(), so rcar_thermal_irq() remains active during rcar_thermal_remove() until devres teardown runs after the remove callback returns. Because rcar_thermal_irq() drops common->lock before queueing priv->work, an in-flight interrupt can re-queue the delayed work after cancel_delayed_work_sync() has returned, triggering a use-after-free after devres frees priv.

Record the requested IRQ numbers in struct rcar_thermal_common and explicitly release them with devm_free_irq() in rcar_thermal_remove() before cancelling delayed work, disabling hardware interrupts, and dropping runtime PM.

Fixes e0a5172e9eec ("thermal: rcar: add interrupt support")
---
 drivers/thermal/renesas/rcar_thermal.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
drivers/thermal/renesas/rcar_thermal.c +17 -1
index af6d09a75bb6..3e02b16084b4 100644
@@ -39,11 +39,15 @@
 /* THSSR */
 #define CTEMP	0x3f
 
+#define RCAR_THERMAL_MAX_IRQS	2
+
 struct rcar_thermal_common {
 	void __iomem *base;
 	struct device *dev;
 	struct list_head head;
 	spinlock_t lock;
+	int irqs[RCAR_THERMAL_MAX_IRQS];
+	unsigned int nirqs;
 };
 
 struct rcar_thermal_chip {
@@ -377,9 +381,15 @@ static void rcar_thermal_remove(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct rcar_thermal_priv *priv;
 
-	rcar_thermal_for_each_priv(priv, common) {
+	rcar_thermal_for_each_priv(priv, common)
 		rcar_thermal_irq_disable(priv);
+
+	for (unsigned int i = 0; i < common->nirqs; i++)
+		devm_free_irq(dev, common->irqs[i], common);
+
+	rcar_thermal_for_each_priv(priv, common) {
 		cancel_delayed_work_sync(&priv->work);
+		rcar_thermal_irq_disable(priv);
 		if (priv->chip->use_of_thermal)
 			thermal_remove_hwmon_sysfs(priv->zone);
 		else
@@ -444,10 +454,16 @@ static int rcar_thermal_probe(struct platform_device *pdev)
 			idle = 0; /* polling delay is not needed */
 		}
 
+		if (common->nirqs >= RCAR_THERMAL_MAX_IRQS) {
+			ret = -EINVAL;
+			goto error_unregister;
+		}
+
 		ret = devm_request_irq(dev, irq, rcar_thermal_irq,
 				       IRQF_SHARED, dev_name(dev), common);
 		if (ret)
 			goto error_unregister;
+		common->irqs[common->nirqs++] = irq;
 
 		/* update ENR bits */
 		if (chip->irq_per_ch)
Signature · 1 line
2.56.1.911.g883d8bcb20-goog
#10 lore raw

Re: [PATCH 06/10] thermal/drivers/rcar: Free IRQs before cancelling delayed work on remove

Hi Lee,

Thanks for your work.

Quoted 42 lines · Lee Jones

rcar_thermal_probe() requests shared IRQs via devm_request_irq(), so rcar_thermal_irq() remains active during rcar_thermal_remove() until devres teardown runs after the remove callback returns. Because rcar_thermal_irq() drops common->lock before queueing priv->work, an in-flight interrupt can re-queue the delayed work after cancel_delayed_work_sync() has returned, triggering a use-after-free after devres frees priv.

Record the requested IRQ numbers in struct rcar_thermal_common and explicitly release them with devm_free_irq() in rcar_thermal_remove() before cancelling delayed work, disabling hardware interrupts, and dropping runtime PM.

Fixes e0a5172e9eec ("thermal: rcar: add interrupt support")
---
 drivers/thermal/renesas/rcar_thermal.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
drivers/thermal/renesas/rcar_thermal.c +4 -0
index af6d09a75bb6..3e02b16084b4 100644
@@ -39,11 +39,15 @@
 /* THSSR */
 #define CTEMP	0x3f
 
+#define RCAR_THERMAL_MAX_IRQS	2
+
 struct rcar_thermal_common {
 	void __iomem *base;
 	struct device *dev;
 	struct list_head head;
 	spinlock_t lock;
+	int irqs[RCAR_THERMAL_MAX_IRQS];
+	unsigned int nirqs;
 };
 
 struct rcar_thermal_chip {

drivers/thermal/renesas/rcar_thermal.c static void rcar_thermal_remove(struct platform_device *pdev) · line 382

Quoted 2 lines
drivers/thermal/renesas/rcar_thermal.c +0 -0
@@ -377,9 +381,15 @@ static void rcar_thermal_remove(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct rcar_thermal_priv *priv;

Would not a call to disable_delayed_work_sync() here complete/cancel any in-flight top-half of the interrupt handler and prevent any new ones from being scheduled?

Then calling rcar_thermal_irq_disable() would prevent any new bottom half interrupts and we could led devres clean up?

There is some work in progress for this issue already [1], but I'm not sure Yaohan was planing to continue it as he had no hardware to test on. Adding him to CC.

1. https://lore.kernel.org/linux-renesas-soc/[email protected]/

Quoted 34 lines
drivers/thermal/renesas/rcar_thermal.c +13 -1
-	rcar_thermal_for_each_priv(priv, common) {
+	rcar_thermal_for_each_priv(priv, common)
 		rcar_thermal_irq_disable(priv);
+
+	for (unsigned int i = 0; i < common->nirqs; i++)
+		devm_free_irq(dev, common->irqs[i], common);
+
+	rcar_thermal_for_each_priv(priv, common) {
 		cancel_delayed_work_sync(&priv->work);
+		rcar_thermal_irq_disable(priv);
 		if (priv->chip->use_of_thermal)
 			thermal_remove_hwmon_sysfs(priv->zone);
 		else
@@ -444,10 +454,16 @@ static int rcar_thermal_probe(struct platform_device *pdev)
 			idle = 0; /* polling delay is not needed */
 		}
 
+		if (common->nirqs >= RCAR_THERMAL_MAX_IRQS) {
+			ret = -EINVAL;
+			goto error_unregister;
+		}
+
 		ret = devm_request_irq(dev, irq, rcar_thermal_irq,
 				       IRQF_SHARED, dev_name(dev), common);
 		if (ret)
 			goto error_unregister;
+		common->irqs[common->nirqs++] = irq;
 
 		/* update ENR bits */
 		if (chip->irq_per_ch)
Signature · 1 line
2.56.1.911.g883d8bcb20-goog
Signature · 2 lines
Kind Regards,
Niklas Söderlund
author
#11 lore raw

PATCH 7/10 thermal/drivers/imx91: Acquire runtime PM reference in imx91_tmu_get_temp()

In reply to Lee Jones

The thermal core allows get_temp() to be called via sysfs even when the thermal zone has been disabled and imx91_tmu_change_mode() has dropped the runtime PM reference, gating the TMU clock. Reading IMX91_TMU_DATA0 in imx91_tmu_get_temp() while the clock is disabled causes an unclocked register access.

Wrap the register read in imx91_tmu_get_temp() with pm_runtime_resume_and_get() and pm_runtime_put().

Fixes c411d8bf0699 ("thermal/drivers/imx91: Add support for i.MX91 thermal monitoring unit")
---
 drivers/thermal/imx91_thermal.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/thermal/imx91_thermal.c +7 -0
index 6d0aba992244..c3a72df665a8 100644
@@ -110,11 +110,18 @@ static int imx91_tmu_get_temp(struct thermal_zone_device *tz, int *temp)
 {
 	struct imx91_tmu *tmu = thermal_zone_device_priv(tz);
 	s16 data;
+	int ret;
+
+	ret = pm_runtime_resume_and_get(tmu->dev);
+	if (ret < 0)
+		return ret;
 
 	/* DATA0 is 16bit signed number */
 	data = readw_relaxed(tmu->base + IMX91_TMU_DATA0);
 	*temp = imx91_tmu_to_mcelsius(data);
 
+	pm_runtime_put(tmu->dev);
+
 	return 0;
 }
 
Signature · 1 line
2.56.1.911.g883d8bcb20-goog
#12 lore raw

Re: [PATCH 07/10] thermal/drivers/imx91: Acquire runtime PM reference in imx91_tmu_get_temp()

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] thermal/imx91: imx91_tmu_get_temp() reads stale DATA0 when zone is disabled --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] thermal/imx91: imx91_tmu_get_temp() reads stale DATA0 when zone is disabled
--

commit 6c2200e167fb50e996061c6b352e037ffc580431
Author: Lee Jones <[email protected]>

thermal/drivers/imx91: Acquire runtime PM reference in imx91_tmu_get_temp()

This commit wraps the IMX91_TMU_DATA0 register read in imx91_tmu_get_temp() with pm_runtime_resume_and_get() and pm_runtime_put() to avoid unclocked register access when the thermal zone is disabled.

Quoted 12 lines
drivers/thermal/imx91_thermal.c +4 -0
index 6d0aba992244b..c3a72df665a81 100644
@@ -110,11 +110,18 @@ static int imx91_tmu_get_temp(struct thermal_zone_device *tz, int *temp)
 {
 	struct imx91_tmu *tmu = thermal_zone_device_priv(tz);
 	s16 data;
+	int ret;
+
+	ret = pm_runtime_resume_and_get(tmu->dev);
+	if (ret < 0)

drivers/thermal/imx91_thermal.c static int imx91_tmu_get_temp(struct thermal_zone_device *tz, int *temp) · line 126

Quoted 10 lines
drivers/thermal/imx91_thermal.c +3 -0
+		return ret;
 
 	/* DATA0 is 16bit signed number */
 	data = readw_relaxed(tmu->base + IMX91_TMU_DATA0);
 	*temp = imx91_tmu_to_mcelsius(data);
 
+	pm_runtime_put(tmu->dev);
+
 	return 0;
 }

[Severity: Medium]
Can this return stale temperature data from IMX91_TMU_DATA0 when the thermal zone is disabled?

Disabling the zone in imx91_tmu_change_mode() stops measurements via imx91_tmu_start(tmu, false) before calling pm_runtime_put(). imx91_tmu_runtime_resume() only re-enables the clock and IMX91_TMU_CTRL1_EN, without starting a measurement or waiting for a conversion to complete.

Reading sysfs temp while disabled then succeeds with whatever stale or zero value sits in IMX91_TMU_DATA0. Should imx91_tmu_get_temp() return -EAGAIN when the zone is disabled, or start a conversion and wait for data ready before reading?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#13 lore raw

Re: [PATCH 07/10] thermal/drivers/imx91: Acquire runtime PM reference in imx91_tmu_get_temp()

Quoted 47 lines · On Thu, Dec 03, 2026 at 08:11:17PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] thermal/imx91: imx91_tmu_get_temp() reads stale DATA0 when zone is disabled
--

commit 6c2200e167fb50e996061c6b352e037ffc580431
Author: Lee Jones <[email protected]>

thermal/drivers/imx91: Acquire runtime PM reference in imx91_tmu_get_temp()

This commit wraps the IMX91_TMU_DATA0 register read in imx91_tmu_get_temp() with pm_runtime_resume_and_get() and pm_runtime_put() to avoid unclocked register access when the thermal zone is disabled.

Quoted 12 lines
drivers/thermal/imx91_thermal.c +4 -0
index 6d0aba992244b..c3a72df665a81 100644
@@ -110,11 +110,18 @@ static int imx91_tmu_get_temp(struct thermal_zone_device *tz, int *temp)
 {
 	struct imx91_tmu *tmu = thermal_zone_device_priv(tz);
 	s16 data;
+	int ret;
+
+	ret = pm_runtime_resume_and_get(tmu->dev);
+	if (ret < 0)

drivers/thermal/imx91_thermal.c static int imx91_tmu_get_temp(struct thermal_zone_device *tz, int *temp) · line 126

Quoted 10 lines
drivers/thermal/imx91_thermal.c +3 -0
+		return ret;
 
 	/* DATA0 is 16bit signed number */
 	data = readw_relaxed(tmu->base + IMX91_TMU_DATA0);
 	*temp = imx91_tmu_to_mcelsius(data);
 
+	pm_runtime_put(tmu->dev);
+
 	return 0;
 }

[Severity: Medium]
Can this return stale temperature data from IMX91_TMU_DATA0 when the thermal zone is disabled?

Disabling the zone in imx91_tmu_change_mode() stops measurements via imx91_tmu_start(tmu, false) before calling pm_runtime_put(). imx91_tmu_runtime_resume() only re-enables the clock and IMX91_TMU_CTRL1_EN, without starting a measurement or waiting for a conversion to complete.

Quoted 4 lines

Reading sysfs temp while disabled then succeeds with whatever stale or zero value sits in IMX91_TMU_DATA0. Should imx91_tmu_get_temp() return -EAGAIN when the zone is disabled, or start a conversion and wait for data ready before reading?

Yes, this is problem. Ideally tmu framework should check status instead of each driver do that.

In https://lore.kernel.org/all/[email protected]/
change to use change_mode callback.

Frank

Quoted 3 lines

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7

Reviewed-by Peng Fan on v1 7/10
#14 lore raw

Re: [PATCH 07/10] thermal/drivers/imx91: Acquire runtime PM reference in imx91_tmu_get_temp()

In reply to Lee Jones
Quoted 6 lines · On Thu, 3 Dec 2026 19:54:18 +0000 Lee Jones <[email protected]> wrote:

The thermal core allows get_temp() to be called via sysfs even when the thermal zone has been disabled and imx91_tmu_change_mode() has dropped the runtime PM reference, gating the TMU clock. Reading IMX91_TMU_DATA0 in imx91_tmu_get_temp() while the clock is disabled causes an unclocked register access.

Quoted 7 lines

Wrap the register read in imx91_tmu_get_temp() with pm_runtime_resume_and_get() and pm_runtime_put().

Fixes c411d8bf0699 ("thermal/drivers/imx91: Add support for i.MX91 thermal monitoring unit")
author
#15 lore raw

PATCH 8/10 tools/thermal/tmon: Open log file with O_NOFOLLOW before validating and truncating

In reply to Lee Jones

prepare_logging() opens /var/tmp/tmon.log with fopen(..., "w+") before checking lstat() for symlinks or ownership. Because tmon runs as root and fopen("w+") follows symlinks and immediately truncates the target, a local attacker can clobber arbitrary files via a symlink in /var/tmp.

Open the log file with open(..., O_RDWR | O_CREAT | O_NOFOLLOW | O_CLOEXEC, 0600) without O_TRUNC, validate that the opened descriptor refers to a regular file owned by the current user via fstat(), and only then call ftruncate() and fdopen().

Fixes 951fda3d8c64 ("tmon: Check log file for common secuirty issues")
---
 tools/thermal/tmon/tmon.c | 36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)
tools/thermal/tmon/tmon.c +24 -12
index 70a2ec50a461..701163b4a08a 100644
@@ -8,6 +8,7 @@
  */
 
 #include <getopt.h>
+#include <fcntl.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -130,37 +131,48 @@ static void start_syslog(void)
 
 static void prepare_logging(void)
 {
-	int i;
+	int i, fd;
 	struct stat logstat;
 
 	if (!logging)
 		return;
 	/* open local data log file */
-	tmon_log = fopen(TMON_LOG_FILE, "w+");
-	if (!tmon_log) {
+	fd = open(TMON_LOG_FILE, O_RDWR | O_CREAT | O_NOFOLLOW | O_CLOEXEC,
+		  0600);
+	if (fd < 0) {
 		syslog(LOG_ERR, "failed to open log file %s\n", TMON_LOG_FILE);
 		return;
 	}
 
-	if (lstat(TMON_LOG_FILE, &logstat) < 0) {
+	if (fstat(fd, &logstat) < 0) {
 		syslog(LOG_ERR, "Unable to stat log file %s\n", TMON_LOG_FILE);
-		fclose(tmon_log);
-		tmon_log = NULL;
+		close(fd);
 		return;
 	}
 
 	/* The log file must be a regular file owned by us */
-	if (S_ISLNK(logstat.st_mode)) {
-		syslog(LOG_ERR, "Log file is a symlink.  Will not log\n");
-		fclose(tmon_log);
-		tmon_log = NULL;
+	if (!S_ISREG(logstat.st_mode)) {
+		syslog(LOG_ERR, "Log file is not a regular file.  Will not log\n");
+		close(fd);
 		return;
 	}
 
 	if (logstat.st_uid != getuid()) {
 		syslog(LOG_ERR, "We don't own the log file.  Not logging\n");
-		fclose(tmon_log);
-		tmon_log = NULL;
+		close(fd);
+		return;
+	}
+
+	if (ftruncate(fd, 0) < 0) {
+		syslog(LOG_ERR, "Unable to truncate log file %s\n", TMON_LOG_FILE);
+		close(fd);
+		return;
+	}
+
+	tmon_log = fdopen(fd, "w+");
+	if (!tmon_log) {
+		syslog(LOG_ERR, "failed to open log file %s\n", TMON_LOG_FILE);
+		close(fd);
 		return;
 	}
 
Signature · 1 line
2.56.1.911.g883d8bcb20-goog
maintainer Applied
#16 lore raw

Re: [PATCH 08/10] tools/thermal/tmon: Open log file with O_NOFOLLOW before validating and truncating

Quoted 83 lines · Lee Jones

prepare_logging() opens /var/tmp/tmon.log with fopen(..., "w+") before checking lstat() for symlinks or ownership. Because tmon runs as root and fopen("w+") follows symlinks and immediately truncates the target, a local attacker can clobber arbitrary files via a symlink in /var/tmp.

Open the log file with open(..., O_RDWR | O_CREAT | O_NOFOLLOW | O_CLOEXEC, 0600) without O_TRUNC, validate that the opened descriptor refers to a regular file owned by the current user via fstat(), and only then call ftruncate() and fdopen().

Fixes 951fda3d8c64 ("tmon: Check log file for common secuirty issues")
---
 tools/thermal/tmon/tmon.c | 36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)
tools/thermal/tmon/tmon.c +18 -12
index 70a2ec50a461..701163b4a08a 100644
@@ -8,6 +8,7 @@
  */
 
 #include <getopt.h>
+#include <fcntl.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -130,37 +131,48 @@ static void start_syslog(void)
 
 static void prepare_logging(void)
 {
-       int i;
+       int i, fd;
        struct stat logstat;
 
        if (!logging)
                return;
        /* open local data log file */
-       tmon_log = fopen(TMON_LOG_FILE, "w+");
-       if (!tmon_log) {
+       fd = open(TMON_LOG_FILE, O_RDWR | O_CREAT | O_NOFOLLOW | O_CLOEXEC,
+                 0600);
+       if (fd < 0) {
                syslog(LOG_ERR, "failed to open log file %s\n", TMON_LOG_FILE);
                return;
        }
 
-       if (lstat(TMON_LOG_FILE, &logstat) < 0) {
+       if (fstat(fd, &logstat) < 0) {
                syslog(LOG_ERR, "Unable to stat log file %s\n", TMON_LOG_FILE);
-               fclose(tmon_log);
-               tmon_log = NULL;
+               close(fd);
                return;
        }
 
        /* The log file must be a regular file owned by us */
-       if (S_ISLNK(logstat.st_mode)) {
-               syslog(LOG_ERR, "Log file is a symlink.  Will not log\n");
-               fclose(tmon_log);
-               tmon_log = NULL;
+       if (!S_ISREG(logstat.st_mode)) {
+               syslog(LOG_ERR, "Log file is not a regular file.  Will not log\n");
+               close(fd);
                return;
        }
 
        if (logstat.st_uid != getuid()) {
                syslog(LOG_ERR, "We don't own the log file.  Not logging\n");
-               fclose(tmon_log);
-               tmon_log = NULL;
+               close(fd);
+               return;
+       }
+
+       if (ftruncate(fd, 0) < 0) {
+               syslog(LOG_ERR, "Unable to truncate log file %s\n", TMON_LOG_FILE);
+               close(fd);
+               return;

tools/thermal/tmon/tmon.c static void start_syslog(void)

Quoted 10 lines
tools/thermal/tmon/tmon.c +6 -1
+       }
+
+       tmon_log = fdopen(fd, "w+");
+       if (!tmon_log) {
+               syslog(LOG_ERR, "failed to open log file %s\n", TMON_LOG_FILE);
+               close(fd);
                return;
        }
 
--

Applied as 7.4-rc material, thanks!

author
#17 lore raw

PATCH 9/10 thermal/drivers/qcom/tsens: Drop __init from ops init callbacks

In reply to Lee Jones

The TSENS ops init callbacks (init_common and the per-SoC init helpers) are annotated with __init even though they are stored in const struct tsens_ops tables and invoked from non-__init tsens_probe(). When built into the kernel, deferred probe or driver rebind after free_initmem() jumps into freed init text.

Remove __init from all nine init callbacks.

Fixes 9066073c6c27 ("thermal: qcom: tsens: Add a skeletal TSENS drivers")
---
 drivers/thermal/qcom/tsens-v0_1.c | 8 ++++----
 drivers/thermal/qcom/tsens-v1.c   | 6 +++---
 drivers/thermal/qcom/tsens-v2.c   | 2 +-
 drivers/thermal/qcom/tsens.c      | 2 +-
 4 files changed, 9 insertions(+), 9 deletions(-)
drivers/thermal/qcom/tsens-v0_1.c +4 -4
index 468da9e513e2..bcd3c0bf49dd 100644
@@ -207,7 +207,7 @@ static int calibrate_8974(struct tsens_priv *priv)
 	return 0;
 }
 
-static int __init init_8226(struct tsens_priv *priv)
+static int init_8226(struct tsens_priv *priv)
 {
 	static const u32 slopes[] = { 2901, 2846, 3038, 2955, 2901, 2846 };
 
@@ -217,7 +217,7 @@ static int __init init_8226(struct tsens_priv *priv)
 	return init_common(priv);
 }
 
-static int __init init_8909(struct tsens_priv *priv)
+static int init_8909(struct tsens_priv *priv)
 {
 	static const int p1_offsets[] = { 0, -10, 0, -9, -8 };
 	static const int p2_offsets[] = { 0, -6, 0, -9, -10 };
@@ -233,7 +233,7 @@ static int __init init_8909(struct tsens_priv *priv)
 	return init_common(priv);
 }
 
-static int __init init_8939(struct tsens_priv *priv)
+static int init_8939(struct tsens_priv *priv)
 {
 	static const u32 slopes[] = {
 		2911, 2789, 2906, 2763, 2922, 2867, 2833, 2838, 2840,
@@ -245,7 +245,7 @@ static int __init init_8939(struct tsens_priv *priv)
 	return init_common(priv);
 }
 
-static int __init init_9607(struct tsens_priv *priv)
+static int init_9607(struct tsens_priv *priv)
 {
 	static const int p1_offsets[] = { 1, -4, 4, -3, -4 };
 	static const int p2_offsets[] = { 1, -2, 8, -5, -4 };
drivers/thermal/qcom/tsens-v1.c +3 -3
index a43ccc4bda86..14c6c6c2c0d6 100644
@@ -148,7 +148,7 @@ static const struct reg_field tsens_v1_regfields[MAX_REGFIELDS] = {
 	[TRDY] = REG_FIELD(TM_TRDY_OFF, 0, 0),
 };
 
-static int __init init_8952(struct tsens_priv *priv)
+static int init_8952(struct tsens_priv *priv)
 {
 	static const int p1_offsets[] = { 2, -4, 4, 1, 2, -1, 0, 3, 2, 0, -3 };
 	static const int p2_offsets[] = { -1, -4, 5, 1, 3, -1, -1, 4, 4, 0, -2 };
@@ -161,7 +161,7 @@ static int __init init_8952(struct tsens_priv *priv)
 	return init_common(priv);
 }
 
-static int __init init_8956(struct tsens_priv *priv)
+static int init_8956(struct tsens_priv *priv)
 {
 	static const u32 slopes[] = {
 		3313, 3275, 3320, 3246, 3279, 3257, 3234, 3269, 3255, 3239, 3286,
@@ -173,7 +173,7 @@ static int __init init_8956(struct tsens_priv *priv)
 	return init_common(priv);
 }
 
-static int __init init_tsens_v1_no_rpm(struct tsens_priv *priv)
+static int init_tsens_v1_no_rpm(struct tsens_priv *priv)
 {
 	int i, ret;
 	u32 mask = 0;
drivers/thermal/qcom/tsens-v2.c +1 -1
index 843dd29fad2e..22284973bb61 100644
@@ -220,7 +220,7 @@ static int tsens_v2_calibration(struct tsens_priv *priv)
 	return 0;
 }
 
-static int __init init_tsens_v2_no_rpm(struct tsens_priv *priv)
+static int init_tsens_v2_no_rpm(struct tsens_priv *priv)
 {
 	struct device *dev = priv->dev;
 	int i, ret;
drivers/thermal/qcom/tsens.c +1 -1
index ff7c573c6a21..6ea0581e9161 100644
@@ -929,7 +929,7 @@ static const struct regmap_config tsens_srot_config = {
 	.reg_stride	= 4,
 };
 
-int __init init_common(struct tsens_priv *priv)
+int init_common(struct tsens_priv *priv)
 {
 	void __iomem *tm_base, *srot_base;
 	struct device *dev = priv->dev;
Signature · 1 line
2.56.1.911.g883d8bcb20-goog
author
#18 lore raw

PATCH 10/10 thermal/drivers/imx91: Use pm_runtime_resume_and_get() in imx91_tmu_change_mode()

In reply to Lee Jones

When enabling the thermal zone, imx91_tmu_change_mode() calls asynchronous pm_runtime_get() and immediately writes TMU control registers before the device has resumed and enabled its clock. On error, it also returns without dropping the incremented runtime PM usage count.

Use synchronous pm_runtime_resume_and_get() instead.

Fixes c411d8bf0699 ("thermal/drivers/imx91: Add support for i.MX91 thermal monitoring unit")
---
 drivers/thermal/imx91_thermal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/imx91_thermal.c +1 -1
index c3a72df665a8..dbd45a1910f5 100644
@@ -213,7 +213,7 @@ static int imx91_tmu_change_mode(struct thermal_zone_device *tz, enum thermal_de
 	int ret;
 
 	if (mode == THERMAL_DEVICE_ENABLED) {
-		ret = pm_runtime_get(tmu->dev);
+		ret = pm_runtime_resume_and_get(tmu->dev);
 		if (ret < 0)
 			return ret;
 
Signature · 1 line
2.56.1.911.g883d8bcb20-goog
Reviewed-by on v1 10/10
#19 lore raw

Re: [PATCH 10/10] thermal/drivers/imx91: Use pm_runtime_resume_and_get() in imx91_tmu_change_mode()

Quoted 6 lines · Lee Jones

When enabling the thermal zone, imx91_tmu_change_mode() calls asynchronous pm_runtime_get() and immediately writes TMU control registers before the device has resumed and enabled its clock. On error, it also returns without dropping the incremented runtime PM usage count.

Quoted 7 lines

Use synchronous pm_runtime_resume_and_get() instead.

Fixes c411d8bf0699 ("thermal/drivers/imx91: Add support for i.MX91 thermal monitoring unit")

---

Quoted 20 lines
 drivers/thermal/imx91_thermal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/imx91_thermal.c +1 -2
index c3a72df665a8..dbd45a1910f5 100644
@@ -213,7 +213,7 @@ static int imx91_tmu_change_mode(struct thermal_zone_device *tz, enum thermal_de
 	int ret;
 
 	if (mode == THERMAL_DEVICE_ENABLED) {
-		ret = pm_runtime_get(tmu->dev);
+		ret = pm_runtime_resume_and_get(tmu->dev);
 		if (ret < 0)
 			return ret;
 
--

2.56.1.911.g883d8bcb20-goog

Reviewed-by Peng Fan on v1 10/10
#20 lore raw

Re: [PATCH 10/10] thermal/drivers/imx91: Use pm_runtime_resume_and_get() in imx91_tmu_change_mode()

In reply to Lee Jones
Quoted 6 lines · On Thu, 3 Dec 2026 19:54:21 +0000 Lee Jones <[email protected]> wrote:

When enabling the thermal zone, imx91_tmu_change_mode() calls asynchronous pm_runtime_get() and immediately writes TMU control registers before the device has resumed and enabled its clock. On error, it also returns without dropping the incremented runtime PM usage count.

Quoted 6 lines

Use synchronous pm_runtime_resume_and_get() instead.

Fixes c411d8bf0699 ("thermal/drivers/imx91: Add support for i.MX91 thermal monitoring unit")