[PATCH] thermal/debugfs: Fix truncated cooling state transitions
From: Sumeet Pawnikar
Date: Fri Nov 20 2026 - 13:24:14 EST
cdev_tt_seq_show() can truncate cooling device transition labels
in the trans_table debugfs output. The largest packed label,
"65535->65535" needs 13 bytes including the terminator. A W=1
build exposes this problem as a format-truncation error.
The buffer was sized for an assumed maximum cooling state of 1024,
but the transition identifier reserves 16 bits for each state and
does not enforce that assumption. The signed identifier was also
shifted directly, which can sign-extend the upper state when bit
number 31 is set.
Decode the packed identifier through a u32 and size the buffer
from the largest representable transition string. This prevents
truncation and prints both state fields as unsigned values.
Issue reproduced and verified with a W=1 build.
Fixes: 755113d76786 ("thermal/debugfs: Add thermal cooling device debugfs information")
Signed-off-by: Sumeet Pawnikar <sumeet4linux@xxxxxxxxx>
---
drivers/thermal/thermal_debugfs.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/thermal/thermal_debugfs.c b/drivers/thermal/thermal_debugfs.c
index da02d8f179b0..107569d12965 100644
--- a/drivers/thermal/thermal_debugfs.c
+++ b/drivers/thermal/thermal_debugfs.c
@@ -322,14 +322,11 @@ static int cdev_tt_seq_show(struct seq_file *s, void *v)
seq_puts(s, "Transition\tOccurrences\n");
list_for_each_entry(entry, &transitions[i], node) {
- /*
- * Assuming maximum cdev states is 1024, the longer
- * string for a transition would be "1024->1024\0"
- */
- char buffer[11];
+ u32 transition = entry->id;
+ char buffer[sizeof("65535->65535")];
- snprintf(buffer, ARRAY_SIZE(buffer), "%d->%d",
- entry->id >> 16, entry->id & 0xFFFF);
+ snprintf(buffer, sizeof(buffer), "%u->%u",
+ transition >> 16, transition & 0xffff);
seq_printf(s, "%-10s\t%-10llu\n", buffer, entry->count);
}
--
2.53.0