From nobody Sun Feb 8 06:00:00 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D80623AEF27 for ; Thu, 15 Jan 2026 17:24:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497892; cv=none; b=M42UxSm6prgiZlJu6b3AJIUv6Dzcr4ecsRmwPE+dMV6kwv/DIMHd4CTUaBuUbb/w+AfhkHWKj3WBwpo3L9KJnFaNQXvOZqDC5Jm0cWOgYB734O+Zudh66HVBlmcxzyXPVF8a7LwJS5ApztSVv4P+GF1sssR3kqJxVjEQTrvw6MU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497892; c=relaxed/simple; bh=lpv/5z9xSeKmIzg4U8Z/mGk6pdKQOx9JE/ymYcbtrKk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SvWz1hEBpjefgwS4cEuVRqna4JEzzC6bKKPSfnT5sOIKScTmBu1g/4wiArqEuqhLPq4oPHPEmS9Z1XPK9xpukmAHm8O9jN7X6YRGWS/9mcyMrHd5dNduLsEkkaP28AfvNA3/c0sK6VFdxlMEvQxMnoo/4Ihmc/+oyZELa8NhOws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=OOjD4v4g; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OOjD4v4g" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768497890; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jpVUckxFnqqTc+pbFGmUzfoOXq0tLVqdR2qqu4/NzrM=; b=OOjD4v4gfZN5LamnzRNn9M4wID9k++/0L8DmjseixhT/IHyO42/lKOWA4JOv9qlpQ1SSOM 9tGA2o8amrZOM2CWasfOxDMmOZ4FzsKbIygk2KlNOnnJhwgY08pqo8oar61qrqFciqdsD3 gNZAThJrtw0Uy/1gAjAtw27Awr9lKXc= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-626-uPkaOWbAN2m81idWKl3kbw-1; Thu, 15 Jan 2026 12:24:46 -0500 X-MC-Unique: uPkaOWbAN2m81idWKl3kbw-1 X-Mimecast-MFC-AGG-ID: uPkaOWbAN2m81idWKl3kbw_1768497885 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7A3DE1800357; Thu, 15 Jan 2026 17:24:44 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 112791800285; Thu, 15 Jan 2026 17:24:38 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Haiyong Sun , Tiezhu Yang , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 01/18] rtla: Exit on memory allocation failures during initialization Date: Thu, 15 Jan 2026 13:31:44 -0300 Message-ID: <20260115163650.118910-2-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Most memory allocations in rtla happen during early initialization before any resources are acquired that would require cleanup. In these cases, propagating allocation errors just adds complexity without any benefit. There's nothing to clean up, and the program must exit anyway. This patch introduces fatal allocation wrappers (calloc_fatal, reallocarray_fatal, strdup_fatal) that call fatal() on allocation failure. These wrappers simplify the code by eliminating unnecessary error propagation paths. The patch converts early allocations to use these wrappers in actions_init() and related action functions, osnoise_context_alloc() and osnoise_init_tool(), trace_instance_init() and trace event functions, and parameter structure allocations in main functions. This simplifies the code while maintaining the same behavior: immediate exit on allocation failure during initialization. Allocations that require cleanup, such as those in histogram allocation functions with goto cleanup paths, are left unchanged and continue to return errors. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/actions.c | 50 ++++++++++++-------------- tools/tracing/rtla/src/actions.h | 8 ++--- tools/tracing/rtla/src/osnoise.c | 22 ++++-------- tools/tracing/rtla/src/osnoise_hist.c | 22 ++++-------- tools/tracing/rtla/src/osnoise_top.c | 22 ++++-------- tools/tracing/rtla/src/timerlat_hist.c | 22 ++++-------- tools/tracing/rtla/src/timerlat_top.c | 22 ++++-------- tools/tracing/rtla/src/trace.c | 30 ++++------------ tools/tracing/rtla/src/trace.h | 4 +-- tools/tracing/rtla/src/utils.c | 35 ++++++++++++++++++ tools/tracing/rtla/src/utils.h | 3 ++ 11 files changed, 108 insertions(+), 132 deletions(-) diff --git a/tools/tracing/rtla/src/actions.c b/tools/tracing/rtla/src/acti= ons.c index a42615011962d..22b8283a183f3 100644 --- a/tools/tracing/rtla/src/actions.c +++ b/tools/tracing/rtla/src/actions.c @@ -15,7 +15,7 @@ void actions_init(struct actions *self) { self->size =3D action_default_size; - self->list =3D calloc(self->size, sizeof(struct action)); + self->list =3D calloc_fatal(self->size, sizeof(struct action)); self->len =3D 0; self->continue_flag =3D false; =20 @@ -50,8 +50,10 @@ static struct action * actions_new(struct actions *self) { if (self->len >=3D self->size) { - self->size *=3D 2; - self->list =3D realloc(self->list, self->size * sizeof(struct action)); + const size_t new_size =3D self->size * 2; + + self->list =3D reallocarray_fatal(self->list, new_size, sizeof(struct ac= tion)); + self->size =3D new_size; } =20 return &self->list[self->len++]; @@ -60,25 +62,21 @@ actions_new(struct actions *self) /* * actions_add_trace_output - add an action to output trace */ -int +void actions_add_trace_output(struct actions *self, const char *trace_output) { struct action *action =3D actions_new(self); =20 self->present[ACTION_TRACE_OUTPUT] =3D true; action->type =3D ACTION_TRACE_OUTPUT; - action->trace_output =3D calloc(strlen(trace_output) + 1, sizeof(char)); - if (!action->trace_output) - return -1; + action->trace_output =3D calloc_fatal(strlen(trace_output) + 1, sizeof(ch= ar)); strcpy(action->trace_output, trace_output); - - return 0; } =20 /* * actions_add_trace_output - add an action to send signal to a process */ -int +void actions_add_signal(struct actions *self, int signal, int pid) { struct action *action =3D actions_new(self); @@ -87,40 +85,32 @@ actions_add_signal(struct actions *self, int signal, in= t pid) action->type =3D ACTION_SIGNAL; action->signal =3D signal; action->pid =3D pid; - - return 0; } =20 /* * actions_add_shell - add an action to execute a shell command */ -int +void actions_add_shell(struct actions *self, const char *command) { struct action *action =3D actions_new(self); =20 self->present[ACTION_SHELL] =3D true; action->type =3D ACTION_SHELL; - action->command =3D calloc(strlen(command) + 1, sizeof(char)); - if (!action->command) - return -1; + action->command =3D calloc_fatal(strlen(command) + 1, sizeof(char)); strcpy(action->command, command); - - return 0; } =20 /* * actions_add_continue - add an action to resume measurement */ -int +void actions_add_continue(struct actions *self) { struct action *action =3D actions_new(self); =20 self->present[ACTION_CONTINUE] =3D true; action->type =3D ACTION_CONTINUE; - - return 0; } =20 /* @@ -176,7 +166,8 @@ actions_parse(struct actions *self, const char *trigger= , const char *tracefn) /* Only one argument allowed */ return -1; } - return actions_add_trace_output(self, trace_output); + actions_add_trace_output(self, trace_output); + break; case ACTION_SIGNAL: /* Takes two arguments, num (signal) and pid */ while (token !=3D NULL) { @@ -200,21 +191,26 @@ actions_parse(struct actions *self, const char *trigg= er, const char *tracefn) /* Missing argument */ return -1; =20 - return actions_add_signal(self, signal, pid); + actions_add_signal(self, signal, pid); + break; case ACTION_SHELL: if (token =3D=3D NULL) return -1; - if (strlen(token) > 8 && strncmp(token, "command=3D", 8) =3D=3D 0) - return actions_add_shell(self, token + 8); - return -1; + if (strlen(token) > 8 && strncmp(token, "command=3D", 8)) + return -1; + actions_add_shell(self, token + 8); + break; case ACTION_CONTINUE: /* Takes no argument */ if (token !=3D NULL) return -1; - return actions_add_continue(self); + actions_add_continue(self); + break; default: return -1; } + + return 0; } =20 /* diff --git a/tools/tracing/rtla/src/actions.h b/tools/tracing/rtla/src/acti= ons.h index fb77069c972ba..034048682fefb 100644 --- a/tools/tracing/rtla/src/actions.h +++ b/tools/tracing/rtla/src/actions.h @@ -49,9 +49,9 @@ struct actions { =20 void actions_init(struct actions *self); void actions_destroy(struct actions *self); -int actions_add_trace_output(struct actions *self, const char *trace_outpu= t); -int actions_add_signal(struct actions *self, int signal, int pid); -int actions_add_shell(struct actions *self, const char *command); -int actions_add_continue(struct actions *self); +void actions_add_trace_output(struct actions *self, const char *trace_outp= ut); +void actions_add_signal(struct actions *self, int signal, int pid); +void actions_add_shell(struct actions *self, const char *command); +void actions_add_continue(struct actions *self); int actions_parse(struct actions *self, const char *trigger, const char *t= racefn); int actions_perform(struct actions *self); diff --git a/tools/tracing/rtla/src/osnoise.c b/tools/tracing/rtla/src/osno= ise.c index 945eb61efc465..ec074cd53dd84 100644 --- a/tools/tracing/rtla/src/osnoise.c +++ b/tools/tracing/rtla/src/osnoise.c @@ -938,9 +938,7 @@ struct osnoise_context *osnoise_context_alloc(void) { struct osnoise_context *context; =20 - context =3D calloc(1, sizeof(*context)); - if (!context) - return NULL; + context =3D calloc_fatal(1, sizeof(*context)); =20 context->orig_stop_us =3D OSNOISE_OPTION_INIT_VAL; context->stop_us =3D OSNOISE_OPTION_INIT_VAL; @@ -1017,24 +1015,16 @@ void osnoise_destroy_tool(struct osnoise_tool *top) struct osnoise_tool *osnoise_init_tool(char *tool_name) { struct osnoise_tool *top; - int retval; - - top =3D calloc(1, sizeof(*top)); - if (!top) - return NULL; =20 + top =3D calloc_fatal(1, sizeof(*top)); top->context =3D osnoise_context_alloc(); - if (!top->context) - goto out_err; =20 - retval =3D trace_instance_init(&top->trace, tool_name); - if (retval) - goto out_err; + if (trace_instance_init(&top->trace, tool_name)) { + osnoise_destroy_tool(top); + return NULL; + } =20 return top; -out_err: - osnoise_destroy_tool(top); - return NULL; } =20 /* diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src= /osnoise_hist.c index 9d70ea34807ff..efbd2e834cf0e 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -466,9 +466,7 @@ static struct common_params int c; char *trace_output =3D NULL; =20 - params =3D calloc(1, sizeof(*params)); - if (!params) - exit(1); + params =3D calloc_fatal(1, sizeof(*params)); =20 actions_init(¶ms->common.threshold_actions); actions_init(¶ms->common.end_actions); @@ -579,22 +577,16 @@ static struct common_params params->common.hist.with_zeros =3D 1; break; case '4': /* trigger */ - if (params->common.events) { - retval =3D trace_event_add_trigger(params->common.events, optarg); - if (retval) - fatal("Error adding trigger %s", optarg); - } else { + if (params->common.events) + trace_event_add_trigger(params->common.events, optarg); + else fatal("--trigger requires a previous -e"); - } break; case '5': /* filter */ - if (params->common.events) { - retval =3D trace_event_add_filter(params->common.events, optarg); - if (retval) - fatal("Error adding filter %s", optarg); - } else { + if (params->common.events) + trace_event_add_filter(params->common.events, optarg); + else fatal("--filter requires a previous -e"); - } break; case '6': params->common.warmup =3D get_llong_from_str(optarg); diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/= osnoise_top.c index d54d47947fb44..d2b4ac64e77b4 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -319,9 +319,7 @@ struct common_params *osnoise_top_parse_args(int argc, = char **argv) int c; char *trace_output =3D NULL; =20 - params =3D calloc(1, sizeof(*params)); - if (!params) - exit(1); + params =3D calloc_fatal(1, sizeof(*params)); =20 actions_init(¶ms->common.threshold_actions); actions_init(¶ms->common.end_actions); @@ -410,22 +408,16 @@ struct common_params *osnoise_top_parse_args(int argc= , char **argv) params->threshold =3D get_llong_from_str(optarg); break; case '0': /* trigger */ - if (params->common.events) { - retval =3D trace_event_add_trigger(params->common.events, optarg); - if (retval) - fatal("Error adding trigger %s", optarg); - } else { + if (params->common.events) + trace_event_add_trigger(params->common.events, optarg); + else fatal("--trigger requires a previous -e"); - } break; case '1': /* filter */ - if (params->common.events) { - retval =3D trace_event_add_filter(params->common.events, optarg); - if (retval) - fatal("Error adding filter %s", optarg); - } else { + if (params->common.events) + trace_event_add_filter(params->common.events, optarg); + else fatal("--filter requires a previous -e"); - } break; case '2': params->common.warmup =3D get_llong_from_str(optarg); diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/sr= c/timerlat_hist.c index 4e8c38a61197c..6ea397421f1c9 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -766,9 +766,7 @@ static struct common_params int c; char *trace_output =3D NULL; =20 - params =3D calloc(1, sizeof(*params)); - if (!params) - exit(1); + params =3D calloc_fatal(1, sizeof(*params)); =20 actions_init(¶ms->common.threshold_actions); actions_init(¶ms->common.end_actions); @@ -914,22 +912,16 @@ static struct common_params params->common.hist.with_zeros =3D 1; break; case '6': /* trigger */ - if (params->common.events) { - retval =3D trace_event_add_trigger(params->common.events, optarg); - if (retval) - fatal("Error adding trigger %s", optarg); - } else { + if (params->common.events) + trace_event_add_trigger(params->common.events, optarg); + else fatal("--trigger requires a previous -e"); - } break; case '7': /* filter */ - if (params->common.events) { - retval =3D trace_event_add_filter(params->common.events, optarg); - if (retval) - fatal("Error adding filter %s", optarg); - } else { + if (params->common.events) + trace_event_add_filter(params->common.events, optarg); + else fatal("--filter requires a previous -e"); - } break; case '8': params->dma_latency =3D get_llong_from_str(optarg); diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src= /timerlat_top.c index 284b74773c2b5..dd727cb48b551 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -537,9 +537,7 @@ static struct common_params int c; char *trace_output =3D NULL; =20 - params =3D calloc(1, sizeof(*params)); - if (!params) - exit(1); + params =3D calloc_fatal(1, sizeof(*params)); =20 actions_init(¶ms->common.threshold_actions); actions_init(¶ms->common.end_actions); @@ -664,22 +662,16 @@ static struct common_params params->common.user_data =3D true; break; case '0': /* trigger */ - if (params->common.events) { - retval =3D trace_event_add_trigger(params->common.events, optarg); - if (retval) - fatal("Error adding trigger %s", optarg); - } else { + if (params->common.events) + trace_event_add_trigger(params->common.events, optarg); + else fatal("--trigger requires a previous -e"); - } break; case '1': /* filter */ - if (params->common.events) { - retval =3D trace_event_add_filter(params->common.events, optarg); - if (retval) - fatal("Error adding filter %s", optarg); - } else { + if (params->common.events) + trace_event_add_filter(params->common.events, optarg); + else fatal("--filter requires a previous -e"); - } break; case '2': /* dma-latency */ params->dma_latency =3D get_llong_from_str(optarg); diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index b8be3e28680ee..211ca54b15b0e 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -191,9 +191,7 @@ void trace_instance_destroy(struct trace_instance *trac= e) */ int trace_instance_init(struct trace_instance *trace, char *tool_name) { - trace->seq =3D calloc(1, sizeof(*trace->seq)); - if (!trace->seq) - goto out_err; + trace->seq =3D calloc_fatal(1, sizeof(*trace->seq)); =20 trace_seq_init(trace->seq); =20 @@ -274,15 +272,9 @@ struct trace_events *trace_event_alloc(const char *eve= nt_string) { struct trace_events *tevent; =20 - tevent =3D calloc(1, sizeof(*tevent)); - if (!tevent) - return NULL; + tevent =3D calloc_fatal(1, sizeof(*tevent)); =20 - tevent->system =3D strdup(event_string); - if (!tevent->system) { - free(tevent); - return NULL; - } + tevent->system =3D strdup_fatal(event_string); =20 tevent->event =3D strstr(tevent->system, ":"); if (tevent->event) { @@ -296,31 +288,23 @@ struct trace_events *trace_event_alloc(const char *ev= ent_string) /* * trace_event_add_filter - record an event filter */ -int trace_event_add_filter(struct trace_events *event, char *filter) +void trace_event_add_filter(struct trace_events *event, char *filter) { if (event->filter) free(event->filter); =20 - event->filter =3D strdup(filter); - if (!event->filter) - return 1; - - return 0; + event->filter =3D strdup_fatal(filter); } =20 /* * trace_event_add_trigger - record an event trigger action */ -int trace_event_add_trigger(struct trace_events *event, char *trigger) +void trace_event_add_trigger(struct trace_events *event, char *trigger) { if (event->trigger) free(event->trigger); =20 - event->trigger =3D strdup(trigger); - if (!event->trigger) - return 1; - - return 0; + event->trigger =3D strdup_fatal(trigger); } =20 /* diff --git a/tools/tracing/rtla/src/trace.h b/tools/tracing/rtla/src/trace.h index 1e5aee4b828dd..95b911a2228b2 100644 --- a/tools/tracing/rtla/src/trace.h +++ b/tools/tracing/rtla/src/trace.h @@ -45,6 +45,6 @@ void trace_events_destroy(struct trace_instance *instance, int trace_events_enable(struct trace_instance *instance, struct trace_events *events); =20 -int trace_event_add_filter(struct trace_events *event, char *filter); -int trace_event_add_trigger(struct trace_events *event, char *trigger); +void trace_event_add_filter(struct trace_events *event, char *filter); +void trace_event_add_trigger(struct trace_events *event, char *trigger); int trace_set_buffer_size(struct trace_instance *trace, int size); diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index 18986a5aed3c1..75cdcc63d5a15 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -1032,3 +1032,38 @@ int strtoi(const char *s, int *res) *res =3D (int) lres; return 0; } + +static inline void fatal_alloc(void) +{ + fatal("Error allocating memory\n"); +} + +void *calloc_fatal(size_t n, size_t size) +{ + void *p =3D calloc(n, size); + + if (!p) + fatal_alloc(); + + return p; +} + +void *reallocarray_fatal(void *p, size_t n, size_t size) +{ + p =3D reallocarray(p, n, size); + + if (!p) + fatal_alloc(); + + return p; +} + +char *strdup_fatal(const char *s) +{ + char *p =3D strdup(s); + + if (!p) + fatal_alloc(); + + return p; +} diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h index f7c2a52a0ab54..e29c2eb5d569d 100644 --- a/tools/tracing/rtla/src/utils.h +++ b/tools/tracing/rtla/src/utils.h @@ -69,6 +69,9 @@ int set_comm_sched_attr(const char *comm_prefix, struct s= ched_attr *attr); int set_comm_cgroup(const char *comm_prefix, const char *cgroup); int set_pid_cgroup(pid_t pid, const char *cgroup); int set_cpu_dma_latency(int32_t latency); +void *calloc_fatal(size_t n, size_t size); +void *reallocarray_fatal(void *p, size_t n, size_t size); +char *strdup_fatal(const char *s); #ifdef HAVE_LIBCPUPOWER_SUPPORT int save_cpu_idle_disable_state(unsigned int cpu); int restore_cpu_idle_disable_state(unsigned int cpu); --=20 2.52.0 From nobody Sun Feb 8 06:00:00 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD07E2D9494 for ; Thu, 15 Jan 2026 17:25:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497911; cv=none; b=tmI6PL7QJclbDG5xWPpn8Iq27Qwv0J+Q3jxAbHiNx14/B1a9DGjSeDpDe4nwl1C9dhMjU4S9FzVWb908Cnh6q8EaWLrtUFiJXVa8CEjJvFBJk8qmJQocSr+I77mc1IT+sjWkb/0t0wzIF91LBWDmeCD1h5pavlrYAMV5be9cOE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497911; c=relaxed/simple; bh=b9UIcCzgHzv5dWFzcFJ8wptQQxfWpu7+N36izSipW0M=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nj8xWhw5rO4LFSsKZcs2fgY2LTQ3KnQccgtOevgVam3Ycbbxoh6KAAvOHMCFw/4kyKiP6lviq32FSsd6EmlL0IuPRSDr2boYOaL8TKyZokYNV0JKqR93/mBtEipfczlD2RSDAU4b/x3DULaikPH6SFxoxESSdoFI33Ux54+m5I0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=bV+xPRIe; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bV+xPRIe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768497908; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=clIrUy6vZlEsDOhtFnJV3d0FNSzh4HR8QlMrRlaBWdo=; b=bV+xPRIe3SDHBZpri2Dqligj9txVIuZF3bk+/6ZheiTU3sr0mMD/2uzjE8BrrYIFBUUtRe 2VyYaMoUSoInXxFeG57/BQeFBAqgydQ5g9JZwjyj2O8glrjm2AEuUKyMLP7ZcRYLNzh4B2 RlOql2tVsaedqbeT28fk5N3FtJg19s0= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638-o3aZ0iaINpmInAaQNQmjCw-1; Thu, 15 Jan 2026 12:25:05 -0500 X-MC-Unique: o3aZ0iaINpmInAaQNQmjCw-1 X-Mimecast-MFC-AGG-ID: o3aZ0iaINpmInAaQNQmjCw_1768497904 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0F4FA195608E; Thu, 15 Jan 2026 17:25:04 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6C63F18004D8; Thu, 15 Jan 2026 17:24:59 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Tiezhu Yang , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 02/18] rtla: Use strdup() to simplify code Date: Thu, 15 Jan 2026 13:31:45 -0300 Message-ID: <20260115163650.118910-3-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The actions_add_trace_output() and actions_add_shell() functions were using calloc() followed by strcpy() to allocate and copy a string. This can be simplified by using strdup(), which allocates memory and copies the string in a single step. Replace the calloc() and strcpy() calls with strdup(), making the code more concise and readable. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/actions.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/tracing/rtla/src/actions.c b/tools/tracing/rtla/src/acti= ons.c index 22b8283a183f3..0ac42ffd734a3 100644 --- a/tools/tracing/rtla/src/actions.c +++ b/tools/tracing/rtla/src/actions.c @@ -69,8 +69,7 @@ actions_add_trace_output(struct actions *self, const char= *trace_output) =20 self->present[ACTION_TRACE_OUTPUT] =3D true; action->type =3D ACTION_TRACE_OUTPUT; - action->trace_output =3D calloc_fatal(strlen(trace_output) + 1, sizeof(ch= ar)); - strcpy(action->trace_output, trace_output); + action->trace_output =3D strdup_fatal(trace_output); } =20 /* @@ -97,8 +96,7 @@ actions_add_shell(struct actions *self, const char *comma= nd) =20 self->present[ACTION_SHELL] =3D true; action->type =3D ACTION_SHELL; - action->command =3D calloc_fatal(strlen(command) + 1, sizeof(char)); - strcpy(action->command, command); + action->command =3D strdup_fatal(command); } =20 /* --=20 2.52.0 From nobody Sun Feb 8 06:00:00 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45F603BF2FA for ; Thu, 15 Jan 2026 17:25:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497931; cv=none; b=Ib7LE5RfHQpmnLj1RQeHq1pRpTLpH4bm9BmU7TwYsfQewLY5/QuI9dO2mSJ1OVKzBzZ5Y9owUPcim8kjpRaCdl1DUc3ZzsOg2U0LAMdwNuJ+mACzsegqYZj4t/N0/nt5mMSpdKSogZr+pV0KefAl0cYx5fJc96mZOSH71V10pQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497931; c=relaxed/simple; bh=u1r49FuSp7idbRrrUtXRDCMaM0faDivhFJHkbmS+TP8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B5ouw4Ea5pni0LKUdn2BXMT2uDe1wklxHHqUwvxRPlRPcIXy2aj8h2zHwAfKyIMax4vRAg+yBZg4uaMBsC+VHVQGXAuU2lDfJ3xYG9yqi3j51arI5Yqo4MCTOGOpXt/imLaPfo4FCgabfWdh82x5mrv1vglF+fB+GvRkio9sSUo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ctzMdwXs; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ctzMdwXs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768497929; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ANB34oPiS2LxVk2Ywz66GKqLjmyf0reRPynvvnfmGMo=; b=ctzMdwXsdvJMRkXVYXIWZ7jYl7b1HSh8ZJVDOm7nUoymPj0xPcoVIqb3d427UGayjkCH36 jba3rhI0YP3IauExUtpbmOvTQmBXVfxE1/LdaRjWpEoiqUSuOrXW0CXThRFTWt9GsFqlWH QECnznAcrsZ4gLmI2cbmleZv0fxnIY8= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-686-SSOTAUToPlKbiVWLIZlquw-1; Thu, 15 Jan 2026 12:25:25 -0500 X-MC-Unique: SSOTAUToPlKbiVWLIZlquw-1 X-Mimecast-MFC-AGG-ID: SSOTAUToPlKbiVWLIZlquw_1768497924 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1567A1954B21; Thu, 15 Jan 2026 17:25:24 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EE4FD1800285; Thu, 15 Jan 2026 17:25:18 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Haiyong Sun , Tiezhu Yang , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 03/18] rtla: Simplify argument parsing Date: Thu, 15 Jan 2026 13:31:46 -0300 Message-ID: <20260115163650.118910-4-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The actions_parse() function uses open-coded logic to extract arguments from a string. This includes manual length checks and strncmp() calls, which can be verbose and error-prone. To simplify and improve the robustness of argument parsing, introduce a new extract_arg() helper macro. This macro extracts the value from a "key=3Dvalue" pair, making the code more concise and readable. Also, introduce STRING_LENGTH() and strncmp_static() macros to perform compile-time calculations of string lengths and safer string comparisons. Refactor actions_parse() to use these new helpers, resulting in cleaner and more maintainable code. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/actions.c | 57 +++++++++++++++++++++++--------- tools/tracing/rtla/src/utils.h | 14 ++++++-- 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/tools/tracing/rtla/src/actions.c b/tools/tracing/rtla/src/acti= ons.c index 0ac42ffd734a3..b0d68b5de08db 100644 --- a/tools/tracing/rtla/src/actions.c +++ b/tools/tracing/rtla/src/actions.c @@ -111,6 +111,29 @@ actions_add_continue(struct actions *self) action->type =3D ACTION_CONTINUE; } =20 +static inline const char *__extract_arg(const char *token, const char *opt= , size_t opt_len) +{ + const size_t tok_len =3D strlen(token); + + if (tok_len <=3D opt_len) + return NULL; + + if (strncmp(token, opt, opt_len)) + return NULL; + + return token + opt_len; +} + +/* + * extract_arg - extract argument value from option token + * @token: option token (e.g., "file=3Dtrace.txt") + * @opt: option name to match (e.g., "file") + * + * Returns pointer to argument value after "=3D" if token matches "opt=3D", + * otherwise returns NULL. + */ +#define extract_arg(token, opt) __extract_arg(token, opt "=3D", STRING_LEN= GTH(opt "=3D")) + /* * actions_parse - add an action based on text specification */ @@ -120,6 +143,7 @@ actions_parse(struct actions *self, const char *trigger= , const char *tracefn) enum action_type type =3D ACTION_NONE; const char *token; char trigger_c[strlen(trigger) + 1]; + const char *arg_value; =20 /* For ACTION_SIGNAL */ int signal =3D 0, pid =3D 0; @@ -152,12 +176,10 @@ actions_parse(struct actions *self, const char *trigg= er, const char *tracefn) if (token =3D=3D NULL) trace_output =3D tracefn; else { - if (strlen(token) > 5 && strncmp(token, "file=3D", 5) =3D=3D 0) { - trace_output =3D token + 5; - } else { + trace_output =3D extract_arg(token, "file"); + if (!trace_output) /* Invalid argument */ return -1; - } =20 token =3D strtok(NULL, ","); if (token !=3D NULL) @@ -169,17 +191,21 @@ actions_parse(struct actions *self, const char *trigg= er, const char *tracefn) case ACTION_SIGNAL: /* Takes two arguments, num (signal) and pid */ while (token !=3D NULL) { - if (strlen(token) > 4 && strncmp(token, "num=3D", 4) =3D=3D 0) { - if (strtoi(token + 4, &signal)) - return -1; - } else if (strlen(token) > 4 && strncmp(token, "pid=3D", 4) =3D=3D 0) { - if (strncmp(token + 4, "parent", 7) =3D=3D 0) - pid =3D -1; - else if (strtoi(token + 4, &pid)) + arg_value =3D extract_arg(token, "num"); + if (arg_value) { + if (strtoi(arg_value, &signal)) return -1; } else { - /* Invalid argument */ - return -1; + arg_value =3D extract_arg(token, "pid"); + if (arg_value) { + if (strncmp_static(arg_value, "parent") =3D=3D 0) + pid =3D -1; + else if (strtoi(arg_value, &pid)) + return -1; + } else { + /* Invalid argument */ + return -1; + } } =20 token =3D strtok(NULL, ","); @@ -194,9 +220,10 @@ actions_parse(struct actions *self, const char *trigge= r, const char *tracefn) case ACTION_SHELL: if (token =3D=3D NULL) return -1; - if (strlen(token) > 8 && strncmp(token, "command=3D", 8)) + arg_value =3D extract_arg(token, "command"); + if (!arg_value) return -1; - actions_add_shell(self, token + 8); + actions_add_shell(self, arg_value); break; case ACTION_CONTINUE: /* Takes no argument */ diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h index e29c2eb5d569d..8323c999260c2 100644 --- a/tools/tracing/rtla/src/utils.h +++ b/tools/tracing/rtla/src/utils.h @@ -14,8 +14,18 @@ #define MAX_NICE 20 #define MIN_NICE -19 =20 -#define container_of(ptr, type, member)({ \ - const typeof(((type *)0)->member) *__mptr =3D (ptr); \ +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) +#endif + +/* Calculate string length at compile time (excluding null terminator) */ +#define STRING_LENGTH(s) (ARRAY_SIZE(s) - sizeof(*(s))) + +/* Compare string with static string, length determined at compile time */ +#define strncmp_static(s1, s2) strncmp(s1, s2, ARRAY_SIZE(s2)) + +#define container_of(ptr, type, member)({ \ + const typeof(((type *)0)->member) * __mptr =3D (ptr); \ (type *)((char *)__mptr - offsetof(type, member)) ; }) =20 extern int config_debug; --=20 2.52.0 From nobody Sun Feb 8 06:00:00 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 735F33BFE3D for ; Thu, 15 Jan 2026 17:25:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497951; cv=none; b=FjLt/kYKbhtWm7DiIJ+PyR9bmq+0hlRiAkuLYucn1Chwh8iLtbVWESg2DbPo3cR+AJ409VEII1cH3ghj0Xoxhx/mssgFhjAaD43x1zVA1x2q5xzvVj1nsU6zoEtBZGZPM9xL8DeJDAAo0eQHP8Rl7QdHReUD0lB0e7inZDKfCfA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497951; c=relaxed/simple; bh=p+NEomgsJB/QdCWy6uY+hD71CazlnStfzf6iCmkP6cw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G20fKzkBj5wEdhRIBpAQc1zMjU3aaL+2FDuo3aJrnIhVjZNmKeqeMBwc/kMXy7Xxn0NmDeAIJuXOxtrZO9OosyKLnmhnXIRKjfeFcotBbydPOilz+xKnr9+7CIjz2p3TdyPzL8/VpTDjyS/9c3MSYxUzeqJtYGP5uuTgR7mIXtY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NNYwtwFi; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NNYwtwFi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768497948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EFAJ+b7YV88HP2PCJWlcs+TXD7SDHzMTMKvxpmYsN4w=; b=NNYwtwFiNvzLNt4TQnUU2VVSP2URysuPL1qDx2PnhoHH3xtY5b9CVkmZx+UQaCmHi5Aw/O h+fbkuj/fJymVWPA2G9E8KfhJB4cBwpDnb0FUHdA/U4gQE2CdZxlPprBIcWTFbYTDpHne2 VCS8jwDq8UXWBFIsUfw74pKOtnU3yLw= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-216-uqSFpn_SPjqk6OT6ADvM4Q-1; Thu, 15 Jan 2026 12:25:45 -0500 X-MC-Unique: uqSFpn_SPjqk6OT6ADvM4Q-1 X-Mimecast-MFC-AGG-ID: uqSFpn_SPjqk6OT6ADvM4Q_1768497943 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8E7A91954B0C; Thu, 15 Jan 2026 17:25:43 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0DB7418004D8; Thu, 15 Jan 2026 17:25:38 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Ivan Pravdin , Crystal Wood , Costa Shulyupin , John Kacur , Tiezhu Yang , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 04/18] rtla: Introduce common_threshold_handler() helper Date: Thu, 15 Jan 2026 13:31:47 -0300 Message-ID: <20260115163650.118910-5-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Several functions duplicate the logic for handling threshold actions. When a threshold is reached, these functions stop the trace, perform configured actions, and restart the trace if --on-threshold continue is set. Create common_threshold_handler() to centralize this shared logic and avoid code duplication. The function executes the configured threshold actions and restarts the necessary trace instances when appropriate. Also add should_continue_tracing() helper to encapsulate the check for whether tracing should continue after a threshold event, improving code readability at call sites. In timerlat_top_bpf_main_loop(), use common_params directly instead of casting through timerlat_params when only common fields are needed. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/common.c | 61 ++++++++++++++++++-------- tools/tracing/rtla/src/common.h | 18 ++++++++ tools/tracing/rtla/src/timerlat_hist.c | 19 ++++---- tools/tracing/rtla/src/timerlat_top.c | 32 +++++++------- 4 files changed, 86 insertions(+), 44 deletions(-) diff --git a/tools/tracing/rtla/src/common.c b/tools/tracing/rtla/src/commo= n.c index ceff76a62a30b..cbc207fa58707 100644 --- a/tools/tracing/rtla/src/common.c +++ b/tools/tracing/rtla/src/common.c @@ -175,6 +175,38 @@ common_apply_config(struct osnoise_tool *tool, struct = common_params *params) } =20 =20 +/** + * common_threshold_handler - handle latency threshold overflow + * @tool: pointer to the osnoise_tool instance containing trace contexts + * + * Executes the configured threshold actions (e.g., saving trace, printing, + * sending signals). If the continue flag is set (--on-threshold continue), + * restarts the auxiliary trace instances to continue monitoring. + * + * Return: 0 for success, -1 for error. + */ +int +common_threshold_handler(const struct osnoise_tool *tool) +{ + actions_perform(&tool->params->threshold_actions); + + if (!should_continue_tracing(tool->params)) + /* continue flag not set, break */ + return 0; + + /* continue action reached, re-enable tracing */ + if (tool->record && trace_instance_start(&tool->record->trace)) + goto err; + if (tool->aa && trace_instance_start(&tool->aa->trace)) + goto err; + + return 0; + +err: + err_msg("Error restarting trace\n"); + return -1; +} + int run_tool(struct tool_ops *ops, int argc, char *argv[]) { struct common_params *params; @@ -352,17 +384,14 @@ int top_main_loop(struct osnoise_tool *tool) /* stop tracing requested, do not perform actions */ return 0; =20 - actions_perform(¶ms->threshold_actions); + retval =3D common_threshold_handler(tool); + if (retval) + return retval; + =20 - if (!params->threshold_actions.continue_flag) - /* continue flag not set, break */ + if (!should_continue_tracing(params)) return 0; =20 - /* continue action reached, re-enable tracing */ - if (record) - trace_instance_start(&record->trace); - if (tool->aa) - trace_instance_start(&tool->aa->trace); trace_instance_start(trace); } =20 @@ -403,18 +432,14 @@ int hist_main_loop(struct osnoise_tool *tool) /* stop tracing requested, do not perform actions */ break; =20 - actions_perform(¶ms->threshold_actions); + retval =3D common_threshold_handler(tool); + if (retval) + return retval; =20 - if (!params->threshold_actions.continue_flag) - /* continue flag not set, break */ - break; + if (!should_continue_tracing(params)) + return 0; =20 - /* continue action reached, re-enable tracing */ - if (tool->record) - trace_instance_start(&tool->record->trace); - if (tool->aa) - trace_instance_start(&tool->aa->trace); - trace_instance_start(&tool->trace); + trace_instance_start(trace); } =20 /* is there still any user-threads ? */ diff --git a/tools/tracing/rtla/src/common.h b/tools/tracing/rtla/src/commo= n.h index 7602c5593ef5d..c548decd3c40f 100644 --- a/tools/tracing/rtla/src/common.h +++ b/tools/tracing/rtla/src/common.h @@ -143,6 +143,24 @@ struct tool_ops { void (*free)(struct osnoise_tool *tool); }; =20 +/** + * should_continue_tracing - check if tracing should continue after thresh= old + * @params: pointer to the common parameters structure + * + * Returns true if the continue action was configured (--on-threshold cont= inue), + * indicating that tracing should be restarted after handling the threshol= d event. + * + * Return: 1 if tracing should continue, 0 otherwise. + */ +static inline int +should_continue_tracing(const struct common_params *params) +{ + return params->threshold_actions.continue_flag; +} + +int +common_threshold_handler(const struct osnoise_tool *tool); + int osnoise_set_cpus(struct osnoise_context *context, char *cpus); void osnoise_restore_cpus(struct osnoise_context *context); =20 diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/sr= c/timerlat_hist.c index 6ea397421f1c9..6b8eaef8a3a09 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -17,6 +17,7 @@ #include "timerlat.h" #include "timerlat_aa.h" #include "timerlat_bpf.h" +#include "common.h" =20 struct timerlat_hist_cpu { int *irq; @@ -1048,7 +1049,6 @@ static struct osnoise_tool =20 static int timerlat_hist_bpf_main_loop(struct osnoise_tool *tool) { - struct timerlat_params *params =3D to_timerlat_params(tool->params); int retval; =20 while (!stop_tracing) { @@ -1056,18 +1056,17 @@ static int timerlat_hist_bpf_main_loop(struct osnoi= se_tool *tool) =20 if (!stop_tracing) { /* Threshold overflow, perform actions on threshold */ - actions_perform(¶ms->common.threshold_actions); + retval =3D common_threshold_handler(tool); + if (retval) + return retval; =20 - if (!params->common.threshold_actions.continue_flag) - /* continue flag not set, break */ + if (!should_continue_tracing(tool->params)) break; =20 - /* continue action reached, re-enable tracing */ - if (tool->record) - trace_instance_start(&tool->record->trace); - if (tool->aa) - trace_instance_start(&tool->aa->trace); - timerlat_bpf_restart_tracing(); + if (timerlat_bpf_restart_tracing()) { + err_msg("Error restarting BPF trace\n"); + return -1; + } } } timerlat_bpf_detach(); diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src= /timerlat_top.c index dd727cb48b551..c6f6757c3fb6b 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -17,6 +17,7 @@ #include "timerlat.h" #include "timerlat_aa.h" #include "timerlat_bpf.h" +#include "common.h" =20 struct timerlat_top_cpu { unsigned long long irq_count; @@ -801,10 +802,10 @@ static struct osnoise_tool static int timerlat_top_bpf_main_loop(struct osnoise_tool *tool) { - struct timerlat_params *params =3D to_timerlat_params(tool->params); + const struct common_params *params =3D tool->params; int retval, wait_retval; =20 - if (params->common.aa_only) { + if (params->aa_only) { /* Auto-analysis only, just wait for stop tracing */ timerlat_bpf_wait(-1); return 0; @@ -812,8 +813,8 @@ timerlat_top_bpf_main_loop(struct osnoise_tool *tool) =20 /* Pull and display data in a loop */ while (!stop_tracing) { - wait_retval =3D timerlat_bpf_wait(params->common.quiet ? -1 : - params->common.sleep_time); + wait_retval =3D timerlat_bpf_wait(params->quiet ? -1 : + params->sleep_time); =20 retval =3D timerlat_top_bpf_pull_data(tool); if (retval) { @@ -821,28 +822,27 @@ timerlat_top_bpf_main_loop(struct osnoise_tool *tool) return retval; } =20 - if (!params->common.quiet) + if (!params->quiet) timerlat_print_stats(tool); =20 if (wait_retval !=3D 0) { /* Stopping requested by tracer */ - actions_perform(¶ms->common.threshold_actions); + retval =3D common_threshold_handler(tool); + if (retval) + return retval; =20 - if (!params->common.threshold_actions.continue_flag) - /* continue flag not set, break */ + if (!should_continue_tracing(tool->params)) break; =20 - /* continue action reached, re-enable tracing */ - if (tool->record) - trace_instance_start(&tool->record->trace); - if (tool->aa) - trace_instance_start(&tool->aa->trace); - timerlat_bpf_restart_tracing(); + if (timerlat_bpf_restart_tracing()) { + err_msg("Error restarting BPF trace\n"); + return -1; + } } =20 /* is there still any user-threads ? */ - if (params->common.user_workload) { - if (params->common.user.stopped_running) { + if (params->user_workload) { + if (params->user.stopped_running) { debug_msg("timerlat user space threads stopped!\n"); break; } --=20 2.52.0 From nobody Sun Feb 8 06:00:00 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F50F3A0E98 for ; Thu, 15 Jan 2026 17:26:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497972; cv=none; b=DaVRrATkmlHHNNBvZZLRXhd9Ko18N0/xUn1SlPVN+Mg7GNKyx9LHymGnMsjdAUO1OirpDnDViHqXMXXnKyo6RW5goXdXl09YGn1r1GE7uP4I6wf430JuIBg7lh9zH07suJAKIuz9jl7/t6cpU15KUJ81+K0vs6XOd7Mn+wuFqy8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497972; c=relaxed/simple; bh=GZcEHYQTtmZ0VfDcQ20iq3OLyxEpGboaa5o647sLiJE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rc+i/jL4nvWQreuoctxx80n5D1nDg5ZMiaD4666xeo4NaUZAmuIyl8lONTGoU67+KKpv0BHWXfhYuEpF9yIWqmVvOzGLpfwfw5d0+YvG9aLjtK3Fy6PEfDXqO4KuAej67hGzRJ+vJJ+bXUjHZrCIwhwuQCYmeAr9D/IPPTUWYvs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Hayi5hzB; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Hayi5hzB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768497969; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=60sKp2ZfEgwvQCWM+SD55B2y7ixOltC+YNnJohYOh4k=; b=Hayi5hzB2Jx3OAax9J8AQ+DnaTff+pCKI1Rht5y8sSldghrO0zNZx5nQl3ySySfdcsBfha 6AijN3D6gN5spdCxkr4w0SdPp+5aZlU6OC453hFdQ2DpuhK7vPetUmUshqkAfOIEKDd/K1 hD33WATmCtxx0Y6+NBn5rt49pYx3pFw= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-674-5_Q0xnrFM8CY7zLUftDHaQ-1; Thu, 15 Jan 2026 12:26:04 -0500 X-MC-Unique: 5_Q0xnrFM8CY7zLUftDHaQ-1 X-Mimecast-MFC-AGG-ID: 5_Q0xnrFM8CY7zLUftDHaQ_1768497963 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4EABE195606E; Thu, 15 Jan 2026 17:26:03 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8278A1800285; Thu, 15 Jan 2026 17:25:58 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Ivan Pravdin , Crystal Wood , Costa Shulyupin , John Kacur , Tiezhu Yang , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 05/18] rtla: Replace magic number with MAX_PATH Date: Thu, 15 Jan 2026 13:31:48 -0300 Message-ID: <20260115163650.118910-6-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The trace functions use a buffer to manipulate strings that will be written to tracefs files. These buffers are defined with a magic number of 1024, which is a common source of vulnerabilities. Replace the magic number 1024 with the MAX_PATH macro to make the code safer and more readable. While at it, replace other instances of the magic number with ARRAY_SIZE() when the buffer is locally defined. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/osnoise.c | 4 ++-- tools/tracing/rtla/src/timerlat_u.c | 4 ++-- tools/tracing/rtla/src/trace.c | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/tracing/rtla/src/osnoise.c b/tools/tracing/rtla/src/osno= ise.c index ec074cd53dd84..4890a9a9d6466 100644 --- a/tools/tracing/rtla/src/osnoise.c +++ b/tools/tracing/rtla/src/osnoise.c @@ -52,7 +52,7 @@ char *osnoise_get_cpus(struct osnoise_context *context) int osnoise_set_cpus(struct osnoise_context *context, char *cpus) { char *orig_cpus =3D osnoise_get_cpus(context); - char buffer[1024]; + char buffer[MAX_PATH]; int retval; =20 if (!orig_cpus) @@ -62,7 +62,7 @@ int osnoise_set_cpus(struct osnoise_context *context, cha= r *cpus) if (!context->curr_cpus) return -1; =20 - snprintf(buffer, 1024, "%s\n", cpus); + snprintf(buffer, ARRAY_SIZE(buffer), "%s\n", cpus); =20 debug_msg("setting cpus to %s from %s", cpus, context->orig_cpus); =20 diff --git a/tools/tracing/rtla/src/timerlat_u.c b/tools/tracing/rtla/src/t= imerlat_u.c index ce68e39d25fde..efe2f72686486 100644 --- a/tools/tracing/rtla/src/timerlat_u.c +++ b/tools/tracing/rtla/src/timerlat_u.c @@ -32,7 +32,7 @@ static int timerlat_u_main(int cpu, struct timerlat_u_params *params) { struct sched_param sp =3D { .sched_priority =3D 95 }; - char buffer[1024]; + char buffer[MAX_PATH]; int timerlat_fd; cpu_set_t set; int retval; @@ -83,7 +83,7 @@ static int timerlat_u_main(int cpu, struct timerlat_u_par= ams *params) =20 /* add should continue with a signal handler */ while (true) { - retval =3D read(timerlat_fd, buffer, 1024); + retval =3D read(timerlat_fd, buffer, ARRAY_SIZE(buffer)); if (retval < 0) break; } diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index 211ca54b15b0e..e1af54f9531b8 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -313,7 +313,7 @@ void trace_event_add_trigger(struct trace_events *event= , char *trigger) static void trace_event_disable_filter(struct trace_instance *instance, struct trace_events *tevent) { - char filter[1024]; + char filter[MAX_PATH]; int retval; =20 if (!tevent->filter) @@ -325,7 +325,7 @@ static void trace_event_disable_filter(struct trace_ins= tance *instance, debug_msg("Disabling %s:%s filter %s\n", tevent->system, tevent->event ? : "*", tevent->filter); =20 - snprintf(filter, 1024, "!%s\n", tevent->filter); + snprintf(filter, ARRAY_SIZE(filter), "!%s\n", tevent->filter); =20 retval =3D tracefs_event_file_write(instance->inst, tevent->system, tevent->event, "filter", filter); @@ -344,7 +344,7 @@ static void trace_event_save_hist(struct trace_instance= *instance, { int retval, index, out_fd; mode_t mode =3D 0644; - char path[1024]; + char path[MAX_PATH]; char *hist; =20 if (!tevent) @@ -359,7 +359,7 @@ static void trace_event_save_hist(struct trace_instance= *instance, if (retval) return; =20 - snprintf(path, 1024, "%s_%s_hist.txt", tevent->system, tevent->event); + snprintf(path, ARRAY_SIZE(path), "%s_%s_hist.txt", tevent->system, tevent= ->event); =20 printf(" Saving event %s:%s hist to %s\n", tevent->system, tevent->event= , path); =20 @@ -391,7 +391,7 @@ static void trace_event_save_hist(struct trace_instance= *instance, static void trace_event_disable_trigger(struct trace_instance *instance, struct trace_events *tevent) { - char trigger[1024]; + char trigger[MAX_PATH]; int retval; =20 if (!tevent->trigger) @@ -405,7 +405,7 @@ static void trace_event_disable_trigger(struct trace_in= stance *instance, =20 trace_event_save_hist(instance, tevent); =20 - snprintf(trigger, 1024, "!%s\n", tevent->trigger); + snprintf(trigger, ARRAY_SIZE(trigger), "!%s\n", tevent->trigger); =20 retval =3D tracefs_event_file_write(instance->inst, tevent->system, tevent->event, "trigger", trigger); @@ -444,7 +444,7 @@ void trace_events_disable(struct trace_instance *instan= ce, static int trace_event_enable_filter(struct trace_instance *instance, struct trace_events *tevent) { - char filter[1024]; + char filter[MAX_PATH]; int retval; =20 if (!tevent->filter) @@ -456,7 +456,7 @@ static int trace_event_enable_filter(struct trace_insta= nce *instance, return 1; } =20 - snprintf(filter, 1024, "%s\n", tevent->filter); + snprintf(filter, ARRAY_SIZE(filter), "%s\n", tevent->filter); =20 debug_msg("Enabling %s:%s filter %s\n", tevent->system, tevent->event ? : "*", tevent->filter); @@ -479,7 +479,7 @@ static int trace_event_enable_filter(struct trace_insta= nce *instance, static int trace_event_enable_trigger(struct trace_instance *instance, struct trace_events *tevent) { - char trigger[1024]; + char trigger[MAX_PATH]; int retval; =20 if (!tevent->trigger) @@ -491,7 +491,7 @@ static int trace_event_enable_trigger(struct trace_inst= ance *instance, return 1; } =20 - snprintf(trigger, 1024, "%s\n", tevent->trigger); + snprintf(trigger, ARRAY_SIZE(trigger), "%s\n", tevent->trigger); =20 debug_msg("Enabling %s:%s trigger %s\n", tevent->system, tevent->event ? : "*", tevent->trigger); --=20 2.52.0 From nobody Sun Feb 8 06:00:00 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6FB93C1FEF for ; Thu, 15 Jan 2026 17:26:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497990; cv=none; b=Ov2FWKBhS2MdWPdZd1W2aNgBVJIQLNUkSUa2VGsRHh20PkNCJemwGTYlc0UNGvaVZLPjMeFfz5+E9zdY07o3bTVx8VeOTDXelfEt+hiGKyFiles0+sdg2tlB5yJgsZeTU7Tz29JcZ9S/X87efFNu4PHcjRGuEYsFg/jttPomugY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497990; c=relaxed/simple; bh=T7o0zP6EJubXjuBW2C/9GrQT2Gye/tqv6VQ1VxV83rs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VAakhZCnBwrW+s4Fw5SBAmYaMhTn/Bz5MgFfVZMEl+5deWlq/P+IX6aC8TK91N1ZagoNCN6WfSh7ZwU6KMhlkid9QGYVaUdXNMkHoLAzco9If75K6fGmO8TPsD9TR+3Ck7sLDVUMGLB+OxfOCRS1HkWGmfGfBNrvBa0Nehx8LdE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FkCk0Xt3; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FkCk0Xt3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768497987; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E8KTz5utFl7V46Z0aDTcTYKhxj6BI+IbgWi2PWVNcmE=; b=FkCk0Xt3o0GIDB3MXM5OEc1ibrH29Ulvb8SJd/UAxK0T+SadYSWSlBGRI8Vai+ywbg2Bmc OHZDjCKFgttFRrU+1CBLC8cxWKNy3CnmRh8Y0rKd085to7NMCqFHaD2sqpvPVeXs81rNl4 aBC6M4CdDb3r6T5Hrc3Y+GpaaBHDx+0= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-660-tbDEcCIEOoufTouSJuJYug-1; Thu, 15 Jan 2026 12:26:24 -0500 X-MC-Unique: tbDEcCIEOoufTouSJuJYug-1 X-Mimecast-MFC-AGG-ID: tbDEcCIEOoufTouSJuJYug_1768497983 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C509B18005AD; Thu, 15 Jan 2026 17:26:22 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 35FB918004D8; Thu, 15 Jan 2026 17:26:17 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Ivan Pravdin , Crystal Wood , Costa Shulyupin , John Kacur , Tiezhu Yang , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 06/18] rtla: Simplify code by caching string lengths Date: Thu, 15 Jan 2026 13:31:49 -0300 Message-ID: <20260115163650.118910-7-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Simplify trace_event_save_hist() and set_comm_cgroup() by computing string lengths once and storing them in local variables, rather than calling strlen() multiple times on the same unchanged strings. This makes the code clearer by eliminating redundant function calls and improving readability. In trace_event_save_hist(), the write loop previously called strlen() on the hist buffer twice per iteration for both the size calculation and loop condition. Store the length in hist_len before entering the loop. In set_comm_cgroup(), strlen() was called on cgroup_path up to three times in succession. Store the result in cg_path_len to use in both the offset calculation and size parameter for subsequent append operations. This simplification makes the code easier to read and maintain without changing program behavior. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/trace.c | 6 ++++-- tools/tracing/rtla/src/utils.c | 11 +++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index e1af54f9531b8..2f529aaf8deef 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -346,6 +346,7 @@ static void trace_event_save_hist(struct trace_instance= *instance, mode_t mode =3D 0644; char path[MAX_PATH]; char *hist; + size_t hist_len; =20 if (!tevent) return; @@ -376,9 +377,10 @@ static void trace_event_save_hist(struct trace_instanc= e *instance, } =20 index =3D 0; + hist_len =3D strlen(hist); do { - index +=3D write(out_fd, &hist[index], strlen(hist) - index); - } while (index < strlen(hist)); + index +=3D write(out_fd, &hist[index], hist_len - index); + } while (index < hist_len); =20 free(hist); out_close: diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index 75cdcc63d5a15..b5a6007b108d2 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -811,6 +811,7 @@ static int open_cgroup_procs(const char *cgroup) char cgroup_procs[MAX_PATH]; int retval; int cg_fd; + size_t cg_path_len; =20 retval =3D find_mount("cgroup2", cgroup_path, sizeof(cgroup_path)); if (!retval) { @@ -818,16 +819,18 @@ static int open_cgroup_procs(const char *cgroup) return -1; } =20 + cg_path_len =3D strlen(cgroup_path); + if (!cgroup) { - retval =3D get_self_cgroup(&cgroup_path[strlen(cgroup_path)], - sizeof(cgroup_path) - strlen(cgroup_path)); + retval =3D get_self_cgroup(&cgroup_path[cg_path_len], + sizeof(cgroup_path) - cg_path_len); if (!retval) { err_msg("Did not find self cgroup\n"); return -1; } } else { - snprintf(&cgroup_path[strlen(cgroup_path)], - sizeof(cgroup_path) - strlen(cgroup_path), "%s/", cgroup); + snprintf(&cgroup_path[cg_path_len], + sizeof(cgroup_path) - cg_path_len, "%s/", cgroup); } =20 snprintf(cgroup_procs, MAX_PATH, "%s/cgroup.procs", cgroup_path); --=20 2.52.0 From nobody Sun Feb 8 06:00:00 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 188143BC4C9 for ; Thu, 15 Jan 2026 17:26:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498008; cv=none; b=hyJ/pPLH7RehronPWq2H/cS0tMFpayEOt5+FqHl0PnxvQ5OxGlgpFkoYfCqOQSnyDhSmu4ZLb5MxBPWYrVwFXy2SeHuMSCr7ANijKHEW/ZY6gyoJuxslL+Vh5Qdi/PdPhs4RUTogIOdkcqpUcFb9Vce90hl5244jMpBMObKBiOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498008; c=relaxed/simple; bh=szhz/dB9EAzsGuSsGHAlmKNjv6lSXykuU7dDqVz0V+w=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CmddwAIhHpWAVxm65zPAtmTLQEGyUb8+XadCOSgRpdE3OxoOfrDxQQ6TzDN7t6eCv8JnmQUKshCBF/H96Kg1a7GJ7+WpWXEYZAg+iKErKMKm9D1tHigRqG3eeFyfj72s1WklQl4QdYK/fUL2cRS7b9/pJkLZEoCwOdrDpTHPMNs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZT5f2a3Z; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZT5f2a3Z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768498006; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1rSo0ZpftjCBpY+QQsVLQhenX4Nub+dXJ6+E44kUmrI=; b=ZT5f2a3ZMTGx8AXWAo1G0zjRNhxc0U7ZiB3FU+lFfS/qVMaut2AjScNXnKviIsoVkcFsLw cqRlhRMvyJyqno60RyjVo4OgxNfbKgb3J2FfDlyPiA5A2AJ/W9fOAtHObwr0swKm5qg90+ 5rDbZK/LlDgL2jXzm0sNXxG0s+j+kDE= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-676-Ocnl8lsaMYqGiJHHLWbIig-1; Thu, 15 Jan 2026 12:26:45 -0500 X-MC-Unique: Ocnl8lsaMYqGiJHHLWbIig-1 X-Mimecast-MFC-AGG-ID: Ocnl8lsaMYqGiJHHLWbIig_1768498002 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 78CFD18003FD; Thu, 15 Jan 2026 17:26:42 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A586B18004D8; Thu, 15 Jan 2026 17:26:37 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Tiezhu Yang , Haiyong Sun , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 07/18] rtla: Add strscpy() and replace strncpy() calls Date: Thu, 15 Jan 2026 13:31:50 -0300 Message-ID: <20260115163650.118910-8-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Introduce a userspace strscpy() implementation that matches the Linux kernel's strscpy() semantics. The function is built on top of glibc's strlcpy() and provides guaranteed NUL-termination along with proper truncation detection through its return value. The previous strncpy() calls had potential issues: strncpy() does not guarantee NUL-termination when the source string length equals or exceeds the destination buffer size. This required defensive patterns like pre-zeroing buffers or manually setting the last byte to NUL. The new strscpy() function always NUL-terminates the destination buffer unless the size is zero, and returns -E2BIG on truncation, making error handling cleaner and more consistent with kernel code. Note that unlike the kernel's strscpy(), this implementation uses strlcpy() internally, which reads the entire source string to determine its length. The kernel avoids this to prevent potential DoS attacks from extremely long untrusted strings. This is harmless for a userspace CLI tool like rtla where input sources are bounded and trusted. Replace all strncpy() calls in rtla with strscpy(), using sizeof() for buffer sizes instead of magic constants to ensure the sizes stay in sync with the actual buffer declarations. Also remove a now-redundant memset() call that was previously needed to work around strncpy() behavior. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/timerlat_aa.c | 6 ++--- tools/tracing/rtla/src/utils.c | 34 ++++++++++++++++++++++++++-- tools/tracing/rtla/src/utils.h | 1 + 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/tools/tracing/rtla/src/timerlat_aa.c b/tools/tracing/rtla/src/= timerlat_aa.c index 31e66ea2b144c..30ef56d644f9c 100644 --- a/tools/tracing/rtla/src/timerlat_aa.c +++ b/tools/tracing/rtla/src/timerlat_aa.c @@ -455,9 +455,9 @@ static int timerlat_aa_thread_handler(struct trace_seq = *s, struct tep_record *re taa_data->thread_blocking_duration =3D duration; =20 if (comm) - strncpy(taa_data->run_thread_comm, comm, MAX_COMM); + strscpy(taa_data->run_thread_comm, comm, sizeof(taa_data->run_thread_co= mm)); else - sprintf(taa_data->run_thread_comm, "<...>"); + strscpy(taa_data->run_thread_comm, "<...>", sizeof(taa_data->run_thread= _comm)); =20 } else { taa_data->thread_thread_sum +=3D duration; @@ -519,7 +519,7 @@ static int timerlat_aa_sched_switch_handler(struct trac= e_seq *s, struct tep_reco tep_get_field_val(s, event, "next_pid", record, &taa_data->current_pid, 1= ); comm =3D tep_get_field_raw(s, event, "next_comm", record, &val, 1); =20 - strncpy(taa_data->current_comm, comm, MAX_COMM); + strscpy(taa_data->current_comm, comm, sizeof(taa_data->current_comm)); =20 /* * If this was a kworker, clean the last kworkers that ran. diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index b5a6007b108d2..e98288e55db15 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -722,8 +722,7 @@ static const int find_mount(const char *fs, char *mp, i= nt sizeof_mp) if (!found) return 0; =20 - memset(mp, 0, sizeof_mp); - strncpy(mp, mount_point, sizeof_mp - 1); + strscpy(mp, mount_point, sizeof_mp); =20 debug_msg("Fs %s found at %s\n", fs, mp); return 1; @@ -1036,6 +1035,37 @@ int strtoi(const char *s, int *res) return 0; } =20 +/** + * strscpy - Copy a C-string into a sized buffer + * @dst: Where to copy the string to + * @src: Where to copy the string from + * @count: Size of destination buffer + * + * Copy the source string @src, or as much of it as fits, into the destina= tion + * @dst buffer. The destination @dst buffer is always NUL-terminated, unle= ss + * it's zero-sized. + * + * This is a userspace implementation matching the kernel's strscpy() sema= ntics, + * built on top of glibc's strlcpy(). + * + * Returns the number of characters copied (not including the trailing NUL) + * or -E2BIG if @count is 0 or the copy was truncated. + */ +ssize_t strscpy(char *dst, const char *src, size_t count) +{ + size_t len; + + if (count =3D=3D 0) + return -E2BIG; + + len =3D strlcpy(dst, src, count); + + if (len >=3D count) + return -E2BIG; + + return (ssize_t) len; +} + static inline void fatal_alloc(void) { fatal("Error allocating memory\n"); diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h index 8323c999260c2..25b08fc5e199a 100644 --- a/tools/tracing/rtla/src/utils.h +++ b/tools/tracing/rtla/src/utils.h @@ -97,6 +97,7 @@ static inline int have_libcpupower_support(void) { return= 0; } #endif /* HAVE_LIBCPUPOWER_SUPPORT */ int auto_house_keeping(cpu_set_t *monitored_cpus); __attribute__((__warn_unused_result__)) int strtoi(const char *s, int *res= ); +ssize_t strscpy(char *dst, const char *src, size_t count); =20 #define ns_to_usf(x) (((double)x/1000)) #define ns_to_per(total, part) ((part * 100) / (double)total) --=20 2.52.0 From nobody Sun Feb 8 06:00:00 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1CB33BFE47 for ; Thu, 15 Jan 2026 17:27:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498029; cv=none; b=b5SpidU4hAJsFRdTtv366s9DnxuXBadFcJc9+zIz9SN/DSgIcZj8Rn447qPR074bAc01/vGJ/NqHiAeL3H5YlwrzfFxeB3Rf0jYmpIlgejYwOGUSaKgGtAOkZ798IY9SNw+vai6bZoij6gs0slfXCWW/hvv0VBJ+R7abLUUf5cI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498029; c=relaxed/simple; bh=tJLt5B2DZji/ml4Afp0udSPkcIunpC8Iq9d4OE08FUY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lizzLS7O0P5aZ0eb0ImjwNKfPypVExpAYemp28d8qbsxvX5mqi83WYn7Q4+x973OeB7O/azyRO7EKVs69tpq4qYH+XDPO6494+9GVC/mzQy2jtwPxYJVBd0g/ZuZYQI8J7XhgedQb0SU+RKTL9L0/pttPvN86c0dZz8lJWiBJQE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=d1hIHypz; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="d1hIHypz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768498027; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FkBXskbl+1yjIDirDDZ66gzhrdCqszVJfA3kLEp28sU=; b=d1hIHypzaLLrmbliBVxg6xoEyrAT/PSZJcwCV52sL/JoTP1+mV2UJnIjRCHdUCNyoE9Rrm ZD9zt9ronfgbXPf49MzuRkOhAsFILGi35TGLxhNn/Up/lFteFE7kOArzhskppu/d+uSMd7 ZZzTFWLQwviYwOYmcHEddGEH0tjFn4Q= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-619-zEVz8VLlNKOeoLOTAr2Ztw-1; Thu, 15 Jan 2026 12:27:03 -0500 X-MC-Unique: zEVz8VLlNKOeoLOTAr2Ztw-1 X-Mimecast-MFC-AGG-ID: zEVz8VLlNKOeoLOTAr2Ztw_1768498022 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 45BB7180047F; Thu, 15 Jan 2026 17:27:02 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6E7F318004D8; Thu, 15 Jan 2026 17:26:57 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Ivan Pravdin , Crystal Wood , Costa Shulyupin , John Kacur , Tiezhu Yang , Haiyong Sun , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 08/18] rtla/timerlat: Add bounds check for softirq vector Date: Thu, 15 Jan 2026 13:31:51 -0300 Message-ID: <20260115163650.118910-9-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Add bounds checking when accessing the softirq_name array using the vector value from kernel trace data. The vector field from the osnoise:softirq_noise event is used directly as an array index without validation, which could cause an out-of-bounds read if the kernel provides an unexpected vector value. The softirq_name array contains 10 elements corresponding to the standard Linux softirq vectors. While the kernel should only provide valid vector values in the range 0-9, defensive programming requires validating untrusted input before using it as an array index. If an out-of-range vector is encountered, display the word UNKNOWN instead of attempting to read beyond the array bounds. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/timerlat_aa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/tracing/rtla/src/timerlat_aa.c b/tools/tracing/rtla/src/= timerlat_aa.c index 30ef56d644f9c..bc421637cc19b 100644 --- a/tools/tracing/rtla/src/timerlat_aa.c +++ b/tools/tracing/rtla/src/timerlat_aa.c @@ -417,8 +417,8 @@ static int timerlat_aa_softirq_handler(struct trace_seq= *s, struct tep_record *r taa_data->thread_softirq_sum +=3D duration; =20 trace_seq_printf(taa_data->softirqs_seq, " %24s:%-3llu %.*s %9.2f us\n", - softirq_name[vector], vector, - 24, spaces, + vector < ARRAY_SIZE(softirq_name) ? softirq_name[vector] : "UNKNOWN", + vector, 24, spaces, ns_to_usf(duration)); return 0; } --=20 2.52.0 From nobody Sun Feb 8 06:00:00 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54E993D3315 for ; Thu, 15 Jan 2026 17:27:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498048; cv=none; b=SAJlvcUfJjIOlHy2FMF0XhOEMqG7JSzZvI2qZWD4pNL53Zi1jKzySe18y7gmZt61RykLBJqFWCZEuhLH0ACRgLxHPXxO73IolM9RiKvmXyacjv0os+VqUhuoTSXOmC3Lyhl76OlAcjWb0Ibg7J0Bw6K2jzv9kXpplfoBJQ0wJ68= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498048; c=relaxed/simple; bh=pf4PhOMROdXPWvou4acT8TMe1DaE0/Vcfn0EXJ5jwGU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CghX5IPUtcuvjElwIcCELIL2F5chfsilIXALysxPYzPy9B0S4kN61cnGealSbjv7JcDs97dQmFgypTL56Aq9kTdEqeQKZ6ZHndrB6aVbrVismG3kq++tlDxEcOvE9uUqvcJykozkElL0lnjOEUIWFwlBGhHzQsPLqyqXcmXhBKU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=SoH3wfb5; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SoH3wfb5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768498046; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jeefTd42LAWau21bgi4bPgUTY/EIGN9zI5P01XBYpQo=; b=SoH3wfb5aq5gyuS+bh68QgHAONG350XMRKEnPn+3jWPzhBGMZOT2vAWdJwJDtFR3Cxc7tV I6fSTOdBeczL1gS+ZYigTIH8VKg8uNeQ+8lyyAewtdUgsbnMUuhejH85S3o9jeVIioSqVU jjZR+GacvVvZfsq9IXfo2XDeLfslyVE= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-582-7mQIheweNQKnyjthnAyH-A-1; Thu, 15 Jan 2026 12:27:23 -0500 X-MC-Unique: 7mQIheweNQKnyjthnAyH-A-1 X-Mimecast-MFC-AGG-ID: 7mQIheweNQKnyjthnAyH-A_1768498041 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C788C1955F38; Thu, 15 Jan 2026 17:27:21 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3CD2D18007D2; Thu, 15 Jan 2026 17:27:16 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Ivan Pravdin , Crystal Wood , Costa Shulyupin , John Kacur , Tiezhu Yang , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 09/18] rtla: Handle pthread_create() failure properly Date: Thu, 15 Jan 2026 13:31:52 -0300 Message-ID: <20260115163650.118910-10-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Add proper error handling when pthread_create() fails to create the timerlat user-space dispatcher thread. Previously, the code only logged an error message but continued execution, which could lead to undefined behavior when the tool later expects the thread to be running. When pthread_create() returns an error, the function now jumps to the out_trace error path to properly clean up resources and exit. This ensures consistent error handling and prevents the tool from running in an invalid state without the required user-space thread. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/common.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/tracing/rtla/src/common.c b/tools/tracing/rtla/src/commo= n.c index cbc207fa58707..73906065e7772 100644 --- a/tools/tracing/rtla/src/common.c +++ b/tools/tracing/rtla/src/common.c @@ -303,8 +303,10 @@ int run_tool(struct tool_ops *ops, int argc, char *arg= v[]) params->user.cgroup_name =3D params->cgroup_name; =20 retval =3D pthread_create(&user_thread, NULL, timerlat_u_dispatcher, &pa= rams->user); - if (retval) + if (retval) { err_msg("Error creating timerlat user-space threads\n"); + goto out_trace; + } } =20 retval =3D ops->enable(tool); --=20 2.52.0 From nobody Sun Feb 8 06:00:00 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5CA1A3BF305 for ; Thu, 15 Jan 2026 17:27:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498068; cv=none; b=oJ/AzbpaGep2oCHHvy/oS7jEkZ8Ou/PSE/KZxSDMX2MHIzWp0ZIhvv8LZElAynNsYWR6DobR9j+Ha0lfwgijU9zsPVBUzHlTzGqU7HH5r4oQhJJyBWw2DzcHcP46PsqLPMwFavDaWhqd8ZOG9R159jve5HTdA1WX+OY6Bd/58ds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498068; c=relaxed/simple; bh=SflMTlFbfvCdZHNORr+SoiLJU7P3mYXJ3mlN96zPHHk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V52UeksG6bET0S8I7qH7cjeLqu15hIuwXsGW7dNharXNW8ZEvI8N/dAWgmPySw3YT2nEeBB8Z4LvULxlM+y2q0q+drW/iBC5llTCBDq7+Gg+2nmxQwFgC8mHjdwdnBXuot348xN8MGC24rafKMl8idVS07KmDsFFyaGzBzO1+C8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZHgeJjll; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZHgeJjll" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768498066; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ceyQmDDfhyqenhcNfQjdho74xmls3IZhe6sIRNkyvRM=; b=ZHgeJjll/o70Plvwkn8dyhOnKqWV5njYyMcjQRPgexgmd+fbh71ES53/sAoLMnuK5vTI5k yaTqDjdiwoLvnWpGQu6mJKYEDVyd5y1wgmqXid9ZI4rSZ2Wo08ra/uiqJZKFZiB5SsV90r QQv2aH277cTTSGyXfBA0J2cUlzPvfIU= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-jbfw4COsOBOuYKhC4wgjyQ-1; Thu, 15 Jan 2026 12:27:43 -0500 X-MC-Unique: jbfw4COsOBOuYKhC4wgjyQ-1 X-Mimecast-MFC-AGG-ID: jbfw4COsOBOuYKhC4wgjyQ_1768498061 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8E1AA1954B0B; Thu, 15 Jan 2026 17:27:41 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B0A3D1800285; Thu, 15 Jan 2026 17:27:36 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Tiezhu Yang , Haiyong Sun , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 10/18] rtla: Add str_has_prefix() helper function Date: Thu, 15 Jan 2026 13:31:53 -0300 Message-ID: <20260115163650.118910-11-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Add a str_has_prefix() helper function that tests whether a string starts with a given prefix. This function provides a cleaner interface for prefix matching compared to using strncmp() with strlen() directly. The function returns a boolean value indicating whether the string starts with the specified prefix. This helper will be used in subsequent changes to simplify prefix matching code throughout rtla. Also add the missing string.h include which is needed for the strlen() and strncmp() functions used by str_has_prefix() and the existing strncmp_static() macro. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/utils.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h index 25b08fc5e199a..1235d0f3a7bfd 100644 --- a/tools/tracing/rtla/src/utils.h +++ b/tools/tracing/rtla/src/utils.h @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 =20 #include +#include #include #include #include @@ -24,6 +25,18 @@ /* Compare string with static string, length determined at compile time */ #define strncmp_static(s1, s2) strncmp(s1, s2, ARRAY_SIZE(s2)) =20 +/** + * str_has_prefix - Test if a string has a given prefix + * @str: The string to test + * @prefix: The string to see if @str starts with + * + * Returns: true if @str starts with @prefix, false otherwise + */ +static inline bool str_has_prefix(const char *str, const char *prefix) +{ + return strncmp(str, prefix, strlen(prefix)) =3D=3D 0; +} + #define container_of(ptr, type, member)({ \ const typeof(((type *)0)->member) * __mptr =3D (ptr); \ (type *)((char *)__mptr - offsetof(type, member)) ; }) --=20 2.52.0 From nobody Sun Feb 8 06:00:00 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4ED903BFE59 for ; Thu, 15 Jan 2026 17:28:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498085; cv=none; b=mkBJNo/6oSbrUunH6BzSlmqobMF98VxOwVip3tvF5RTdOVvyeBEFrmhXsSW6wqXsMIPRmjxVJbWy35Ny/BWwQfu8jNtBAnYg88C/YZrMLts4UNVg7ZX9K62j15Eeqkc0V2Cb1lTDt63RLaKq+6soq6nLmWnDsUmNRzjjwb+Ndv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498085; c=relaxed/simple; bh=qXmnbKh15Yoqog4/pNkLVy8wSmDJ2XbnpsmpCqnrXQ8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xs8VoGLXqQybcVVdv4C1y9gBy7ydL0OCK23u7eQlIaGYKLhpqn0oBQQ8/VykLZlbhEVkCVaOZKScqRqlLGjR/RTZ9Bcaf9irBzpMacz8U7YBShii2HmosIx3sxZBqJ1ylZR0XBqQwypE1pSmFyCuZVPYGFihONlWZBmwCfRumPQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Ua3aHzyS; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ua3aHzyS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768498083; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kubPD8fTiVdrHvK6irQ9IsmC0Dnun29r0AdecZyP2Dg=; b=Ua3aHzySGEm1rb6qOgeZ6LCSHV7MASAPhpVD7alta6lTiB0K6YqLsJZxum4xUGKaKRA4wN ptxXsQa1iGVQF7XXY38uAqJ9r0asFQH9KyMjnFtgFwrKBrPFI+Ch+E6rqwe0lFMruPmUaO a3gksd5A7Ev2W3NL0HSgSN4REjOVw6w= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-306-OlBDCZ9aPF2hDbneA927gg-1; Thu, 15 Jan 2026 12:28:02 -0500 X-MC-Unique: OlBDCZ9aPF2hDbneA927gg-1 X-Mimecast-MFC-AGG-ID: OlBDCZ9aPF2hDbneA927gg_1768498081 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EE2001955F34; Thu, 15 Jan 2026 17:28:00 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6A40D18007D2; Thu, 15 Jan 2026 17:27:56 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Tiezhu Yang , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 11/18] rtla: Use str_has_prefix() for prefix checks Date: Thu, 15 Jan 2026 13:31:54 -0300 Message-ID: <20260115163650.118910-12-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" 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 --- tools/tracing/rtla/src/trace.c | 5 ++--- tools/tracing/rtla/src/utils.c | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index 2f529aaf8deef..ed7db5f4115ce 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -342,7 +342,7 @@ static void trace_event_disable_filter(struct trace_ins= tance *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 =3D 0644; char path[MAX_PATH]; char *hist; @@ -356,8 +356,7 @@ static void trace_event_save_hist(struct trace_instance= *instance, return; =20 /* is this a hist: trigger? */ - retval =3D strncmp(tevent->trigger, "hist:", strlen("hist:")); - if (retval) + if (!str_has_prefix(tevent->trigger, "hist:")) return; =20 snprintf(path, ARRAY_SIZE(path), "%s_%s_hist.txt", tevent->system, tevent= ->event); diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index e98288e55db15..486d96e8290fb 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -318,8 +318,7 @@ static int procfs_is_workload_pid(const char *comm_pref= ix, struct dirent *proc_e return 0; =20 buffer[MAX_PATH-1] =3D '\0'; - retval =3D strncmp(comm_prefix, buffer, strlen(comm_prefix)); - if (retval) + if (!str_has_prefix(buffer, comm_prefix)) return 0; =20 /* comm already have \n */ --=20 2.52.0 From nobody Sun Feb 8 06:00:00 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D553D3BFE3B for ; Thu, 15 Jan 2026 17:28:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498107; cv=none; b=XmMMCMwZD9JXUa31bXpVEvVP1GiHoh/e6mfTYDFC8FnCtmJiTQGd0YTfv4Ltkm/aM2jLk97qAyMOo8VvWkGGKgcGgXWOVQhOlNdxEm9Rz8IRWP7XuS7NJHJAEai/LQIQN5AAZwPzeq3H/EP8YiyNrGSfuzMFAiiimk+XU7jjcr8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498107; c=relaxed/simple; bh=i+zvPJCwKsJSTY0DS4qLye0RX9bNjeXEO9JZECY/rbk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S6OCcTDIfutmYp1yUA/6q7om2HKEu3wvgbLlhRGNtOUhUT9uIyeSBkifJ5WMmItiWScVbh1nYlLY0DENEKxqYtcyWBcwsozYR6C5KQP5hSXZnIzjjN4Ok6Lg3exuLiE44z0qZY3vBcwk2S72kWfSTFr3c9S/FwQP9nGndzXlbAY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=PWRN6aiR; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PWRN6aiR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768498105; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=86QMRTFiSKKXrEOcjxY7eSDwbxvO+9yhIJmoFALNgP4=; b=PWRN6aiRPLooSq/fs58tjOLcUtujBcPmEHIvM7aNJVJYJZEvqLQ2zJsEfbkPEgGYqTJHW7 lOXXnzxaEiDbK/PA0Y+om3Jn/e9gI7fvUknelEwWM96V/PxKvkmJ3nNPZNfntVyAkftMjb yRMdXPQ8fYwLtHZsXlhKxeoyvJ6Z2dc= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-125-oWg-JDsOOGKxRwOlQH3UCA-1; Thu, 15 Jan 2026 12:28:21 -0500 X-MC-Unique: oWg-JDsOOGKxRwOlQH3UCA-1 X-Mimecast-MFC-AGG-ID: oWg-JDsOOGKxRwOlQH3UCA_1768498100 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 64E0818005B2; Thu, 15 Jan 2026 17:28:20 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D83C218004D8; Thu, 15 Jan 2026 17:28:15 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Tiezhu Yang , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 12/18] rtla: Enforce exact match for time unit suffixes Date: Thu, 15 Jan 2026 13:31:55 -0300 Message-ID: <20260115163650.118910-13-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The parse_ns_duration() function currently uses prefix matching for detecting time units. This approach is problematic as it silently accepts malformed strings such as "100nsx" or "100us_invalid" by ignoring the trailing characters, leading to potential configuration errors. Switch to using strcmp() for suffix comparison to enforce exact matches. This ensures that the parser strictly validates the time unit and rejects any input containing invalid trailing characters, thereby improving the robustness of the configuration parsing. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/utils.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index 486d96e8290fb..b029fe5970c31 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -211,15 +211,15 @@ long parse_ns_duration(char *val) t =3D strtol(val, &end, 10); =20 if (end) { - if (!strncmp(end, "ns", 2)) { + if (strcmp(end, "ns") =3D=3D 0) { return t; - } else if (!strncmp(end, "us", 2)) { + } else if (strcmp(end, "us") =3D=3D 0) { t *=3D 1000; return t; - } else if (!strncmp(end, "ms", 2)) { + } else if (strcmp(end, "ms") =3D=3D 0) { t *=3D 1000 * 1000; return t; - } else if (!strncmp(end, "s", 1)) { + } else if (strcmp(end, "s") =3D=3D 0) { t *=3D 1000 * 1000 * 1000; return t; } --=20 2.52.0 From nobody Sun Feb 8 06:00:00 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B28013BC4C9 for ; Thu, 15 Jan 2026 17:28:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498128; cv=none; b=BC3f4QGOfbbBe+4rntEFNxizrP7RaXF71tN8GcIuIgPbSUf+MQh8LxpuL/Py0769njQ68YdTfPzwBJjzcCj6C0a9Vt7cydDWz7iTOeqrRArbBVp/+cbYKj+uraMx8akDeCHDQL9bo6R8Ebfu1VLJElq6wlIC5SsgQ7ngMTJJMlI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498128; c=relaxed/simple; bh=M6q+1YKSMR2qj9nmEYe1yRlHW29HrcG/JoUGyEha3OM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aA+fw8GgbKUoJfxoizMN2eLWpLqkC34zAtkPp2XuHknnWZyPV0aXnMlT7diVO1zhZIEbxySvF5Iq34jVk64sb6gMCmINQNeqIXQfRUixGbplTq91H2xKf5aDwObJXxyMhQAf95uqB3qjooaOTjEIZ/O0jqcjuhTnhXJ9fEOpKhM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=RHq+SjOg; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RHq+SjOg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768498125; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oCDIg29v0GPRUT83B438eXBl9CQINW2Seue9qN0fCYg=; b=RHq+SjOgVskT/fW8PdIisLGm0CxYCB+ocr0HrFf5LXsCjB20Hfm/umxFyIlOJpzWj9q5Tg c3PJXkdUo99P0k5AY7UjDmdg8gYjqi8On9fvMeymke7ZQZuXx57ZLeL+5CadnhBjEyJMKD LVDNOFTBJxCYI//f94p9gzFRW6xv6Os= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-7JG8i3brMzebvukj_r-L8A-1; Thu, 15 Jan 2026 12:28:41 -0500 X-MC-Unique: 7JG8i3brMzebvukj_r-L8A-1 X-Mimecast-MFC-AGG-ID: 7JG8i3brMzebvukj_r-L8A_1768498120 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2A66B195609D; Thu, 15 Jan 2026 17:28:40 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9CFFD1800285; Thu, 15 Jan 2026 17:28:35 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Ivan Pravdin , Crystal Wood , Costa Shulyupin , John Kacur , Tiezhu Yang , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 13/18] rtla: Use str_has_prefix() for option prefix check Date: Thu, 15 Jan 2026 13:31:56 -0300 Message-ID: <20260115163650.118910-14-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The argument parsing code in timerlat_main() and osnoise_main() uses strncmp() with a length of 1 to check if the first argument starts with a dash, indicating an option flag was passed. Replace this pattern with str_has_prefix() for consistency with the rest of the codebase. While character comparison would be slightly more efficient, using str_has_prefix() provides better readability and maintains a uniform coding style throughout the rtla tool. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/osnoise.c | 2 +- tools/tracing/rtla/src/timerlat.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/tracing/rtla/src/osnoise.c b/tools/tracing/rtla/src/osno= ise.c index 4890a9a9d6466..5b342d945c5f6 100644 --- a/tools/tracing/rtla/src/osnoise.c +++ b/tools/tracing/rtla/src/osnoise.c @@ -1210,7 +1210,7 @@ int osnoise_main(int argc, char *argv[]) =20 if ((strcmp(argv[1], "-h") =3D=3D 0) || (strcmp(argv[1], "--help") =3D=3D= 0)) { osnoise_usage(0); - } else if (strncmp(argv[1], "-", 1) =3D=3D 0) { + } else if (str_has_prefix(argv[1], "-")) { /* the user skipped the tool, call the default one */ run_tool(&osnoise_top_ops, argc, argv); exit(0); diff --git a/tools/tracing/rtla/src/timerlat.c b/tools/tracing/rtla/src/tim= erlat.c index 8f8811f7a13bd..84577daadd668 100644 --- a/tools/tracing/rtla/src/timerlat.c +++ b/tools/tracing/rtla/src/timerlat.c @@ -272,7 +272,7 @@ int timerlat_main(int argc, char *argv[]) =20 if ((strcmp(argv[1], "-h") =3D=3D 0) || (strcmp(argv[1], "--help") =3D=3D= 0)) { timerlat_usage(0); - } else if (strncmp(argv[1], "-", 1) =3D=3D 0) { + } else if (str_has_prefix(argv[1], "-")) { /* the user skipped the tool, call the default one */ run_tool(&timerlat_top_ops, argc, argv); exit(0); --=20 2.52.0 From nobody Sun Feb 8 06:00:00 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E6E33C199B for ; Thu, 15 Jan 2026 17:29:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498147; cv=none; b=ODBDbYl3fUtgHKRCBqT6BJA2Ykpj2F3aTjI27P1vnMPiLVyd4q8diDHXEDvRBl22rx9zWehbfUNsemb6V0lp1pEMzsmC502jrMvq38t4jHFfvunfRMU0509QsqSAYOcjfVuL/3uKgkqAdiFnKacV/2k9AH5qKkAOWlAZvEGUxX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498147; c=relaxed/simple; bh=kXIYufS4tBR7/9Rz8yuiI5bX9IGumrtzzuXUIzsGGoM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gTol0xfKy3J/9MCYL5SNnRfG0oZ96j8VTyhzhmBoRkGy3KeS56Yz2q4QnL34VzM25XLL17PcIVNjlAtbSPXkjHZVRE3RJ1Lt0qH6f3MemcLga4ah5s0iujwImuhqzVYqJ8uBKEHYZSg3AFeFr3dNDD/gZdJU5lezS6YXl251yWg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TQy2UG4q; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TQy2UG4q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768498145; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f5rZ+ohXFNfCf+Ydyxx6F9YC5X8JnuneFdycbsszZyU=; b=TQy2UG4qsGGZJprYAhRDpmAI2/Y70nArZxJDmB5usNAAyxCpQrVQJvHASmQP16BQEUxRBN oxQIHrclpbC8YREpFlxGcLWoiJTLEogFma0frZIyLfp9ixLIXyO1hh7+i3p3/p1Fzq8Vu7 JMGncnQAdO9iVproo8D3Fru1tVD+/ZE= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-381-_cb9CclFOJWL4zKUMT6BVw-1; Thu, 15 Jan 2026 12:29:01 -0500 X-MC-Unique: _cb9CclFOJWL4zKUMT6BVw-1 X-Mimecast-MFC-AGG-ID: _cb9CclFOJWL4zKUMT6BVw_1768498140 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 03D1A18005AE; Thu, 15 Jan 2026 17:29:00 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 74E6E18004D8; Thu, 15 Jan 2026 17:28:55 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Tiezhu Yang , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 14/18] rtla/timerlat: Simplify RTLA_NO_BPF environment variable check Date: Thu, 15 Jan 2026 13:31:57 -0300 Message-ID: <20260115163650.118910-15-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The code that checks the RTLA_NO_BPF environment variable calls getenv() twice and uses strncmp() with a length of 2 to compare against the single-character string "1". This is inefficient and the comparison length is unnecessarily long. Store the result of getenv() in a local variable to avoid the redundant call, and replace strncmp() with strcmp() for the exact match comparison. This follows the same pattern established in recent commits that improved string comparison consistency throughout the rtla codebase. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/timerlat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/tracing/rtla/src/timerlat.c b/tools/tracing/rtla/src/tim= erlat.c index 84577daadd668..d7aeaad975386 100644 --- a/tools/tracing/rtla/src/timerlat.c +++ b/tools/tracing/rtla/src/timerlat.c @@ -28,12 +28,13 @@ int timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_params *p= arams) { int retval; + const char *const rtla_no_bpf =3D getenv("RTLA_NO_BPF"); =20 /* * Try to enable BPF, unless disabled explicitly. * If BPF enablement fails, fall back to tracefs mode. */ - if (getenv("RTLA_NO_BPF") && strncmp(getenv("RTLA_NO_BPF"), "1", 2) =3D= =3D 0) { + if (rtla_no_bpf && strcmp(rtla_no_bpf, "1") =3D=3D 0) { debug_msg("RTLA_NO_BPF set, disabling BPF\n"); params->mode =3D TRACING_MODE_TRACEFS; } else if (!tep_find_event_by_name(tool->trace.tep, "osnoise", "timerlat_= sample")) { --=20 2.52.0 From nobody Sun Feb 8 06:00:00 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C54B3C1FCC for ; Thu, 15 Jan 2026 17:29:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498169; cv=none; b=AxV7ApXu4LE9ygkNwPrH77/gXyfx+zr4ArCzk/7bHd9RamectBXp0M/pSFGT/vor41JTZG4wb+0hSgryeL6RZAvErhzgU8FMVskxlWDeViH/L5e0biRfr6HZ4TymF7KhRS4kcg6684KS3kVehK6trXWaHkIzxNAw27J668THoZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498169; c=relaxed/simple; bh=/8OuF00pp6FFiPuSw3AMppL0kz8wKPiLAYLFZ1Ivp8E=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HN2Fi2R6iAt/i8/Wm61VhZo7cTLRr5Z1rzejQsGViIhRZx4syydwyyzsQJ9XrQ/9tafULG7rVxaeOWOZ5zCCiXllF8kr6h4mo4GtIPXtia2GKKoSZXbMH0pkKLePXu6ukzo7cqQUsPIQLDNpdE4F1BpvjcR3dB8oq8fvrR2g7Hw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Xm+4k2PS; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Xm+4k2PS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768498167; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KbxiRjdWmA02eWzJj/JqfOkUupAYpZjuI15c7UU19T8=; b=Xm+4k2PSsEWfCgiX2mLiHgjN1SE6exXarf5X8gtqCxvjNkSFrxdmnA2PxW1oCrv9O64cy3 pRyTb5pm+NiW20yRJDukykQ+WErAUxYKJp8YFnXwuFiBvlwmOyKLn7QEgP4fBmIMqGxQYK oQBStNwXPdVZ8ZMSclVdTdeuDMvxsTY= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-461-uGbfuLnvMPe36yLhCBSY2w-1; Thu, 15 Jan 2026 12:29:24 -0500 X-MC-Unique: uGbfuLnvMPe36yLhCBSY2w-1 X-Mimecast-MFC-AGG-ID: uGbfuLnvMPe36yLhCBSY2w_1768498160 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3B94B180045C; Thu, 15 Jan 2026 17:29:20 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 677AC1800285; Thu, 15 Jan 2026 17:29:15 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Haiyong Sun , Tiezhu Yang , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 15/18] rtla/trace: Fix write loop in trace_event_save_hist() Date: Thu, 15 Jan 2026 13:31:58 -0300 Message-ID: <20260115163650.118910-16-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The write loop in trace_event_save_hist() does not correctly handle errors from the write() system call. If write() returns -1, this value is added to the loop index, leading to an incorrect memory access on the next iteration and potentially an infinite loop. The loop also fails to handle EINTR. Fix the write loop by introducing proper error handling. The return value of write() is now stored in a ssize_t variable and checked for errors. The loop retries the call if interrupted by a signal and breaks on any other error after logging it with strerror(). Additionally, change the index variable type from int to size_t to match the type used for buffer sizes and by strlen(), improving type safety. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/trace.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index ed7db5f4115ce..fed3362527b08 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -342,11 +342,11 @@ static void trace_event_disable_filter(struct trace_i= nstance *instance, static void trace_event_save_hist(struct trace_instance *instance, struct trace_events *tevent) { - int index, out_fd; + size_t index, hist_len; mode_t mode =3D 0644; char path[MAX_PATH]; char *hist; - size_t hist_len; + int out_fd; =20 if (!tevent) return; @@ -378,7 +378,15 @@ static void trace_event_save_hist(struct trace_instanc= e *instance, index =3D 0; hist_len =3D strlen(hist); do { - index +=3D write(out_fd, &hist[index], hist_len - index); + const ssize_t written =3D write(out_fd, &hist[index], hist_len - index); + + if (written < 0) { + if (errno =3D=3D EINTR) + continue; + err_msg(" Error writing hist file: %s\n", strerror(errno)); + break; + } + index +=3D written; } while (index < hist_len); =20 free(hist); --=20 2.52.0 From nobody Sun Feb 8 06:00:00 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A4113C1FCF for ; Thu, 15 Jan 2026 17:29:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498188; cv=none; b=IwEzBFVaUiOZ2WKPFXRLJoB3G1nJC4UAB1XVxEhHJVmxA1usVeWacKsdgsNCSijpF/fhrb02+jtLFSuEmgpkBs9KE2a3aLQtQJyEa9ciU/+G3LvLH9UBj6mEk+gMYL9FWxteTMJVLSxU3WiNzNQtmQwSq8fqrhJ/TwRA4mbcG7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498188; c=relaxed/simple; bh=ShCFLV0cl6uWodOfkKPQsW7EQxQrPSPPxjVzA5jQP5o=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RykCgFZFOvyTYc+1QFRwTzBeh7fcTO2Z5I1iy39hWPojTIyz+gg48RV8lM7K3EKGmBRWs8nYTDd0tXG7hIf+jYcFdUTx7x7cB8AQQQX29EuH+OBd0fxXgk9YT4vuIjbpNjPg2TK5amNxe7tS/o9JrcFa3SyW8nZnjzWM88E+aD0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XgaguXvc; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XgaguXvc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768498184; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w3Gh9XqLfm/ta5RTgIzRh8pa4KVIwrKEpFGs+x5qjPA=; b=XgaguXvclvpGLuHxfeNvlPbB0vmDjt6h1ucBVnR7pLkKejS4PcBHPLEQR1G93RLOEJfXQo 64ysGR1I5EEd/dnQOyfJtLUKHNJ50qbrW8aIXjBSCkKNiP0OwGA4+Fk4y9fiOU+fSXH++o b4YAB+G2l9uIUXWFwIyRwG80px8R55Y= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-175-Gw0g7wEEMaiF07PzifD5pw-1; Thu, 15 Jan 2026 12:29:42 -0500 X-MC-Unique: Gw0g7wEEMaiF07PzifD5pw-1 X-Mimecast-MFC-AGG-ID: Gw0g7wEEMaiF07PzifD5pw_1768498180 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7DA5E1954B24; Thu, 15 Jan 2026 17:29:40 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AC76818004D8; Thu, 15 Jan 2026 17:29:35 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Ivan Pravdin , Crystal Wood , Costa Shulyupin , John Kacur , Haiyong Sun , Tiezhu Yang , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 16/18] rtla/trace: Fix I/O handling in save_trace_to_file() Date: Thu, 15 Jan 2026 13:31:59 -0300 Message-ID: <20260115163650.118910-17-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The read/write loop in save_trace_to_file() does not correctly handle errors from the read() and write() system calls. If either call is interrupted by a signal, it returns -1 with errno set to EINTR, but the code treats this as a fatal error and aborts the save operation. Additionally, write() may perform a partial write, returning fewer bytes than requested, which the code does not handle. Fix the I/O loop by introducing proper error handling. The return value of read() is now stored in a ssize_t variable and checked for errors, with EINTR causing a retry. For write(), an inner loop ensures all bytes are written, handling both EINTR and partial writes. Error messages now include strerror() output for better debugging. This follows the same pattern established in the previous commit that fixed trace_event_save_hist(), ensuring consistent and robust I/O handling throughout the trace saving code. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/trace.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index fed3362527b08..8e93b48d33ef8 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -73,6 +73,7 @@ int save_trace_to_file(struct tracefs_instance *inst, con= st char *filename) char buffer[4096]; int out_fd, in_fd; int retval =3D -1; + ssize_t n_read; =20 if (!inst || !filename) return 0; @@ -90,15 +91,30 @@ int save_trace_to_file(struct tracefs_instance *inst, c= onst char *filename) goto out_close_in; } =20 - do { - retval =3D read(in_fd, buffer, sizeof(buffer)); - if (retval <=3D 0) + for (;;) { + n_read =3D read(in_fd, buffer, sizeof(buffer)); + if (n_read < 0) { + if (errno =3D=3D EINTR) + continue; + err_msg("Error reading trace file: %s\n", strerror(errno)); goto out_close; + } + if (n_read =3D=3D 0) + break; =20 - retval =3D write(out_fd, buffer, retval); - if (retval < 0) - goto out_close; - } while (retval > 0); + ssize_t n_written =3D 0; + while (n_written < n_read) { + ssize_t w =3D write(out_fd, buffer + n_written, n_read - n_written); + + if (w < 0) { + if (errno =3D=3D EINTR) + continue; + err_msg("Error writing trace file: %s\n", strerror(errno)); + goto out_close; + } + n_written +=3D w; + } + } =20 retval =3D 0; out_close: --=20 2.52.0 From nobody Sun Feb 8 06:00:00 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F26D33D523E for ; Thu, 15 Jan 2026 17:30:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498208; cv=none; b=BlBnOAZxhV3fj7g+NJTZZ1DVC8I0hqYze68vREYCTWIUY4+av/ISfHvKmEmUnmyd1kXAaLwObyQrO8aJX5Cs/36EJ4ygM4hC7U6GrJio36PBDMl3APMHfVmInFfrRFuL9acGbeZWZUCdMAUhL0rFHd/5Cw2Z3QwO03RGDhl//ZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498208; c=relaxed/simple; bh=pcZuVBEpKHuMkiFAbHRlsLm6TtFLtJutf7CGGP8HEhs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jFKVq0iGUUiJ1NlOc4R/yPeND4+a35DxIchSijHVjRablqUuhNIXds19PEs+g65oySO/XF5g4Ksd0c6Pvm7zP5byAkf6fZ3fD9E5wYJxO59ftIGnKZbYDcG7FEkIJOQUJnn4kXON2+EvaA2v+X0nPJkL81x5IB13Jd518boSFac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NF+WwPYU; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NF+WwPYU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768498206; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uPVrOWC176arGNNcGQ7j00oHxNfVI2h958WatvwkW7A=; b=NF+WwPYUu+Wfr+qsoZ9W5v7PkJIKMkSvwoebkz9GgeoJOMseYKrtP6Ippuyq+0A0nzYeGX KPET5OBX8yugoL2TFXvfEzqxzevDE4qm+teKGa/EJfGMlWT/pISzHCygfHSq434Um80NAf KU/slBTqdQDYDMw7bj0RV7kUl+Oa3jw= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-30-xfMwIAJhMiSF0A-W9h2tGQ-1; Thu, 15 Jan 2026 12:30:02 -0500 X-MC-Unique: xfMwIAJhMiSF0A-W9h2tGQ-1 X-Mimecast-MFC-AGG-ID: xfMwIAJhMiSF0A-W9h2tGQ_1768498201 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EE91919560A3; Thu, 15 Jan 2026 17:30:00 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C874918004D8; Thu, 15 Jan 2026 17:29:55 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Ivan Pravdin , Crystal Wood , Costa Shulyupin , John Kacur , Haiyong Sun , Tiezhu Yang , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 17/18] rtla/utils: Fix resource leak in set_comm_sched_attr() Date: Thu, 15 Jan 2026 13:32:00 -0300 Message-ID: <20260115163650.118910-18-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The set_comm_sched_attr() function opens the /proc directory via opendir() but fails to call closedir() on its successful exit path. If the function iterates through all processes without error, it returns 0 directly, leaking the DIR stream pointer. Fix this by refactoring the function to use a single exit path. A retval variable is introduced to track the success or failure status. All exit points now jump to a unified out label that calls closedir() before the function returns, ensuring the resource is always freed. Fixes: dada03db9bb19 ("rtla: Remove procps-ng dependency") Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/utils.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index b029fe5970c31..1ea9980d8ecd3 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -362,22 +362,23 @@ int set_comm_sched_attr(const char *comm_prefix, stru= ct sched_attr *attr) =20 if (strtoi(proc_entry->d_name, &pid)) { err_msg("'%s' is not a valid pid", proc_entry->d_name); - goto out_err; + retval =3D 1; + goto out; } /* procfs_is_workload_pid confirmed it is a pid */ retval =3D __set_sched_attr(pid, attr); if (retval) { err_msg("Error setting sched attributes for pid:%s\n", proc_entry->d_na= me); - goto out_err; + goto out; } =20 debug_msg("Set sched attributes for pid:%s\n", proc_entry->d_name); } - return 0; =20 -out_err: + retval =3D 0; +out: closedir(procfs); - return 1; + return retval; } =20 #define INVALID_VAL (~0L) --=20 2.52.0 From nobody Sun Feb 8 06:00:00 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 797953D3315 for ; Thu, 15 Jan 2026 17:30:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498228; cv=none; b=mf0OeUwb5GZvlb+sazkza1Moq7t/cUcdj1zQnlMGNoxGSENcsolOF8x87cspZOo9Y4HKFQdmii90tNGKvM6WDcnqILWacQZe4RMr3LGsmyCL5FpzftLpDfGGXMpKWWeCyoNZgo9KOy8jBhkuVhSA/OCPOxT0XVNvwJLYUkIR+YM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498228; c=relaxed/simple; bh=KoiAGygCsP7LdXIPJKl87sZsR/SSo6UkoSgUMxQy9Hc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tnIUcZ5J6rsYhBya8vC9DnHo4Q+6hLOy2AfIr25fLClpTufHgyPX6IxSnixqvY/W7wU8xD6lrNqg2P8GL3ujPdYkoVyoxyt/JDK98n25CsJB83X4V5gssd80EaYIrpVar/90xptBbwJaS8ol/Pi06L/7dyO15+8F7Col5UfsIW4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Usdy7Oki; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Usdy7Oki" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768498226; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2Tu3p1Zj6pQY7Vz4/LZDPBl0XAGrdE37S9bZ1+G2txM=; b=Usdy7Okiq4jRPz7zIVo3XpZ1vimWSlL0KGeyMyD51AK+i4CIsr1nilWAVZoDFuVmriOD0Y EqjiOJa0K28J+i8o2FTlo2SdGt+I/1GACWsOPppzyCfEmlyWLchrGxlA4FvOw7HsjCYhzb XIaLwAB3a78FzfwB6VIKuxHZ8HkgG3k= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-573-F7Y7gd1ZOAmofL9UcD7uvg-1; Thu, 15 Jan 2026 12:30:22 -0500 X-MC-Unique: F7Y7gd1ZOAmofL9UcD7uvg-1 X-Mimecast-MFC-AGG-ID: F7Y7gd1ZOAmofL9UcD7uvg_1768498220 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A82EF19560B5; Thu, 15 Jan 2026 17:30:20 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 194AC1800285; Thu, 15 Jan 2026 17:30:15 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Tiezhu Yang , Daniel Wagner , Daniel Bristot de Oliveira , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v3 18/18] rtla/utils: Fix loop condition in PID validation Date: Thu, 15 Jan 2026 13:32:01 -0300 Message-ID: <20260115163650.118910-19-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" 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 --- tools/tracing/rtla/src/utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index 1ea9980d8ecd3..3d47f3ed52dee 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -296,7 +296,7 @@ static int procfs_is_workload_pid(const char *comm_pref= ix, struct dirent *proc_e return 0; =20 /* check if the string is a pid */ - for (t_name =3D proc_entry->d_name; t_name; t_name++) { + for (t_name =3D proc_entry->d_name; *t_name; t_name++) { if (!isdigit(*t_name)) break; } --=20 2.52.0