Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rtla: Use str_has_prefix() for prefix checks

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>

authored by

Wander Lairson Costa and committed by
Tomas Glozar
265905df 0f4bc9d6

+3 -5
+2 -3
tools/tracing/rtla/src/trace.c
··· 342 342 static void trace_event_save_hist(struct trace_instance *instance, 343 343 struct trace_events *tevent) 344 344 { 345 - int retval, index, out_fd; 345 + int index, out_fd; 346 346 mode_t mode = 0644; 347 347 char path[MAX_PATH]; 348 348 char *hist; ··· 356 356 return; 357 357 358 358 /* is this a hist: trigger? */ 359 - retval = strncmp(tevent->trigger, "hist:", strlen("hist:")); 360 - if (retval) 359 + if (!str_has_prefix(tevent->trigger, "hist:")) 361 360 return; 362 361 363 362 snprintf(path, ARRAY_SIZE(path), "%s_%s_hist.txt", tevent->system, tevent->event);
+1 -2
tools/tracing/rtla/src/utils.c
··· 331 331 return 0; 332 332 333 333 buffer[MAX_PATH-1] = '\0'; 334 - retval = strncmp(comm_prefix, buffer, strlen(comm_prefix)); 335 - if (retval) 334 + if (!str_has_prefix(buffer, comm_prefix)) 336 335 return 0; 337 336 338 337 /* comm already have \n */