From nobody Mon Dec 1 22:03:59 2025 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BE1D10F1 for ; Mon, 1 Dec 2025 00:08:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764547694; cv=none; b=iSDaGUqDlfCxMIe2s8UnaaF0T3raIlIYXvCVhWzG8lV4VZN/54/ZRUGHLIPWNL9hjOA6NNpoFgDxRhPHx2P7Oe23rhulCLBMI4lVttwTXTspzQmWvYIO40qCW4e7WKLamPy/9DVCe2UpJKc61Y2VbaE2vjEf9zjEIsjDs8iMf7I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764547694; c=relaxed/simple; bh=b+1xAFRCtHQMGDBpzmF2Xs9hsAV+Ssxx7l/FQeK6AGU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Rlnup3b7azjybAxgkaUAiJAjDR8LGlg1aQZ/RdIVBgz7uvptQFQCktnuizyNlC7Z9myEoSRdV5FLofLy9qWT9uH/CPLzFo3mvDhR+ZGIFvfsEvJxHiGBELeRDEEUlCQm1t/9nQ0nG4EB5powR0z3KkijQpP9aaRz20pZrOyfHpw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=coaP8mRe; arc=none smtp.client-ip=91.218.175.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="coaP8mRe" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1764547685; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=uCNF53Li60QdPXxf/q2DlB7bjSdyWe25Wed4MJMg7yg=; b=coaP8mReT1H7VX76ICiZUOitVVGjcUrWSnvZFHLeCLfv2BbATVaykMbq2LQRNsQqNuTH1D fNzipGLA/HIxuDPic5mDEF6AyfUUl+mxfjW9QQ+R9N2ncErc72vco0GGMlRbLZU3N1SbDw c5c6uI113EKlcXqaD2QDC2qjeJNM5ns= From: Thorsten Blum To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Florian Fainelli , Ray Jui , Scott Branden , Broadcom internal kernel review list , Luca Ceresoli , Geert Uytterhoeven Cc: Thorsten Blum , linux-pm@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] thermal: broadcom: Use clamp() to simplify bcm2835_thermal_temp2adc() Date: Mon, 1 Dec 2025 01:07:09 +0100 Message-ID: <20251201000714.74752-2-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" 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 --- drivers/thermal/broadcom/bcm2835_thermal.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/thermal/broadcom/bcm2835_thermal.c b/drivers/thermal/b= roadcom/bcm2835_thermal.c index 685a5aee5e0d..c5105dfc6ec9 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 -=3D offset; temp /=3D slope; =20 - if (temp < 0) - temp =3D 0; - if (temp >=3D BIT(BCM2835_TS_TSENSSTAT_DATA_BITS)) - temp =3D BIT(BCM2835_TS_TSENSSTAT_DATA_BITS) - 1; - - return temp; + return clamp(temp, 0, (int)BIT(BCM2835_TS_TSENSSTAT_DATA_BITS) - 1); } =20 static int bcm2835_thermal_get_temp(struct thermal_zone_device *tz, int *t= emp) --=20 Thorsten Blum GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4