[PATCH] thermal: of-thermal: return -EAGAIN until thermal_zone_of_sensor_register() was called

From: Kuninori Morimoto
Date: Wed Jan 20 2016 - 00:53:35 EST


From: Kuninori Morimoto <kuninori.morimoto.gx@xxxxxxxxxxx>

of_parse_thermal_zones() will call thermal_zone_device_register(), and it
calls thermal_zone_get_temp() before calling thermal_zone_of_sensor_register()
which setup .get_temp on thermal_zone_of_add_sensor.
Because of this setting path, thermal_zone_device_register() will call
.get_temp and it gets -EINVAL from thermal_zone_get_temp().
Thus, kernel always indicates

thermal thermal_zone0: failed to read out thermal zone (-22)

This patch solves this issue.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@xxxxxxxxxxx>
---
drivers/thermal/of-thermal.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
index 440ea63..729e2d4 100644
--- a/drivers/thermal/of-thermal.c
+++ b/drivers/thermal/of-thermal.c
@@ -89,6 +89,15 @@ struct __thermal_zone {
};

/*** DT thermal zone device callbacks ***/
+static int of_thermal_null_get_temp(struct thermal_zone_device *tz,
+ int *temp)
+{
+ /*
+ * This function will be replaced with
+ * of_thermal_get_temp() by thermal_zone_of_add_sensor()
+ */
+ return -EAGAIN;
+}

static int of_thermal_get_temp(struct thermal_zone_device *tz,
int *temp)
@@ -383,6 +392,7 @@ static struct thermal_zone_device_ops of_thermal_ops = {
.get_mode = of_thermal_get_mode,
.set_mode = of_thermal_set_mode,

+ .get_temp = of_thermal_null_get_temp,
.get_trip_type = of_thermal_get_trip_type,
.get_trip_temp = of_thermal_get_trip_temp,
.set_trip_temp = of_thermal_set_trip_temp,
@@ -549,7 +559,7 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
return;

mutex_lock(&tzd->lock);
- tzd->ops->get_temp = NULL;
+ tzd->ops->get_temp = of_thermal_null_get_temp;
tzd->ops->get_trend = NULL;
tzd->ops->set_emul_temp = NULL;

--
1.9.1