From nobody Sat Feb 7 15:11:00 2026 Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) (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 D4096334C20 for ; Mon, 5 Jan 2026 12:13:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767615200; cv=none; b=PdsLoVraZx9iRex6c9lC13ykk2l0hvSXiagmnqP2cuFQuLRpcoVTXOMkXsawS/BEgi/20TF+CdrlD4l5szQt8fQZCIaZNUC/v3f2I/b0HdQDWZfnGqdCOt05RclMpFRIcYM3utzM8z3U5WMv7YDdCMLYbyJWBg2Or4jG6Sxexkg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767615200; c=relaxed/simple; bh=4cLdNFYkRy+cmFYJFX8QQFZ4tNGG1bMNcj6dmpLj/CM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=BlV/fr9vXbm4/goMMki5dkjVydZJXB4FDxPyRVZeiOqEx57yPSTyguQ4eJLZVjom8ZjQOBy6X9lol2FafMmFXff2dwvnhYiVcJC3727EgUamk0CsPNZcZD3HtYBwcx9nEQIIhwrD9ebe7Y+Jyb1LIZVOCygTB3CA8bv5r6ACy4I= 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=CJC3xu91; arc=none smtp.client-ip=95.215.58.172 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="CJC3xu91" 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=1767615195; 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=tmsC7tVniwT8Wa+M6xzLWHZmhRLH7ixcu3nderl3sVI=; b=CJC3xu91f8z5MbjqZWTN3ji6eUc+2M8SkU0lULgvVcv6kFMaSlzxBLzNIhAC1dYxF3/KX6 UTBWDtRTNwYgWUnrm/MXi8TuxktMs62H0KvoeTthaM18dO1zh8BKT4DUs6DKYYedTqMt6r a4sdCA8V2JqI8UMjf9ATjdLy3bZWDko= From: Thorsten Blum To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Florian Fainelli , Broadcom internal kernel review list , Ray Jui , Scott Branden , 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 RESEND] thermal: broadcom: Use clamp to simplify bcm2835_thermal_temp2adc Date: Mon, 5 Jan 2026 13:13:03 +0100 Message-ID: <20260105121308.1761-1-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 Reviewed-by: Luca Ceresoli --- 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)