]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
rtla/utils: Fix loop condition in PID validation
authorWander Lairson Costa <wander@redhat.com>
Mon, 9 Mar 2026 19:46:31 +0000 (16:46 -0300)
committerTomas Glozar <tglozar@redhat.com>
Wed, 11 Mar 2026 14:29:50 +0000 (15:29 +0100)
The procfs_is_workload_pid() function iterates through a directory
entry name to validate if it represents a process ID. The loop
condition checks if the pointer t_name is non-NULL, but since
incrementing a pointer never makes it NULL, this condition is always
true within the loop's context. Although the inner isdigit() check
catches the NUL terminator and breaks out of the loop, the condition
is semantically misleading and not idiomatic for C string processing.

Correct the loop condition from checking the pointer (t_name) to
checking the character it points to (*t_name). This ensures the loop
terminates when the NUL terminator is reached, aligning with standard
C string iteration practices. While the original code functioned
correctly due to the existing character validation, this change
improves code clarity and maintainability.

Signed-off-by: Wander Lairson Costa <wander@redhat.com>
Link: https://lore.kernel.org/r/20260309195040.1019085-19-wander@redhat.com
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
tools/tracing/rtla/src/utils.c

index 80b7eb7b6a7a2ff6f2f1649ce88bd5fe0f7c9bcd..9cec5b3e02c88ee33beb1f1ef7ccf026f9e5d676 100644 (file)
@@ -324,7 +324,7 @@ static int procfs_is_workload_pid(const char *comm_prefix, struct dirent *proc_e
                return 0;
 
        /* check if the string is a pid */
-       for (t_name = proc_entry->d_name; t_name; t_name++) {
+       for (t_name = proc_entry->d_name; *t_name; t_name++) {
                if (!isdigit(*t_name))
                        break;
        }