* [PATCH] thermal: imx: Fix race condition in imx_thermal_probe()
@ 2018-02-02 18:17 Fabio Estevam
2018-02-14 3:23 ` Fabio Estevam
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Fabio Estevam @ 2018-02-02 18:17 UTC (permalink / raw)
To: rui.zhang
Cc: edubezval, mikhail.lappo, linux-pm, linux-imx, p.zabel, shawnguo,
stable, Fabio Estevam
From: Mikhail Lappo <mikhail.lappo@esrlabs.com>
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")
Cc: <stable@vger.kernel.org>
Signed-off-by: Mikhail Lappo <mikhail.lappo@esrlabs.com>
Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
---
drivers/thermal/imx_thermal.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
index a67781b..ee3a215 100644
--- a/drivers/thermal/imx_thermal.c
+++ b/drivers/thermal/imx_thermal.c
@@ -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
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH] thermal: imx: Fix race condition in imx_thermal_probe() 2018-02-02 18:17 [PATCH] thermal: imx: Fix race condition in imx_thermal_probe() Fabio Estevam @ 2018-02-14 3:23 ` Fabio Estevam 2018-02-26 18:56 ` Fabio Estevam 2018-02-27 8:44 ` Philipp Zabel 2018-02-28 2:16 ` A.s. Dong 2 siblings, 1 reply; 9+ messages in thread From: Fabio Estevam @ 2018-02-14 3:23 UTC (permalink / raw) To: rui.zhang Cc: Eduardo Valentin, Mikhail Lappo, linux-pm, NXP Linux Team, Philipp Zabel, Shawn Guo, stable, Fabio Estevam Hi Eduardo and Rui, On Fri, Feb 2, 2018 at 4:17 PM, Fabio Estevam <festevam@gmail.com> wrote: > From: Mikhail Lappo <mikhail.lappo@esrlabs.com> > > 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") > Cc: <stable@vger.kernel.org> > Signed-off-by: Mikhail Lappo <mikhail.lappo@esrlabs.com> > Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com> A gentle ping on this patch. > --- > drivers/thermal/imx_thermal.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c > index a67781b..ee3a215 100644 > --- a/drivers/thermal/imx_thermal.c > +++ b/drivers/thermal/imx_thermal.c > @@ -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 > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] thermal: imx: Fix race condition in imx_thermal_probe() 2018-02-14 3:23 ` Fabio Estevam @ 2018-02-26 18:56 ` Fabio Estevam 2018-02-28 4:42 ` Zhang Rui 0 siblings, 1 reply; 9+ messages in thread From: Fabio Estevam @ 2018-02-26 18:56 UTC (permalink / raw) To: rui.zhang Cc: Eduardo Valentin, Mikhail Lappo, linux-pm, NXP Linux Team, Philipp Zabel, Shawn Guo, stable, Fabio Estevam Rui, Any comments, please? On Wed, Feb 14, 2018 at 1:23 AM, Fabio Estevam <festevam@gmail.com> wrote: > Hi Eduardo and Rui, > > On Fri, Feb 2, 2018 at 4:17 PM, Fabio Estevam <festevam@gmail.com> wrote: >> From: Mikhail Lappo <mikhail.lappo@esrlabs.com> >> >> 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") >> Cc: <stable@vger.kernel.org> >> Signed-off-by: Mikhail Lappo <mikhail.lappo@esrlabs.com> >> Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com> > > A gentle ping on this patch. > >> --- >> drivers/thermal/imx_thermal.c | 6 +++--- >> 1 file changed, 3 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c >> index a67781b..ee3a215 100644 >> --- a/drivers/thermal/imx_thermal.c >> +++ b/drivers/thermal/imx_thermal.c >> @@ -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 >> ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] thermal: imx: Fix race condition in imx_thermal_probe() 2018-02-26 18:56 ` Fabio Estevam @ 2018-02-28 4:42 ` Zhang Rui 2018-03-07 19:55 ` Fabio Estevam 0 siblings, 1 reply; 9+ messages in thread From: Zhang Rui @ 2018-02-28 4:42 UTC (permalink / raw) To: Fabio Estevam Cc: Eduardo Valentin, Mikhail Lappo, linux-pm, NXP Linux Team, Philipp Zabel, Shawn Guo, stable, Fabio Estevam On Mon, 2018-02-26 at 15:56 -0300, Fabio Estevam wrote: > 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 > On Wed, Feb 14, 2018 at 1:23 AM, Fabio Estevam <festevam@gmail.com> > wrote: > > > > Hi Eduardo and Rui, > > > > On Fri, Feb 2, 2018 at 4:17 PM, Fabio Estevam <festevam@gmail.com> > > wrote: > > > > > > From: Mikhail Lappo <mikhail.lappo@esrlabs.com> > > > > > > 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") > > > Cc: <stable@vger.kernel.org> > > > Signed-off-by: Mikhail Lappo <mikhail.lappo@esrlabs.com> > > > Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com> > > A gentle ping on this patch. > > > > > > > > --- > > > drivers/thermal/imx_thermal.c | 6 +++--- > > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > > > diff --git a/drivers/thermal/imx_thermal.c > > > b/drivers/thermal/imx_thermal.c > > > index a67781b..ee3a215 100644 > > > --- a/drivers/thermal/imx_thermal.c > > > +++ b/drivers/thermal/imx_thermal.c > > > @@ -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 > > > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] thermal: imx: Fix race condition in imx_thermal_probe() 2018-02-28 4:42 ` Zhang Rui @ 2018-03-07 19:55 ` Fabio Estevam 2018-03-20 13:13 ` Fabio Estevam 0 siblings, 1 reply; 9+ messages in thread From: Fabio Estevam @ 2018-03-07 19:55 UTC (permalink / raw) To: Zhang Rui Cc: Eduardo Valentin, Mikhail Lappo, linux-pm, NXP Linux Team, Philipp Zabel, Shawn Guo, stable, Fabio Estevam Hi Rui, On Wed, Feb 28, 2018 at 1:42 AM, Zhang Rui <rui.zhang@intel.com> wrote: > 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. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] thermal: imx: Fix race condition in imx_thermal_probe() 2018-03-07 19:55 ` Fabio Estevam @ 2018-03-20 13:13 ` Fabio Estevam 2018-03-20 13:19 ` Zhang Rui 0 siblings, 1 reply; 9+ messages in thread From: Fabio Estevam @ 2018-03-20 13:13 UTC (permalink / raw) To: Zhang Rui, Eduardo Valentin Cc: Mikhail Lappo, linux-pm, NXP Linux Team, Philipp Zabel, Shawn Guo, stable, Fabio Estevam Hi Rui, On Wed, Mar 7, 2018 at 4:55 PM, Fabio Estevam <festevam@gmail.com> wrote: > Hi Rui, > > On Wed, Feb 28, 2018 at 1:42 AM, Zhang Rui <rui.zhang@intel.com> wrote: > >> 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? ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] thermal: imx: Fix race condition in imx_thermal_probe() 2018-03-20 13:13 ` Fabio Estevam @ 2018-03-20 13:19 ` Zhang Rui 0 siblings, 0 replies; 9+ messages in thread From: Zhang Rui @ 2018-03-20 13:19 UTC (permalink / raw) To: Fabio Estevam, Eduardo Valentin Cc: Mikhail Lappo, linux-pm, NXP Linux Team, Philipp Zabel, Shawn Guo, stable, Fabio Estevam On 二, 2018-03-20 at 10:13 -0300, Fabio Estevam wrote: > Hi Rui, > > On Wed, Mar 7, 2018 at 4:55 PM, Fabio Estevam <festevam@gmail.com> > wrote: > > > > Hi Rui, > > > > On Wed, Feb 28, 2018 at 1:42 AM, Zhang Rui <rui.zhang@intel.com> > > wrote: > > > > > > > > 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? yes, it's in my tree now. thanks, rui ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] thermal: imx: Fix race condition in imx_thermal_probe() 2018-02-02 18:17 [PATCH] thermal: imx: Fix race condition in imx_thermal_probe() Fabio Estevam 2018-02-14 3:23 ` Fabio Estevam @ 2018-02-27 8:44 ` Philipp Zabel 2018-02-28 2:16 ` A.s. Dong 2 siblings, 0 replies; 9+ messages in thread From: Philipp Zabel @ 2018-02-27 8:44 UTC (permalink / raw) To: Fabio Estevam, rui.zhang Cc: edubezval, mikhail.lappo, linux-pm, linux-imx, shawnguo, stable, Fabio Estevam On Fri, 2018-02-02 at 16:17 -0200, Fabio Estevam wrote: > From: Mikhail Lappo <mikhail.lappo@esrlabs.com> > > 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") > Cc: <stable@vger.kernel.org> > Signed-off-by: Mikhail Lappo <mikhail.lappo@esrlabs.com> > Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com> Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de> regards Philipp ^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH] thermal: imx: Fix race condition in imx_thermal_probe() 2018-02-02 18:17 [PATCH] thermal: imx: Fix race condition in imx_thermal_probe() Fabio Estevam 2018-02-14 3:23 ` Fabio Estevam 2018-02-27 8:44 ` Philipp Zabel @ 2018-02-28 2:16 ` A.s. Dong 2 siblings, 0 replies; 9+ messages in thread From: A.s. Dong @ 2018-02-28 2:16 UTC (permalink / raw) To: Fabio Estevam, rui.zhang@intel.com Cc: edubezval@gmail.com, mikhail.lappo@esrlabs.com, linux-pm@vger.kernel.org, dl-linux-imx, p.zabel@pengutronix.de, shawnguo@kernel.org, stable@vger.kernel.org, Fabio Estevam > -----Original Message----- > From: Fabio Estevam [mailto:festevam@gmail.com] > Sent: Saturday, February 3, 2018 2:18 AM > To: rui.zhang@intel.com > Cc: edubezval@gmail.com; mikhail.lappo@esrlabs.com; linux- > pm@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>; > p.zabel@pengutronix.de; shawnguo@kernel.org; stable@vger.kernel.org; > Fabio Estevam <fabio.estevam@nxp.com> > Subject: [PATCH] thermal: imx: Fix race condition in imx_thermal_probe() > > From: Mikhail Lappo <mikhail.lappo@esrlabs.com> > > 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") > Cc: <stable@vger.kernel.org> > Signed-off-by: Mikhail Lappo <mikhail.lappo@esrlabs.com> > Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com> Looks reasonable to me. Acked-by: Dong Aisheng <aisheng.dong@nxp.com> Regards Dong Aisheng > --- > drivers/thermal/imx_thermal.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c > index a67781b..ee3a215 100644 > --- a/drivers/thermal/imx_thermal.c > +++ b/drivers/thermal/imx_thermal.c > @@ -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 ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-03-20 13:19 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-02-02 18:17 [PATCH] thermal: imx: Fix race condition in imx_thermal_probe() Fabio Estevam 2018-02-14 3:23 ` Fabio Estevam 2018-02-26 18:56 ` Fabio Estevam 2018-02-28 4:42 ` Zhang Rui 2018-03-07 19:55 ` Fabio Estevam 2018-03-20 13:13 ` Fabio Estevam 2018-03-20 13:19 ` Zhang Rui 2018-02-27 8:44 ` Philipp Zabel 2018-02-28 2:16 ` A.s. Dong
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).