Commit b03628b7 authored by Niklas Söderlund's avatar Niklas Söderlund Committed by Daniel Lezcano
Browse files

thermal: rcar_thermal: Clean up rcar_thermal_update_temp()



Moving the ctemp variable out of the private data structure made it
possible to clean up rcar_thermal_update_temp(). Initialize the local
ctemp to the error code to return if the reading fails and just return
it at the end of the function.

It's OK to change the datatype of old, new and ctemp to int as all
values are ANDed with CTEMP (0x3f) before being stored. While at it
change the datatype of the loop variable 'i' to to unsigned int.

Suggested-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: default avatarNiklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20200514152505.1927634-1-niklas.soderlund+renesas@ragnatech.se
parent 1ab20c0e
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -198,8 +198,8 @@ static void _rcar_thermal_bset(struct rcar_thermal_priv *priv, u32 reg,
static int rcar_thermal_update_temp(struct rcar_thermal_priv *priv)
{
	struct device *dev = rcar_priv_to_dev(priv);
	int i;
	u32 ctemp, old, new;
	int old, new, ctemp = -EINVAL;
	unsigned int i;

	mutex_lock(&priv->lock);

@@ -209,7 +209,6 @@ static int rcar_thermal_update_temp(struct rcar_thermal_priv *priv)
	 */
	rcar_thermal_bset(priv, THSCR, CPCTL, CPCTL);

	ctemp = 0;
	old = ~0;
	for (i = 0; i < 128; i++) {
		/*
@@ -227,7 +226,7 @@ static int rcar_thermal_update_temp(struct rcar_thermal_priv *priv)
		old = new;
	}

	if (!ctemp) {
	if (ctemp < 0) {
		dev_err(dev, "thermal sensor was broken\n");
		goto err_out_unlock;
	}
@@ -248,7 +247,7 @@ static int rcar_thermal_update_temp(struct rcar_thermal_priv *priv)
err_out_unlock:
	mutex_unlock(&priv->lock);

	return ctemp ? ctemp : -EINVAL;
	return ctemp;
}

static int rcar_thermal_get_current_temp(struct rcar_thermal_priv *priv,