Simplify code_to_degc() so we don't need a third variable. Signed-off-by: Carlos Bilbao <carlos.bilbao@xxxxxxx> --- drivers/thermal/qcom/tsens-common.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c index 528df8801254..492b0e9cc2a2 100644 --- a/drivers/thermal/qcom/tsens-common.c +++ b/drivers/thermal/qcom/tsens-common.c @@ -66,21 +66,18 @@ void compute_intercept_slope(struct tsens_priv *priv, u32 *p1, static inline int code_to_degc(u32 adc_code, const struct tsens_sensor *s) { - int degc, num, den; + int num, den; num = (adc_code * SLOPE_FACTOR) - s->offset; den = s->slope; + if (!num) + return 0; + if (num > 0) - degc = num + (den / 2); - else if (num < 0) - degc = num - (den / 2); + return (num + (den / 2)) / den; else - degc = num; - - degc /= den; - - return degc; + return (num - (den / 2)) / den; } int get_temp_tsens_valid(struct tsens_priv *priv, int i, int *temp) -- 2.31.1