Skip to content

Commit 5f8f064

Browse files
DienPhamMdlezcano
authored andcommitted
thermal/drivers/rcar_gen3: Fix undefined temperature if negative
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 cleanup. Signed-off-by: Van Do <[email protected]> Signed-off-by: Dien Pham <[email protected]> [shimoda: minor fixes, add Fixes tag] Fixes: 564e73d ("thermal: rcar_gen3_thermal: Add R-Car Gen3 thermal driver") Signed-off-by: Yoshihiro Shimoda <[email protected]> Reviewed-by: Niklas Soderlund <[email protected]> Tested-by: Niklas Soderlund <[email protected]> Reviewed-by: Amit Kucheria <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/1593085099-2057-1-git-send-email-yoshihiro.shimoda.uh@renesas.com
1 parent 371a3bc commit 5f8f064

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/thermal/rcar_gen3_thermal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static int rcar_gen3_thermal_get_temp(void *devdata, int *temp)
167167
{
168168
struct rcar_gen3_thermal_tsc *tsc = devdata;
169169
int mcelsius, val;
170-
u32 reg;
170+
int reg;
171171

172172
/* Read register and convert to mili Celsius */
173173
reg = rcar_gen3_thermal_read(tsc, REG_GEN3_TEMP) & CTEMP_MASK;

0 commit comments

Comments
 (0)