Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thermal/drivers/broadcom: Use clamp to simplify bcm2835_thermal_temp2adc

Use clamp() to simplify bcm2835_thermal_temp2adc() and improve its
readability. Explicitly cast BIT() to int to prevent a signedness error.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Link: https://patch.msgid.link/20260105121308.1761-1-thorsten.blum@linux.dev
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

authored by

Thorsten Blum and committed by
Daniel Lezcano
68dabf4e 8672be1c

+2 -6
+2 -6
drivers/thermal/broadcom/bcm2835_thermal.c
··· 11 11 #include <linux/err.h> 12 12 #include <linux/io.h> 13 13 #include <linux/kernel.h> 14 + #include <linux/minmax.h> 14 15 #include <linux/module.h> 15 16 #include <linux/of.h> 16 17 #include <linux/of_address.h> ··· 81 80 temp -= offset; 82 81 temp /= slope; 83 82 84 - if (temp < 0) 85 - temp = 0; 86 - if (temp >= BIT(BCM2835_TS_TSENSSTAT_DATA_BITS)) 87 - temp = BIT(BCM2835_TS_TSENSSTAT_DATA_BITS) - 1; 88 - 89 - return temp; 83 + return clamp(temp, 0, (int)BIT(BCM2835_TS_TSENSSTAT_DATA_BITS) - 1); 90 84 } 91 85 92 86 static int bcm2835_thermal_get_temp(struct thermal_zone_device *tz, int *temp)