]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rtla: Use str_has_prefix() for prefix checks
authorWander Lairson Costa <wander@redhat.com>
Mon, 9 Mar 2026 19:46:24 +0000 (16:46 -0300)
committerTomas Glozar <tglozar@redhat.com>
Wed, 11 Mar 2026 14:29:50 +0000 (15:29 +0100)
The code currently uses strncmp() combined with strlen() to check if a
string starts with a specific prefix. This pattern is verbose and prone
to errors if the length does not match the prefix string.

Replace this pattern with the str_has_prefix() helper function in both
trace.c and utils.c. This improves code readability and safety by
handling the prefix length calculation automatically.

In addition, remove the unused retval variable from
trace_event_save_hist() in trace.c to clean up the function and
silence potential compiler warnings.

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

index 2f529aaf8deef29904e9a04ca713a17ddb78130d..ed7db5f4115ceb4bdbd4e2b569eb27d6340266c4 100644 (file)
@@ -342,7 +342,7 @@ static void trace_event_disable_filter(struct trace_instance *instance,
 static void trace_event_save_hist(struct trace_instance *instance,
                                  struct trace_events *tevent)
 {
-       int retval, index, out_fd;
+       int index, out_fd;
        mode_t mode = 0644;
        char path[MAX_PATH];
        char *hist;
@@ -356,8 +356,7 @@ static void trace_event_save_hist(struct trace_instance *instance,
                return;
 
        /* is this a hist: trigger? */
-       retval = strncmp(tevent->trigger, "hist:", strlen("hist:"));
-       if (retval)
+       if (!str_has_prefix(tevent->trigger, "hist:"))
                return;
 
        snprintf(path, ARRAY_SIZE(path), "%s_%s_hist.txt", tevent->system, tevent->event);
index ce8b1aa012ecf7197c10a4c77338f8c9007ef55d..89ccacb97ef708ef608891d729edf02afdbd4604 100644 (file)
@@ -331,8 +331,7 @@ static int procfs_is_workload_pid(const char *comm_prefix, struct dirent *proc_e
                return 0;
 
        buffer[MAX_PATH-1] = '\0';
-       retval = strncmp(comm_prefix, buffer, strlen(comm_prefix));
-       if (retval)
+       if (!str_has_prefix(buffer, comm_prefix))
                return 0;
 
        /* comm already have \n */