Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/xe/hwmon: Restrict LONG_MAX overflow check to 32-bit builds
@ 2026-10-23  8:29 Mallesh Koujalagi
  2026-10-23  8:37 ` ✓ CI.KUnit: success for " Patchwork
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Mallesh Koujalagi @ 2026-10-23  8:29 UTC (permalink / raw)
  To: intel-xe, rodrigo.vivi, matthew.brost
  Cc: anshuman.gupta, badal.nilawar, vinay.belgaumkar, riana.tauro,
	karthik.poosa, sk.anirban, raag.jadav, aravind.iddamsetty,
	Mallesh Koujalagi

The temperature decoding code stores the intermediate result in an
s64 and checks it against LONG_MAX before assigning it to a long.

This check is only needed on 32-bit architectures, where long is
narrower than s64. On 64-bit systems, long and s64 are both 64 bits,
so the condition can never be true.

Wrap the check with BITS_PER_LONG == 32 so it is only compiled where
it is needed, preserving the existing overflow protection on 32-bit
architectures while eliminating the dead branch on 64-bit builds.

Fixes: 24ec15d64617 ("drm/xe/hwmon: Decode CRI temperature registers as IEEE-754")
Signed-off-by: Mallesh Koujalagi <mallesh.koujalagi@intel.com>
---
 drivers/gpu/drm/xe/xe_hwmon.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c
index 42acfeb8818c..2ee51921acf5 100644
--- a/drivers/gpu/drm/xe/xe_hwmon.c
+++ b/drivers/gpu/drm/xe/xe_hwmon.c
@@ -1322,9 +1322,14 @@ static int xe_hwmon_temperature_decode(u32 reg_val, long *temperature)
 		value = 0;
 	}
 
-	/* Ensure the magnitude fits in long, which is 32-bit on some arches. */
+#if BITS_PER_LONG == 32
+	/*
+	 * On 32-bit systems, long is smaller than s64, so the value may
+	 * still overflow long even if it fits in s64.
+	 */
 	if (value > LONG_MAX)
 		return -ERANGE;
+#endif
 
 	if (reg_val & IEEE754_SIGN)
 		value = -value;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-10-23 13:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-23  8:29 [PATCH] drm/xe/hwmon: Restrict LONG_MAX overflow check to 32-bit builds Mallesh Koujalagi
2026-10-23  8:37 ` ✓ CI.KUnit: success for " Patchwork
2026-10-23  9:24 ` ✓ Xe.CI.BAT: " Patchwork
2026-10-23 11:20 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-10-23 11:58 ` [PATCH] " Jani Nikula
2026-10-23 12:51   ` Mallesh, Koujalagi
2026-10-23 13:01     ` Jani Nikula

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox