blob: 4fef76634714d63e9df787a8cfdfc44cceda5b35 [file] [log] [blame]
From c4c4727cbe9f221e428f9bbe89c20a5025aeea9a Mon Sep 17 00:00:00 2001
From: Dien Pham <>
Date: Thu, 25 Jun 2020 20:38:19 +0900
Subject: [PATCH] thermal/drivers/rcar_gen3: Fix undefined temperature if
commit 5f8f06425a0dcdad7bedbb77e67f5c65ab4dacfc upstream.
As description for DIV_ROUND_CLOSEST in file include/linux/kernel.h.
"Result is undefined for negative divisors if the dividend variable
type is unsigned and for negative dividends if the divisor variable
type is unsigned."
In current code, the FIXPT_DIV uses DIV_ROUND_CLOSEST but has not
checked sign of divisor before using. It makes undefined temperature
value in case the value is negative.
This patch fixes to satisfy DIV_ROUND_CLOSEST description
and fix bug too. Note that the variable name "reg" is not good
because it should be the same type as rcar_gen3_thermal_read().
However, it's better to rename the "reg" in a further patch as
Signed-off-by: Van Do <>
Signed-off-by: Dien Pham <>
[shimoda: minor fixes, add Fixes tag]
Fixes: 564e73d283af ("thermal: rcar_gen3_thermal: Add R-Car Gen3 thermal driver")
Signed-off-by: Yoshihiro Shimoda <>
Reviewed-by: Niklas Soderlund <>
Tested-by: Niklas Soderlund <>
Reviewed-by: Amit Kucheria <>
Signed-off-by: Daniel Lezcano <>
Signed-off-by: Paul Gortmaker <>
diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c
index a56463308694..7a890bde4cff 100644
--- a/drivers/thermal/rcar_gen3_thermal.c
+++ b/drivers/thermal/rcar_gen3_thermal.c
@@ -169,7 +169,7 @@ static int rcar_gen3_thermal_get_temp(void *devdata, int *temp)
struct rcar_gen3_thermal_tsc *tsc = devdata;
int mcelsius, val;
- u32 reg;
+ int reg;
/* Read register and convert to mili Celsius */
reg = rcar_gen3_thermal_read(tsc, REG_GEN3_TEMP) & CTEMP_MASK;