thermal: imx: Fix race condition in imx_thermal_probe()
Subsystems (3)
Fabio Estevam
reviewerPATCH 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.
--- drivers/thermal/imx_thermal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/thermal/imx_thermal.c +3 -3
@@ -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
Fabio Estevam
reviewerHi Eduardo and Rui,
Quoted 10 lines · Fabio Estevam
From: Mikhail Lappo <[email protected]>
When device boots with T >
T_trip_1and requests interrupt, the race condition takes place. The interrupt comes beforeTHERMAL_DEVICE_ENABLEDis set. This leads to an attempt to reading sensor value from irq and disabling the sensor, based on thedata->modefield, which expected to beTHERMAL_DEVICE_ENABLED, but still stays asTHERMAL_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")Cc <[email protected]>Signed-off-by Mikhail Lappo <[email protected]>Signed-off-by Fabio Estevam <[email protected]>
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@@ -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
Fabio Estevam
reviewerRui,
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_1and requests interrupt, the race condition takes place. The interrupt comes beforeTHERMAL_DEVICE_ENABLEDis set. This leads to an attempt to reading sensor value from irq and disabling the sensor, based on thedata->modefield, which expected to beTHERMAL_DEVICE_ENABLED, but still stays asTHERMAL_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")Cc <[email protected]>Signed-off-by Mikhail Lappo <[email protected]>Signed-off-by Fabio Estevam <[email protected]>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@@ -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
Zhang Rui
reviewerQuoted 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_1and requests interrupt, the race condition takes place. The interrupt comes beforeTHERMAL_DEVICE_ENABLEDis set. This leads to an attempt to reading sensor value from irq and disabling the sensor, based on thedata->modefield, which expected to beTHERMAL_DEVICE_ENABLED,
but still stays asTHERMAL_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 alarminterrupt handling")
Cc <[email protected]>Signed-off-by Mikhail Lappo <[email protected]>Signed-off-by Fabio Estevam <[email protected]>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@@ -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
Fabio Estevam
reviewerHi 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.
Fabio Estevam
reviewerHi 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?
Zhang Rui
reviewerQuoted 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
Quoted 10 lines · Fabio Estevam
From: Mikhail Lappo <[email protected]>
When device boots with T >
T_trip_1and requests interrupt, the race condition takes place. The interrupt comes beforeTHERMAL_DEVICE_ENABLEDis set. This leads to an attempt to reading sensor value from irq and disabling the sensor, based on thedata->modefield, which expected to beTHERMAL_DEVICE_ENABLED, but still stays asTHERMAL_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")Cc <[email protected]>Signed-off-by Mikhail Lappo <[email protected]>Signed-off-by Fabio Estevam <[email protected]>
regards
Philipp
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 inimx_thermal_probe()From: Mikhail Lappo <[email protected]>
When device boots with T >
T_trip_1and requests interrupt, the race condition takes place. The interrupt comes beforeTHERMAL_DEVICE_ENABLEDis set. This leads to an attempt to reading sensor value from irq and disabling the sensor, based on thedata->modefield, which expected to beTHERMAL_DEVICE_ENABLED, but still stays asTHERMAL_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 interrupthandling")
Cc <[email protected]>Signed-off-by Mikhail Lappo <[email protected]>Signed-off-by Fabio Estevam <[email protected]>
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@@ -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
-0ret = devm_request_threaded_irq(&pdev->dev, data->irq, imx_thermal_alarm_irq,
imx_thermal_alarm_irq_thread,drivers/thermal/imx_thermal.c +0
-40, "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