From: Thorsten Blum Date: Mon, 5 Jan 2026 12:13:03 +0000 (+0100) Subject: thermal/drivers/broadcom: Use clamp to simplify bcm2835_thermal_temp2adc X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=68dabf4ebe0ec2f9a51d3fdc17b1ec64500b7ed4;p=thirdparty%2Fkernel%2Flinux.git 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 Reviewed-by: Luca Ceresoli Link: https://patch.msgid.link/20260105121308.1761-1-thorsten.blum@linux.dev Signed-off-by: Daniel Lezcano --- diff --git a/drivers/thermal/broadcom/bcm2835_thermal.c b/drivers/thermal/broadcom/bcm2835_thermal.c index 685a5aee5e0df..c5105dfc6ec97 100644 --- a/drivers/thermal/broadcom/bcm2835_thermal.c +++ b/drivers/thermal/broadcom/bcm2835_thermal.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -80,12 +81,7 @@ static int bcm2835_thermal_temp2adc(int temp, int offset, int slope) temp -= offset; temp /= slope; - if (temp < 0) - temp = 0; - if (temp >= BIT(BCM2835_TS_TSENSSTAT_DATA_BITS)) - temp = BIT(BCM2835_TS_TSENSSTAT_DATA_BITS) - 1; - - return temp; + return clamp(temp, 0, (int)BIT(BCM2835_TS_TSENSSTAT_DATA_BITS) - 1); } static int bcm2835_thermal_get_temp(struct thermal_zone_device *tz, int *temp)