diff mbox

thermal: exynos: Reading temperature makes sense only when TMU is turned on

Message ID 20180227132834.22521-1-m.szyprowski@samsung.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Marek Szyprowski Feb. 27, 2018, 1:28 p.m. UTC
When thermal sensor is not yet enabled, reading temperature might return
random value. This might even result in stopping system booting when such
temperature is higher than critical value. Fix this by checking if TMU
has been actually enabled.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
CC: stable@vger.kernel.org # v4.6+
---
This issue is there since commit 9e4249b40340 ("thermal: exynos: Fix
first temperature read after registering sensor"), but this patch applies
cleanly only to v4.6+ kenrels.
---
 drivers/thermal/samsung/exynos_tmu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Bartlomiej Zolnierkiewicz Feb. 27, 2018, 1:39 p.m. UTC | #1
On Tuesday, February 27, 2018 02:28:34 PM Marek Szyprowski wrote:
> When thermal sensor is not yet enabled, reading temperature might return
> random value. This might even result in stopping system booting when such
> temperature is higher than critical value. Fix this by checking if TMU
> has been actually enabled.

Please also mention the hardware on which the problem happened.

> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
> CC: stable@vger.kernel.org # v4.6+
> ---
> This issue is there since commit 9e4249b40340 ("thermal: exynos: Fix
> first temperature read after registering sensor"), but this patch applies
> cleanly only to v4.6+ kenrels.

Please add "Fixes:" tag.

> ---
>  drivers/thermal/samsung/exynos_tmu.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
> index ed805c7c5ace..367a9f94ece9 100644
> --- a/drivers/thermal/samsung/exynos_tmu.c
> +++ b/drivers/thermal/samsung/exynos_tmu.c
> @@ -205,6 +205,7 @@ struct exynos_tmu_data {
>  	struct regulator *regulator;
>  	struct thermal_zone_device *tzd;
>  	unsigned int ntrip;
> +	bool enabled;

Please also update struct exynos_tmu_data documentation.

>  	int (*tmu_initialize)(struct platform_device *pdev);
>  	void (*tmu_control)(struct platform_device *pdev, bool on);
> @@ -398,6 +399,7 @@ static void exynos_tmu_control(struct platform_device *pdev, bool on)
>  	mutex_lock(&data->lock);
>  	clk_enable(data->clk);
>  	data->tmu_control(pdev, on);
> +	data->enabled = on;
>  	clk_disable(data->clk);
>  	mutex_unlock(&data->lock);
>  }
> @@ -890,7 +892,7 @@ static int exynos_get_temp(void *p, int *temp)
>  {
>  	struct exynos_tmu_data *data = p;
>  
> -	if (!data || !data->tmu_read)
> +	if (!data || !data->tmu_read || !data->enabled)
>  		return -EINVAL;
>  
>  	mutex_lock(&data->lock);

With 3 above minor nits fixed:

Acked-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
index ed805c7c5ace..367a9f94ece9 100644
--- a/drivers/thermal/samsung/exynos_tmu.c
+++ b/drivers/thermal/samsung/exynos_tmu.c
@@ -205,6 +205,7 @@  struct exynos_tmu_data {
 	struct regulator *regulator;
 	struct thermal_zone_device *tzd;
 	unsigned int ntrip;
+	bool enabled;
 
 	int (*tmu_initialize)(struct platform_device *pdev);
 	void (*tmu_control)(struct platform_device *pdev, bool on);
@@ -398,6 +399,7 @@  static void exynos_tmu_control(struct platform_device *pdev, bool on)
 	mutex_lock(&data->lock);
 	clk_enable(data->clk);
 	data->tmu_control(pdev, on);
+	data->enabled = on;
 	clk_disable(data->clk);
 	mutex_unlock(&data->lock);
 }
@@ -890,7 +892,7 @@  static int exynos_get_temp(void *p, int *temp)
 {
 	struct exynos_tmu_data *data = p;
 
-	if (!data || !data->tmu_read)
+	if (!data || !data->tmu_read || !data->enabled)
 		return -EINVAL;
 
 	mutex_lock(&data->lock);