[PATCH] tools/thermal/tmon: propagate fscanf failure in sysfs_get_ulong()
From: Gu Bin
Date: Fri Nov 13 2026 - 02:44:13 EST
sysfs_get_ulong() always returns 0, masking a fscanf() failure, so
find_tzone_tp() cannot detect a malformed trip point temperature file
and reads the uninitialized temp_ulong. The sibling sysfs_get_string()
returns its ret.
Return the fscanf() result from sysfs_get_ulong() and have
find_tzone_tp() skip the entry when the read fails. This also makes
the check honor the "ignore 0/invalid trip points" comment above it:
previously a failed read left the caller-dependent stack value to the
temp_ulong < MAX_TEMP_KC comparison, so a garbage or zero temperature
could be counted as a valid trip point and later drawn as a bogus
marker in the TUI thermal data window.
Return 0 rather than -1 from find_tzone_tp() on the skipped entry so
the scan_tzones() loop keeps running, avoiding the early break that
would leak the remaining scandir() namelist entries.
Fixes: 94f69966faf8 ("tools/thermal: Introduce tmon, a tool for thermal subsystem")
Signed-off-by: Gu Bin <gubin@xxxxxxxxxxxxxxxxxxxx>
---
tools/thermal/tmon/sysfs.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/tools/thermal/tmon/sysfs.c b/tools/thermal/tmon/sysfs.c
index 5d64aff12a86..7f1e38276254 100644
--- a/tools/thermal/tmon/sysfs.c
+++ b/tools/thermal/tmon/sysfs.c
@@ -70,7 +70,7 @@ static int sysfs_get_ulong(char *path, char *filename, unsigned long *p_ulong)
ret = fscanf(fd, "%lu", p_ulong);
fclose(fd);
- return 0;
+ return ret;
}
static int sysfs_get_string(char *path, char *filename, char *str)
@@ -167,14 +167,15 @@ static int find_tzone_tp(char *tz_name, char *d_name, struct tz_info *tzi,
int tz_id)
{
int tp_id;
- unsigned long temp_ulong;
+ unsigned long temp_ulong = 0;
if (strstr(d_name, "trip_point") &&
strstr(d_name, "temp")) {
/* check if trip point temp is non-zero
* ignore 0/invalid trip points
*/
- sysfs_get_ulong(tz_name, d_name, &temp_ulong);
+ if (sysfs_get_ulong(tz_name, d_name, &temp_ulong) != 1)
+ return 0;
if (temp_ulong < MAX_TEMP_KC) {
tzi->nr_trip_pts++;
/* found a valid trip point */
--
2.55.0.windows.3