Skip to contentSkip to conversation

thermal: imx: Fix race condition in imx_thermal_probe()

PATCH In review Fabio Estevam 4 participants 9 messages Feb 2, 2018 – Mar 20, 2018

Subsystems (3)
lore
Share & tools
lore

Fabio Estevam

author reviewer
#0 lore raw

PATCH 1/1 thermal: imx: Fix race condition in imx_thermal_probe()

From: Mikhail Lappo <[email protected]>

When device boots with T > T_trip_1 and requests interrupt, the race condition takes place. The interrupt comes before THERMAL_DEVICE_ENABLED is set. This leads to an attempt to reading sensor value from irq and disabling the sensor, based on the data->mode field, which expected to be THERMAL_DEVICE_ENABLED, but still stays as THERMAL_DEVICE_DISABLED. Afher this issue sensor is never re-enabled, as the driver state is wrong.

Fix this problem by setting the 'data' members prior to requesting the interrupts.

Fixes 37713a1e8e4c ("thermal: imx: implement thermal alarm interrupt handling")
---
 drivers/thermal/imx_thermal.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/thermal/imx_thermal.c +3 -3
index a67781b..ee3a215 100644
@@ -637,6 +637,9 @@ static int imx_thermal_probe(struct platform_device *pdev)
 	regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN);
 	regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP);
 
+	data->irq_enabled = true;
+	data->mode = THERMAL_DEVICE_ENABLED;
+
 	ret = devm_request_threaded_irq(&pdev->dev, data->irq,
 			imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread,
 			0, "imx_thermal", data);
@@ -649,9 +652,6 @@ static int imx_thermal_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	data->irq_enabled = true;
-	data->mode = THERMAL_DEVICE_ENABLED;
-
 	return 0;
 }
 
Signature · 1 line
2.7.4
author reviewer
#1 lore raw

Hi Eduardo and Rui,

Quoted 10 lines · Fabio Estevam

From: Mikhail Lappo <[email protected]>

When device boots with T > T_trip_1 and requests interrupt, the race condition takes place. The interrupt comes before THERMAL_DEVICE_ENABLED is set. This leads to an attempt to reading sensor value from irq and disabling the sensor, based on the data->mode field, which expected to be THERMAL_DEVICE_ENABLED, but still stays as THERMAL_DEVICE_DISABLED. Afher this issue sensor is never re-enabled, as the driver state is wrong.

Quoted 7 lines

Fix this problem by setting the 'data' members prior to requesting the interrupts.

Fixes 37713a1e8e4c ("thermal: imx: implement thermal alarm interrupt handling")

A gentle ping on this patch.

Quoted 31 lines
---
 drivers/thermal/imx_thermal.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/thermal/imx_thermal.c +3 -4
index a67781b..ee3a215 100644
@@ -637,6 +637,9 @@ static int imx_thermal_probe(struct platform_device *pdev)
        regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN);
        regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP);
 
+       data->irq_enabled = true;
+       data->mode = THERMAL_DEVICE_ENABLED;
+
        ret = devm_request_threaded_irq(&pdev->dev, data->irq,
                        imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread,
                        0, "imx_thermal", data);
@@ -649,9 +652,6 @@ static int imx_thermal_probe(struct platform_device *pdev)
                return ret;
        }
 
-       data->irq_enabled = true;
-       data->mode = THERMAL_DEVICE_ENABLED;
-
        return 0;
 }
 
--

2.7.4

author reviewer
#2 lore raw

Rui,

Any comments, please?

Quoted 54 lines · Fabio Estevam

Hi Eduardo and Rui,

Quoted 10 lines · Fabio Estevam

From: Mikhail Lappo <[email protected]>

When device boots with T > T_trip_1 and requests interrupt, the race condition takes place. The interrupt comes before THERMAL_DEVICE_ENABLED is set. This leads to an attempt to reading sensor value from irq and disabling the sensor, based on the data->mode field, which expected to be THERMAL_DEVICE_ENABLED, but still stays as THERMAL_DEVICE_DISABLED. Afher this issue sensor is never re-enabled, as the driver state is wrong.

Quoted 7 lines

Fix this problem by setting the 'data' members prior to requesting the interrupts.

Fixes 37713a1e8e4c ("thermal: imx: implement thermal alarm interrupt handling")

A gentle ping on this patch.

Quoted 31 lines
---
 drivers/thermal/imx_thermal.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/thermal/imx_thermal.c +3 -4
index a67781b..ee3a215 100644
@@ -637,6 +637,9 @@ static int imx_thermal_probe(struct platform_device *pdev)
        regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN);
        regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP);
 
+       data->irq_enabled = true;
+       data->mode = THERMAL_DEVICE_ENABLED;
+
        ret = devm_request_threaded_irq(&pdev->dev, data->irq,
                        imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread,
                        0, "imx_thermal", data);
@@ -649,9 +652,6 @@ static int imx_thermal_probe(struct platform_device *pdev)
                return ret;
        }
 
-       data->irq_enabled = true;
-       data->mode = THERMAL_DEVICE_ENABLED;
-
        return 0;
 }
 
--

2.7.4

reviewer
#3 lore raw
Quoted 4 lines · Fabio Estevam

Rui,

Any comments, please?

interesting, this problem should be covered by this patch https://patch
work.kernel.org/patch/10242483/, together with some driver code change.

anyway, as that is not a complete solution yet, I will apply this patch as a quick solution.

thanks,
rui

Quoted 67 lines
Quoted 65 lines · Fabio Estevam

Hi Eduardo and Rui,

Quoted 12 lines · Fabio Estevam

From: Mikhail Lappo <[email protected]>

When device boots with T > T_trip_1 and requests interrupt, the race condition takes place. The interrupt comes before THERMAL_DEVICE_ENABLED is set. This leads to an attempt to reading sensor value from irq and disabling the sensor, based on the data->mode field, which expected to be THERMAL_DEVICE_ENABLED,
but still stays as THERMAL_DEVICE_DISABLED. Afher this issue sensor is never re-enabled, as the driver state is wrong.

Quoted 8 lines

Fix this problem by setting the 'data' members prior to requesting the interrupts.

Fixes 37713a1e8e4c ("thermal: imx: implement thermal alarm

interrupt handling")

A gentle ping on this patch.

Quoted 38 lines

---
 drivers/thermal/imx_thermal.c | 6 +++---

 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/thermal/imx_thermal.c +3 -0
index a67781b..ee3a215 100644
@@ -637,6 +637,9 @@ static int imx_thermal_probe(struct
 platform_device *pdev)
         regmap_write(map, TEMPSENSE0 + REG_CLR,
 TEMPSENSE0_POWER_DOWN);
         regmap_write(map, TEMPSENSE0 + REG_SET,
 TEMPSENSE0_MEASURE_TEMP);
 
+       data->irq_enabled = true;
+       data->mode = THERMAL_DEVICE_ENABLED;
+

        ret = devm_request_threaded_irq(&pdev->dev, data->irq, imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread,
                        0, "imx_thermal", data);

drivers/thermal/imx_thermal.c +0 -4
@@ -649,9 +652,6 @@ static int imx_thermal_probe(struct
 platform_device *pdev)
                 return ret;
         }
 
-       data->irq_enabled = true;
-       data->mode = THERMAL_DEVICE_ENABLED;
-
         return 0;
  }
 
--

2.7.4

author reviewer
#4 lore raw

Hi Rui,

Quoted 5 lines · Zhang Rui

interesting, this problem should be covered by this patch https://patch
work.kernel.org/patch/10242483/, together with some driver code change.

anyway, as that is not a complete solution yet, I will apply this patch as a quick solution.

Thanks, but I still don't see this one in your tree.

author reviewer
#5 lore raw

Hi Rui,

Quoted 11 lines · Fabio Estevam

Hi Rui,

Quoted 5 lines · Zhang Rui

interesting, this problem should be covered by this patch https://patch
work.kernel.org/patch/10242483/, together with some driver code change.

anyway, as that is not a complete solution yet, I will apply this patch as a quick solution.

Thanks, but I still don't see this one in your tree.

Sorry to bother you, but is it possible to get this one to 4.17, please?

reviewer
#6 lore raw
Quoted 16 lines · Fabio Estevam

Hi Rui,

Quoted 12 lines · Fabio Estevam

Hi Rui,

Quoted 6 lines · Zhang Rui

interesting, this problem should be covered by this patch https:/ /patch
work.kernel.org/patch/10242483/, together with some driver code change.

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

anyway, as that is not a complete solution yet, I will apply this patch
as a quick solution.

Thanks, but I still don't see this one in your tree.

Sorry to bother you, but is it possible to get this one to 4.17, please?

yes, it's in my tree now.

thanks,
rui

Reviewed-by on v1 1/1
#7 lore raw
In reply to Fabio Estevam
Quoted 10 lines · Fabio Estevam

From: Mikhail Lappo <[email protected]>

When device boots with T > T_trip_1 and requests interrupt, the race condition takes place. The interrupt comes before THERMAL_DEVICE_ENABLED is set. This leads to an attempt to reading sensor value from irq and disabling the sensor, based on the data->mode field, which expected to be THERMAL_DEVICE_ENABLED, but still stays as THERMAL_DEVICE_DISABLED. Afher this issue sensor is never re-enabled, as the driver state is wrong.

Quoted 7 lines

Fix this problem by setting the 'data' members prior to requesting the interrupts.

Fixes 37713a1e8e4c ("thermal: imx: implement thermal alarm interrupt handling")

regards
Philipp

Acked-by on v1 1/1
#8 lore raw
In reply to Fabio Estevam
Quoted 20 lines

-----Original Message-----
From: Fabio Estevam [mailto:[email protected]]
Sent: Saturday, February 3, 2018 2:18 AM
To: [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]; [email protected]; Fabio Estevam <[email protected]>
Subject: [PATCH] thermal: imx: Fix race condition in imx_thermal_probe()

From: Mikhail Lappo <[email protected]>

When device boots with T > T_trip_1 and requests interrupt, the race condition takes place. The interrupt comes before THERMAL_DEVICE_ENABLED is set. This leads to an attempt to reading sensor value from irq and disabling the sensor, based on the data->mode field, which expected to be THERMAL_DEVICE_ENABLED, but still stays as THERMAL_DEVICE_DISABLED. Afher this issue sensor is never re-enabled, as the driver state is wrong.

Quoted 8 lines

Fix this problem by setting the 'data' members prior to requesting the interrupts.

Fixes 37713a1e8e4c ("thermal: imx: implement thermal alarm interrupt

handling")

Looks reasonable to me.

Regards
Dong Aisheng

Quoted 35 lines
---
 drivers/thermal/imx_thermal.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/thermal/imx_thermal.c +3 -0
index a67781b..ee3a215 100644
@@ -637,6 +637,9 @@ static int imx_thermal_probe(struct platform_device
 *pdev)
 	regmap_write(map, TEMPSENSE0 + REG_CLR,
 TEMPSENSE0_POWER_DOWN);
 	regmap_write(map, TEMPSENSE0 + REG_SET,
 TEMPSENSE0_MEASURE_TEMP);
 
+	data->irq_enabled = true;
+	data->mode = THERMAL_DEVICE_ENABLED;
+
drivers/thermal/imx_thermal.c +0 -0
 	ret = devm_request_threaded_irq(&pdev->dev, data->irq,
 			imx_thermal_alarm_irq,

imx_thermal_alarm_irq_thread,

drivers/thermal/imx_thermal.c +0 -4
 			0, "imx_thermal", data);
@@ -649,9 +652,6 @@ static int imx_thermal_probe(struct platform_device
 *pdev)
 		return ret;
 	}
 
-	data->irq_enabled = true;
-	data->mode = THERMAL_DEVICE_ENABLED;
-
 	return 0;
 }
 
--

2.7.4