diff mbox

[4/8,v2] thermal: rcar: retern error rcar_thermal_get_temp() if no ctemp update

Message ID 87bna6fwdr.wl%kuninori.morimoto.gx@renesas.com (mailing list archive)
State Superseded
Delegated to: Geert Uytterhoeven
Headers show

Commit Message

Kuninori Morimoto Dec. 4, 2015, 8:33 a.m. UTC
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

Current rcar_thermal_get_temp() returns latest temperature, but it might
not be updated if some HW issue happend. This means user might get
wrong temperature. This patch solved this issue.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v1 -> v2

 - new patch

 drivers/thermal/rcar_thermal.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c
index aaedf37..52493b4 100644
--- a/drivers/thermal/rcar_thermal.c
+++ b/drivers/thermal/rcar_thermal.c
@@ -199,9 +199,9 @@  static int rcar_thermal_update_temp(struct rcar_thermal_priv *priv)
 
 	dev_dbg(dev, "thermal%d  %d -> %d\n", priv->id, priv->ctemp, ctemp);
 
-	priv->ctemp = ctemp;
 	ret = 0;
 err_out_unlock:
+	priv->ctemp = ctemp;
 	mutex_unlock(&priv->lock);
 	return ret;
 }
@@ -209,6 +209,7 @@  err_out_unlock:
 static int rcar_thermal_get_temp(struct thermal_zone_device *zone, int *temp)
 {
 	struct rcar_thermal_priv *priv = rcar_zone_to_priv(zone);
+	int tmp;
 
 	if (!rcar_has_irq_support(priv) || rcar_force_update_temp(priv)) {
 		int ret = rcar_thermal_update_temp(priv);
@@ -217,9 +218,18 @@  static int rcar_thermal_get_temp(struct thermal_zone_device *zone, int *temp)
 	}
 
 	mutex_lock(&priv->lock);
-	*temp =  MCELSIUS((priv->ctemp * 5) - 65);
+	tmp =  MCELSIUS((priv->ctemp * 5) - 65);
 	mutex_unlock(&priv->lock);
 
+	if ((tmp < MCELSIUS(-45)) || (tmp > MCELSIUS(125))) {
+		struct device *dev = rcar_priv_to_dev(priv);
+
+		dev_err(dev, "it couldn't measure temperature correctly\n");
+		return -EIO;
+	}
+
+	*temp = tmp;
+
 	return 0;
 }