Commit 68dabf4e authored by Thorsten Blum's avatar Thorsten Blum Committed by Daniel Lezcano
Browse files

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: default avatarThorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: default avatarLuca Ceresoli <luca.ceresoli@bootlin.com>
Link: https://patch.msgid.link/20260105121308.1761-1-thorsten.blum@linux.dev


Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
parent 8672be1c
Loading
Loading
Loading
Loading
+2 −6
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
#include <linux/err.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/minmax.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_address.h>
@@ -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)