mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] tools thermal tmon: Fix signed shift UB in binding display
@ 2026-09-03  8:28 liujing
  2026-09-28 16:39 ` Daniel Lezcano
  0 siblings, 1 reply; 2+ messages in thread
From: liujing @ 2026-09-03  8:28 UTC (permalink / raw)
  To: Rafael J . Wysocki, Daniel Lezcano
  Cc: Zhang Rui, Lukasz Luba, linux-pm, linux-kernel, Liu Jing

From: Liu Jing <liujing@cmss.chinamobile.com>

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@cmss.chinamobile.com>
---
--- 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",





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

* Re: [PATCH] tools thermal tmon: Fix signed shift UB in binding display
  2026-09-03  8:28 [PATCH] tools thermal tmon: Fix signed shift UB in binding display liujing
@ 2026-09-28 16:39 ` Daniel Lezcano
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Lezcano @ 2026-09-28 16:39 UTC (permalink / raw)
  To: liujing, Rafael J . Wysocki, Daniel Lezcano
  Cc: Zhang Rui, Lukasz Luba, linux-pm, linux-kernel

On 9/3/26 10:28, liujing wrote:
> From: Liu Jing <liujing@cmss.chinamobile.com>
> 
> 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@cmss.chinamobile.com>
> ---
Applied, thanks

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

end of thread, other threads:[~2026-09-28 16:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-03  8:28 [PATCH] tools thermal tmon: Fix signed shift UB in binding display liujing
2026-09-28 16:39 ` Daniel Lezcano

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

all inboxes | Powered by JetHome®