[PATCH] tools thermal tmon: Fix signed shift UB in binding display
From: liujing
Date: Thu Sep 03 2026 - 04:59:55 EST
From: Liu Jing <liujing@xxxxxxxxxxxxxxxxxxxx>
In the thermal zone binding display loop, the expression `(1 << j)`
performs a signed integer shift. When j reaches 31, this sets the
sign bit of a 32-bit signed integer, which is undefined behavior.
Fix it by using `(1U << j)` to perform an unsigned shift.
Signed-off-by: Liu Jing <liujing@xxxxxxxxxxxxxxxxxxxx>
---
--- a/tools/thermal/tmon/tmon.c
+++ b/tools/thermal/tmon/tmon.c
@@ -171,7 +171,7 @@
memset(binding_str, 0, sizeof(binding_str));
for (j = 0; j < 32; j++)
- binding_str[j] = (ptdata.tzi[i].cdev_binding & (1 << j)) ?
+ binding_str[j] = (ptdata.tzi[i].cdev_binding & (1U << j)) ?
'1' : '0';
fprintf(tmon_log, "#thermal zone %s%02d cdevs binding: %32s\n",