Message ID | 87poyh5x69.wl%kuninori.morimoto.gx@renesas.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Geert Uytterhoeven |
Headers | show |
On Tue, Dec 08, 2015 at 05:28:13AM +0000, Kuninori Morimoto wrote: > 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 happened. This means user might get > wrong temperature. This patch solved this issue. > > Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> > --- > v3 -> v4 > > - "happend" -> "happened" > > drivers/thermal/rcar_thermal.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c > index 67b5216..40c3ba5 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; I believe the problem here is actually the lack of error handling/propagation. Are you sure you want to write to parameter in the fail path ? rcar_thermal_update_temp already returns error code when it fails to read temperature. Don't you think it would make more sense to fix the places that call rcar_thermal_update_temp to properly handle its return value and propagate that error code when necessary? BR, -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Eduardo > > --- 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; > > I believe the problem here is actually the lack of error > handling/propagation. Are you sure you want to write to parameter > in the fail path ? > > rcar_thermal_update_temp already returns error code when it fails > to read temperature. Don't you think it would make more sense to fix the > places that call rcar_thermal_update_temp to properly handle its return > value and propagate that error code when necessary? Thanks. But the logic is that priv->ctemp will be 0 in error cases, and it will be reported as dev_err() in rcar_thermal_get_current_temp() The problem was that priv->ctemp will not be updated in error case of rcar_thermal_update_temp(). but user can call get_temp (it doesn't call rcar_thermal_update_temp() if interrupt was supported). In such case, user will get old thermal. -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Eduardo, again > I believe the problem here is actually the lack of error > handling/propagation. Are you sure you want to write to parameter > in the fail path ? > > rcar_thermal_update_temp already returns error code when it fails > to read temperature. Don't you think it would make more sense to fix the > places that call rcar_thermal_update_temp to properly handle its return > value and propagate that error code when necessary? Will update in v5 -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c index 67b5216..40c3ba5 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); @@ -218,9 +219,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; }