Skip to contentSkip to conversation

thermal: intel: int340x: Fix temperature selection around 0 C

PATCH Applied Thorsten Blum 3 participants 3 messages Aug 26 – Sep 4 Thermal

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal: intel: int340x: Fix temperature selection around 0 C

Since commit 7251b9e8a007 ("thermal/intel: Fix intel_tcc_get_temp() to support negative CPU temperature"), intel_tcc_get_temp() can report negative temperatures.

proc_thermal_get_zone_temp() still uses *temp as the current maximum and as an implicit "no reading yet" marker. However, this breaks when a CPU reports 0 C, because a subsequent negative reading can overwrite it.

Use bool temp_valid to track whether a valid temperature has been read. Initialize *temp with the first valid reading and only update it with warmer readings.

Fixes 7251b9e8a007 ("thermal/intel: Fix intel_tcc_get_temp() to support negative CPU temperature")
---
 .../intel/int340x_thermal/processor_thermal_device.c   | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +7 -3
index f80dbe2ca7e4..b0284c2e2e74 100644
@@ -179,17 +179,21 @@ static int proc_thermal_get_zone_temp(struct thermal_zone_device *zone,
 {
 	int cpu;
 	int curr_temp, ret;
-
-	*temp = 0;
+	bool temp_valid = false;
 
 	for_each_online_cpu(cpu) {
 		ret = intel_tcc_get_temp(cpu, &curr_temp, false);
 		if (ret < 0)
 			return ret;
-		if (!*temp || curr_temp > *temp)
+		if (!temp_valid || curr_temp > *temp) {
 			*temp = curr_temp;
+			temp_valid = true;
+		}
 	}
 
+	if (!temp_valid)
+		return -ENODATA;
+
 	*temp *= 1000;
 
 	return 0;
Acked-by on v1 1/1
#1 lore raw
Quoted 16 lines · Thorsten Blum

Since commit 7251b9e8a007 ("thermal/intel: Fix intel_tcc_get_temp() to
support negative CPU temperature"), intel_tcc_get_temp() can report negative temperatures.

proc_thermal_get_zone_temp() still uses *temp as the current maximum and
as an implicit "no reading yet" marker. However, this breaks when a CPU
reports 0 C, because a subsequent negative reading can overwrite it.

Use bool temp_valid to track whether a valid temperature has been read.
Initialize *temp with the first valid reading and only update it with warmer readings.

Quoted 4 lines
Fixes 7251b9e8a007 ("thermal/intel: Fix intel_tcc_get_temp() to

support negative CPU temperature")

Quoted 39 lines

---
 .../intel/int340x_thermal/processor_thermal_device.c   | 10 +++++++- --

 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c index f80dbe2ca7e4..b0284c2e2e74 100644
---
a/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c
+++
b/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c

drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +1 -2
@@ -179,17 +179,21 @@ static int proc_thermal_get_zone_temp(struct
 thermal_zone_device *zone,
  {
  	int cpu;
  	int curr_temp, ret;
-
-	*temp = 0;
+	bool temp_valid = false;


  for_each_online_cpu(cpu) {
  ret = intel_tcc_get_temp(cpu, &curr_temp, false); if (ret < 0)
  return ret;

drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +1 -1
-		if (!*temp || curr_temp > *temp)
+		if (!temp_valid || curr_temp > *temp) {

  *temp = curr_temp;

drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +2 -0
+			temp_valid = true;
+		}

  }

drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +3 -0
+	if (!temp_valid)
+		return -ENODATA;
+

  *temp *= 1000;

  return 0;

maintainer Applied
#2 lore raw
Quoted 18 lines · srinivas pandruvada
Quoted 16 lines · Thorsten Blum

Since commit 7251b9e8a007 ("thermal/intel: Fix intel_tcc_get_temp() to
support negative CPU temperature"), intel_tcc_get_temp() can report negative temperatures.

proc_thermal_get_zone_temp() still uses *temp as the current maximum and
as an implicit "no reading yet" marker. However, this breaks when a CPU
reports 0 C, because a subsequent negative reading can overwrite it.

Use bool temp_valid to track whether a valid temperature has been read.
Initialize *temp with the first valid reading and only update it with warmer readings.

Quoted 6 lines
Quoted 4 lines
Fixes 7251b9e8a007 ("thermal/intel: Fix intel_tcc_get_temp() to

support negative CPU temperature")

Applied as 7.4 material, thanks!

Quoted 40 lines
Quoted 40 lines
---
 .../intel/int340x_thermal/processor_thermal_device.c   | 10 +++++++-
--
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c index f80dbe2ca7e4..b0284c2e2e74 100644
---
a/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c
+++
b/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c

drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +7 -3
@@ -179,17 +179,21 @@ static int proc_thermal_get_zone_temp(struct
 thermal_zone_device *zone,
 {
      int cpu;
      int curr_temp, ret;
-
-     *temp = 0;
+     bool temp_valid = false;
 
      for_each_online_cpu(cpu) {
              ret = intel_tcc_get_temp(cpu, &curr_temp, false);
              if (ret < 0)
                      return ret;
-             if (!*temp || curr_temp > *temp)
+             if (!temp_valid || curr_temp > *temp) {
                      *temp = curr_temp;
+                     temp_valid = true;
+             }
      }
 
+     if (!temp_valid)
+             return -ENODATA;
+
      *temp *= 1000;
 
      return 0;