diff mbox series

[2/4] thermal/drivers/qcom: Simplify function code_to_degc()

Message ID 20220713145655.3844109-3-carlos.bilbao@amd.com
State New
Headers show
Series thermal/drivers/qcom: Code refactoring | expand

Commit Message

Carlos Bilbao July 13, 2022, 2:56 p.m. UTC
Simplify code_to_degc() so we don't need a third variable.

Signed-off-by: Carlos Bilbao <carlos.bilbao@amd.com>
---
 drivers/thermal/qcom/tsens-common.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
diff mbox series

Patch

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)