Skip to content

Commit 68dabf4

Browse files
tobluxdlezcano
authored andcommitted
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>
1 parent 8672be1 commit 68dabf4

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

drivers/thermal/broadcom/bcm2835_thermal.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/err.h>
1212
#include <linux/io.h>
1313
#include <linux/kernel.h>
14+
#include <linux/minmax.h>
1415
#include <linux/module.h>
1516
#include <linux/of.h>
1617
#include <linux/of_address.h>
@@ -80,12 +81,7 @@ static int bcm2835_thermal_temp2adc(int temp, int offset, int slope)
8081
temp -= offset;
8182
temp /= slope;
8283

83-
if (temp < 0)
84-
temp = 0;
85-
if (temp >= BIT(BCM2835_TS_TSENSSTAT_DATA_BITS))
86-
temp = BIT(BCM2835_TS_TSENSSTAT_DATA_BITS) - 1;
87-
88-
return temp;
84+
return clamp(temp, 0, (int)BIT(BCM2835_TS_TSENSSTAT_DATA_BITS) - 1);
8985
}
9086

9187
static int bcm2835_thermal_get_temp(struct thermal_zone_device *tz, int *temp)

0 commit comments

Comments
 (0)