From nobody Sat Feb 7 15:40:24 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 40494225413 for ; Tue, 6 Jan 2026 13:37:46 +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=1767706670; cv=none; b=msOsGXgIc9CjtagweMpWEXic27LuOY6Ha6issZgEp8pbbSRjsQaLt6dsSoV3cVgg8I/aWd5oulLGMRgC3Gswd9U+H3gUGgxUSSO+qBzVsyQcooXKPetrhaxO+vOoOSEt55aJ0IxfBItfXjvym3gKoCv49azY9KhJhdNNJPsfXp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767706670; c=relaxed/simple; bh=ay3+o11g3F2973EBIkCobkS+UPKn9HW13yLOwFXa/gA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ltrzDiQcmJwH2ql0pj2WuMuPjM+Ar6eocaZSFTiEhHtdOz3fSJokR6myNB7tJ9sWu7caZWjI6XyFPnGP20kE6IEQZNCepxwy0vjGXytNonmNCuJWMLCuRe3yZAav7lIcQu0EQRjtOGBK9+7dLw/BO9Zpdi2ryhOI0eS8wrWo1aU= 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=NBCgI8Y0; 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="NBCgI8Y0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767706664; 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=9s5apwvrI9NS4GcATbs3y34CNvepD5CAt4yXpK84c9Q=; b=NBCgI8Y0avwkRryXzhcwi/avtZewwQ9JA5Ouqf7Yvwxfi9nZHaCQJNzt2O5RkGMjRNJaG8 l9T0PuQ/po1is+7FqOB0DX5zObcPhEyVMzGjtI8zFnxbnlMgoyUKd6spXBzttqJFIw/3RQ zRxxLvx8IMt4/78PskWUyiNgYxrwzQo= 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-135-JRqNGrupOfusSZUQdTVqRQ-1; Tue, 06 Jan 2026 08:37:41 -0500 X-MC-Unique: JRqNGrupOfusSZUQdTVqRQ-1 X-Mimecast-MFC-AGG-ID: JRqNGrupOfusSZUQdTVqRQ_1767706660 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 0727E1956053; Tue, 6 Jan 2026 13:37:40 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A9958180035A; Tue, 6 Jan 2026 13:37:35 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Tiezhu Yang , 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 v2 01/18] rtla: Exit on memory allocation failures during initialization Date: Tue, 6 Jan 2026 08:49:37 -0300 Message-ID: <20260106133655.249887-2-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-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 | 25 ++++--------- tools/tracing/rtla/src/osnoise_top.c | 25 ++++--------- tools/tracing/rtla/src/timerlat_hist.c | 24 ++++--------- tools/tracing/rtla/src/timerlat_top.c | 25 ++++--------- 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(+), 143 deletions(-) diff --git a/tools/tracing/rtla/src/actions.c b/tools/tracing/rtla/src/acti= ons.c index 8945aee58d511..ff7811e175930 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 /* @@ -174,7 +164,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) { @@ -197,21 +188,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 a4f9b570775b5..fb366d6509b8b 100644 --- a/tools/tracing/rtla/src/actions.h +++ b/tools/tracing/rtla/src/actions.h @@ -44,9 +44,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 312c511fa0044..c5b41ec26b0a4 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 ff8c231e47c47..af7d8621dd9d7 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -474,9 +474,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); @@ -564,9 +562,6 @@ static struct common_params break; case 'e': tevent =3D trace_event_alloc(optarg); - if (!tevent) - fatal("Error alloc trace event"); - if (params->common.events) tevent->next =3D params->common.events; =20 @@ -631,22 +626,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 04c699bdd7363..31b7e92d76fe4 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -327,9 +327,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,9 +408,6 @@ struct common_params *osnoise_top_parse_args(int argc, = char **argv) break; case 'e': tevent =3D trace_event_alloc(optarg); - if (!tevent) - fatal("Error alloc trace event"); - if (params->common.events) tevent->next =3D params->common.events; params->common.events =3D tevent; @@ -462,22 +457,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 1fb471a787b79..226167c88c8d6 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -772,9 +772,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); @@ -883,8 +881,6 @@ static struct common_params break; case 'e': tevent =3D trace_event_alloc(optarg); - if (!tevent) - fatal("Error alloc trace event"); =20 if (params->common.events) tevent->next =3D params->common.events; @@ -963,22 +959,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 29c2c1f717ed7..31e1514a2528d 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -544,9 +544,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); @@ -655,9 +653,6 @@ static struct common_params break; case 'e': tevent =3D trace_event_alloc(optarg); - if (!tevent) - fatal("Error alloc trace event"); - if (params->common.events) tevent->next =3D params->common.events; params->common.events =3D tevent; @@ -713,22 +708,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 69cbc48d53d3a..b22bb844b71f3 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -192,9 +192,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 @@ -275,15 +273,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) { @@ -297,31 +289,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 9cf5a0098e9aa..acf95afa25b5a 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -1000,3 +1000,38 @@ char *parse_optional_arg(int argc, char **argv) return NULL; } } + +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 091df4ba45877..0ed2c7275f2c5 100644 --- a/tools/tracing/rtla/src/utils.h +++ b/tools/tracing/rtla/src/utils.h @@ -68,6 +68,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 Sat Feb 7 15:40:24 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 C189A3328F8 for ; Tue, 6 Jan 2026 13:39:12 +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=1767706754; cv=none; b=qmhyQhB9/smh8bIChgszVdDlmgboywxm4EylhgX1SK9vjl6ZNZk17C7g6Gn6+r3q9/R1511Dw2ZDJyNkxmKt7GDYcUA9o4EodcMDDN+aW+79SfGE9sOb9s9sibyg0waZka6YiAEQ3BvyyjOutFRiizkA3GzlJDZYyc4ffgUL9DM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767706754; c=relaxed/simple; bh=I6Y2Bnj5DjlTKswbTwkLRHVOQ3wPXG/AMGsGn2yZi04=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dr1DSHInifNTgoCGRNBjbNGPZC0WM05r4wfT5aS48yS6edurAMitDgxVd4KECubobF2Jxa2weuq4iinbgUiriPPLIM8ot/gnZHDuFv8vpXezCPLm22HsNfI9rrTwgURd18PKuXQ4VN3sAm31WePGhjzZqm4cZNwGF25hhUV5b1g= 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=IJqlgTqD; 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="IJqlgTqD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767706751; 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=5uaMzECtULTxucImjVPwH8LTz8bTXnv1pm1HYLWyzkw=; b=IJqlgTqDeAZZ31BgOqThcvrQ/OhGV9e7nYEdt8LZUaeDkoOKID1rD6058FJRXTSoQNeZkX 7CGOMm7XeEdDfq4nncul6/sMcFyRvW2Axuj9M7i4A99qTXEMGekKmYE7IgOQI9xW+nU0/S Hi6bgzUD7fiRRwjO2IBJ40YfqZ7y5vE= 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-553-tYE0V7fbMImPiH-ewnz63g-1; Tue, 06 Jan 2026 08:39:08 -0500 X-MC-Unique: tYE0V7fbMImPiH-ewnz63g-1 X-Mimecast-MFC-AGG-ID: tYE0V7fbMImPiH-ewnz63g_1767706747 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 0E1F41800625; Tue, 6 Jan 2026 13:39:07 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 23BD2180035A; Tue, 6 Jan 2026 13:39:02 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Ivan Pravdin , Crystal Wood , Costa Shulyupin , John Kacur , Tiezhu Yang , 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 v2 02/18] rtla: Use strdup() to simplify code Date: Tue, 6 Jan 2026 08:49:38 -0300 Message-ID: <20260106133655.249887-3-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-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 ff7811e175930..090d514fe4126 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 Sat Feb 7 15:40:24 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 1EA293321BF for ; Tue, 6 Jan 2026 13:39:53 +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=1767706797; cv=none; b=VMmgK1yLICxKUkCjemPRq2mnOuVfyKBOQL2mxlvFO89EO/TluEaRM8d6Xf+GQ+DWjcSDt27M2+0ghiZ5RYO6r5xgFVctGqjlNlx+pxU041XX8XxM0WSGXq9vOWzLOK3Hg9SgSM1WI4+vN221YUXqDr02WdH9IS4ok4kyIPVGW40= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767706797; c=relaxed/simple; bh=2eL6u1tYXRr0f4T07e3bqQR8vmyHHp/n5Y06Uc7Bdt0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ExvLHu2u9ZBEHpRDnsHXBpKwF++SpF4ePnr0nNjz6K6NO5mmH2jVKlR2RK9gORE7afCWFffDgHVBxOPsb1rzixz5Ip5KXOyfwhdJ+uHzD2IHDWupsIUe45yglY306G0I6nxBQqZIk7TCm0Adk8F1sN5/vlYkOt8eDc2ovsqN1FU= 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=TPqIuR8S; 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="TPqIuR8S" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767706791; 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=9x6woanR4M28vlHIWpobUJ+jS/qyut7AGYHXp5l5JGc=; b=TPqIuR8ShvCk/0Wdb8u2WjjuYHvBla6hUbvVPn/8LLBuaFdlDLYGJUkhrg4jPKkx2nFr4B H5qXgpVV0d2YsBu6Vt6124WBFDrxJsu/zdPm5zuB5tCd4Mljm/FsPPiV758Xqto4oMdZUd OG8Bjw1xclc/SxHU6saYh4SXSF+oT08= 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-307--aQgs27MOXSidvNkQQP4JQ-1; Tue, 06 Jan 2026 08:39:46 -0500 X-MC-Unique: -aQgs27MOXSidvNkQQP4JQ-1 X-Mimecast-MFC-AGG-ID: -aQgs27MOXSidvNkQQP4JQ_1767706784 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 EF8611800654; Tue, 6 Jan 2026 13:39:43 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AA0251800367; Tue, 6 Jan 2026 13:39:39 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Tiezhu Yang , 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 v2 03/18] rtla: Introduce for_each_action() helper Date: Tue, 6 Jan 2026 08:49:39 -0300 Message-ID: <20260106133655.249887-4-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-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 for loop to iterate over the list of actions is used in more than one place. To avoid code duplication and improve readability, introduce a for_each_action() helper macro. Replace the open-coded for loops with the new helper. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/actions.c | 6 ++++-- tools/tracing/rtla/src/actions.h | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/tracing/rtla/src/actions.c b/tools/tracing/rtla/src/acti= ons.c index 090d514fe4126..a4d0dc47e6aa1 100644 --- a/tools/tracing/rtla/src/actions.c +++ b/tools/tracing/rtla/src/actions.c @@ -32,7 +32,9 @@ void actions_destroy(struct actions *self) { /* Free any action-specific data */ - for (struct action *action =3D self->list; action < self->list + self->le= n; action++) { + struct action *action; + + for_each_action(self, action) { if (action->type =3D=3D ACTION_SHELL) free(action->command); if (action->type =3D=3D ACTION_TRACE_OUTPUT) @@ -217,7 +219,7 @@ actions_perform(struct actions *self) int pid, retval; const struct action *action; =20 - for (action =3D self->list; action < self->list + self->len; action++) { + for_each_action(self, action) { switch (action->type) { case ACTION_TRACE_OUTPUT: retval =3D save_trace_to_file(self->trace_output_inst, action->trace_ou= tput); diff --git a/tools/tracing/rtla/src/actions.h b/tools/tracing/rtla/src/acti= ons.h index fb366d6509b8b..034048682fefb 100644 --- a/tools/tracing/rtla/src/actions.h +++ b/tools/tracing/rtla/src/actions.h @@ -42,6 +42,11 @@ struct actions { struct tracefs_instance *trace_output_inst; }; =20 +#define for_each_action(actions, action) \ + for ((action) =3D (actions)->list; \ + (action) < (actions)->list + (actions)->len; \ + (action)++) + void actions_init(struct actions *self); void actions_destroy(struct actions *self); void actions_add_trace_output(struct actions *self, const char *trace_outp= ut); --=20 2.52.0 From nobody Sat Feb 7 15:40:24 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 95317334C1E for ; Tue, 6 Jan 2026 13:40: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=1767706829; cv=none; b=W5gj9YAwTHCCRe/M5dnnF0bbyQJi+niK9VUmfQPAKYqh4EO6ICTbsR6pZeS0dXsBYo7KFuQNvvhm1aY7YHd47IoGHkoYe9jtkKqXIykdEf7VLeWlEFCxYhihSwGjMWr/S+uACQMEdd7RRPAiIRauy9CiePjSXp6XjRFnHg0s68U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767706829; c=relaxed/simple; bh=C9pPSqrNCCRKwBOuAOsgJ4xElCRCsaFzDGm/+khZD3Q=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DEyNmw79zHB1ZMVXoXVNcDQtRiGBrhEGJVYwXbGzqYnUkvMVofX8aQtNQCkBmkoCOVm+OeiwymbQdYfYkpyV4AfZKFQNKjAHyqH2b5YeKxJIFGRnmscJdWR6rmJ5tGTSUmi3Cl6f3x+tHeErUsfhL7C6a82oetyZKlJ0rKjcvkQ= 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=EwcDltG4; 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="EwcDltG4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767706826; 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=nmP8xBHdWYkSAZWCXGpMjJAhpv6Mw36u53Y1D1y92fw=; b=EwcDltG4rKfg22A/u7wAB00MXEoctQ8C8HWcEYjyg3xZnqcOquTH4hrEw6Qnt63DXcVEPV pBphdHNfdRwZWnnv6GtOAPNGmTe9JPIkqxB4vwG2hGh+3AOLJ057Zh2KlsD+X0VyZNSAUd 7fRPnGERafw8VcKJ7srKpDV5PYWR/m8= 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-30-aG-OJuyVMCKFReBgsuGUQQ-1; Tue, 06 Jan 2026 08:40:22 -0500 X-MC-Unique: aG-OJuyVMCKFReBgsuGUQQ-1 X-Mimecast-MFC-AGG-ID: aG-OJuyVMCKFReBgsuGUQQ_1767706821 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 B29231956095; Tue, 6 Jan 2026 13:40:21 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CCA2F180066B; Tue, 6 Jan 2026 13:40:15 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Ivan Pravdin , Crystal Wood , Costa Shulyupin , John Kacur , Tiezhu Yang , 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 v2 04/18] rtla: Replace atoi() with a robust strtoi() Date: Tue, 6 Jan 2026 08:49:40 -0300 Message-ID: <20260106133655.249887-5-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-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 atoi() function does not perform error checking, which can lead to undefined behavior when parsing invalid or out-of-range strings. This can cause issues when parsing user-provided numerical inputs, such as signal numbers, PIDs, or CPU lists. To address this, introduce a new strtoi() helper function that safely converts a string to an integer. This function validates the input and checks for overflows, returning a negative value on failure. Replace all calls to atoi() with the new strtoi() function and add proper error handling to make the parsing more robust and prevent potential issues. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/actions.c | 7 +++--- tools/tracing/rtla/src/utils.c | 40 ++++++++++++++++++++++++++++---- tools/tracing/rtla/src/utils.h | 2 ++ 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/tools/tracing/rtla/src/actions.c b/tools/tracing/rtla/src/acti= ons.c index a4d0dc47e6aa1..e933c2c68b208 100644 --- a/tools/tracing/rtla/src/actions.c +++ b/tools/tracing/rtla/src/actions.c @@ -170,12 +170,13 @@ actions_parse(struct actions *self, const char *trigg= er, const char *tracefn) /* Takes two arguments, num (signal) and pid */ while (token !=3D NULL) { if (strlen(token) > 4 && strncmp(token, "num=3D", 4) =3D=3D 0) { - signal =3D atoi(token + 4); + 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 - pid =3D atoi(token + 4); + else if (strtoi(token + 4, &pid)) + return -1; } else { /* Invalid argument */ return -1; diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index acf95afa25b5a..f3e129d17a82b 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -17,6 +17,7 @@ #include #include #include +#include =20 #include "utils.h" =20 @@ -127,16 +128,18 @@ int parse_cpu_set(char *cpu_list, cpu_set_t *set) nr_cpus =3D sysconf(_SC_NPROCESSORS_CONF); =20 for (p =3D cpu_list; *p; ) { - cpu =3D atoi(p); - if (cpu < 0 || (!cpu && *p !=3D '0') || cpu >=3D nr_cpus) + if (strtoi(p, &cpu)) + goto err; + if (cpu < 0 || cpu >=3D nr_cpus) goto err; =20 while (isdigit(*p)) p++; if (*p =3D=3D '-') { p++; - end_cpu =3D atoi(p); - if (end_cpu < cpu || (!end_cpu && *p !=3D '0') || end_cpu >=3D nr_cpus) + if (strtoi(p, &end_cpu)) + goto err; + if (end_cpu < cpu || end_cpu >=3D nr_cpus) goto err; while (isdigit(*p)) p++; @@ -337,6 +340,7 @@ int set_comm_sched_attr(const char *comm_prefix, struct= sched_attr *attr) struct dirent *proc_entry; DIR *procfs; int retval; + int pid; =20 if (strlen(comm_prefix) >=3D MAX_PATH) { err_msg("Command prefix is too long: %d < strlen(%s)\n", @@ -356,8 +360,12 @@ int set_comm_sched_attr(const char *comm_prefix, struc= t sched_attr *attr) if (!retval) continue; =20 + if (strtoi(proc_entry->d_name, &pid)) { + err_msg("'%s' is not a valid pid", proc_entry->d_name); + goto out_err; + } /* procfs_is_workload_pid confirmed it is a pid */ - retval =3D __set_sched_attr(atoi(proc_entry->d_name), attr); + 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; @@ -1035,3 +1043,25 @@ char *strdup_fatal(const char *s) =20 return p; } + +/* + * strtoi - convert string to integer with error checking + * + * Returns 0 on success, -1 if conversion fails or result is out of int ra= nge. + */ +int strtoi(const char *s, int *res) +{ + char *end_ptr; + long lres; + + if (!*s) + return -1; + + errno =3D 0; + lres =3D strtol(s, &end_ptr, 0); + if (errno || *end_ptr || lres > INT_MAX || lres < INT_MIN) + return -1; + + *res =3D (int) lres; + return 0; +} diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h index 0ed2c7275f2c5..efbf798650306 100644 --- a/tools/tracing/rtla/src/utils.h +++ b/tools/tracing/rtla/src/utils.h @@ -3,6 +3,7 @@ #include #include #include +#include =20 /* * '18446744073709551615\0' @@ -85,6 +86,7 @@ static inline int set_deepest_cpu_idle_state(unsigned int= cpu, unsigned int stat 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= ); =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 Sat Feb 7 15:40:24 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 2BB1233C53D for ; Tue, 6 Jan 2026 13:41:05 +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=1767706867; cv=none; b=i89+ZpVAz5oFTkn3bnTZRSHmgylysjngu9vzCFB/YHUdCTn06gwLmiP/+xRjb0L9Vb0ZedBVs/d7pUYz3dj0KZ0iulrn4eOuMqSBpqIQG5lJRFaOnK8IWVYLqczxGbu/SVY+ITKC91fygkeKvCNfQtu30AiRKWZgfOvud4lRLwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767706867; c=relaxed/simple; bh=ijhR3i1gavKundTTF+SyXMl11p58jCX5UvqYieE4d9g=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oPOZw2v5IJWCCdcp1F4YA7zcdTgEkVbyobz8HgSZmUHeVHE53ks4qDv6QnOkWHE129dRIj+Q0z2IzuMlwL01o5bNxgCkPWQ9TJelcPhvphu19dVhJ4ryKWBaDBGD5VWlDnjSueFtc8g12YqXXyhbq1pjsAesBHa0Hs9IzkXmcdI= 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=Ew3/qBF1; 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="Ew3/qBF1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767706865; 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=WL7clRY6ZrnFyBLMlVvLXH34kZISJ+Yx3LR2pif4tUA=; b=Ew3/qBF1qcB3n+Kzumu6MeOasrppaDptKsqPUwXn0QiA0MzL2XbxHc3ztIDQDWp/FzRtjw mvLRBOfTXPmU5HHbdy+gi6lQ850MVfgTHkI2SbkcyLhKecOcQCKjymEy1qdHjnRVz5ae5H BZYFdxQQs4r/aLBE8umwozXYRZDHnFw= 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-647-bOnU7qCXNTu2bRFet3SiNw-1; Tue, 06 Jan 2026 08:41:01 -0500 X-MC-Unique: bOnU7qCXNTu2bRFet3SiNw-1 X-Mimecast-MFC-AGG-ID: bOnU7qCXNTu2bRFet3SiNw_1767706859 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 C2B991800358; Tue, 6 Jan 2026 13:40:59 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8E05D1800367; Tue, 6 Jan 2026 13:40:55 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Ivan Pravdin , Crystal Wood , Costa Shulyupin , John Kacur , Tiezhu Yang , 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 v2 05/18] rtla: Simplify argument parsing Date: Tue, 6 Jan 2026 08:49:41 -0300 Message-ID: <20260106133655.249887-6-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-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 e933c2c68b208..b50bf9f9adf28 100644 --- a/tools/tracing/rtla/src/actions.c +++ b/tools/tracing/rtla/src/actions.c @@ -113,6 +113,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 */ @@ -122,6 +145,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 efbf798650306..7fa3ac5e0bfb6 100644 --- a/tools/tracing/rtla/src/utils.h +++ b/tools/tracing/rtla/src/utils.h @@ -13,8 +13,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, STRING_LENGTH(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 Sat Feb 7 15:40:24 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 01EC433D6E1 for ; Tue, 6 Jan 2026 13:41:44 +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=1767706906; cv=none; b=Xwxf9Bf46vxUU7HSbZtmzpPZCWdLQolRz2uxqmZN4zYBArrX49rzILEW7MJTjxWm2RYRW13QmbFH+wE3VhUS1A8cQ+7p1fiR0o9ZjU2Co7dOXoOwqeahwos8odBpv1mEQBXu3uk0eZ1m7hr/4WbYucg7I3Ce1oUH7yh3JDC5oGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767706906; c=relaxed/simple; bh=FIQU6/noRh/DqRmJSN92ZNNQKs6OnQ2XEwbcrtd2R5g=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=moBpIC5RhdPIViSStKWk5749N9ogipwT1xK+62W7Ud2ehUec15EdR6YIQfIQN2HGKquWM5rv51bCwmcz1oV9anIsHR7pWmDs93+LewXwKAims2KooHVOvF+cllpNSwBIOXHIbZZhZpZk0igFJ/1+9fDIl7heD80JmZbbO1pPKhw= 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=Mfniaa4p; 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="Mfniaa4p" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767706904; 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=977R6OMVKeJ7HyZ84fNIsYfSl3IYsNqr8X/5/SqWz/w=; b=Mfniaa4pVNZIECO52ZMlX+uwsRJLacCmZ3lfnxPUut1IYF/WjBkOqQGxQKAP8LOfkjtdv0 OmbRbaUahTzoUDSlKnHmlJrhL0UD3w8yvlx2fgN2EwkVCne04baGe2i2D9TwsMgPCOFuP2 q0A6Vw+KcOaU4irc20IZJxs+ez2NC8w= 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-427-IV61w0_OOneAqtSBBtN4ng-1; Tue, 06 Jan 2026 08:41:38 -0500 X-MC-Unique: IV61w0_OOneAqtSBBtN4ng-1 X-Mimecast-MFC-AGG-ID: IV61w0_OOneAqtSBBtN4ng_1767706897 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 7722619560B2; Tue, 6 Jan 2026 13:41:37 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 17DE7180035A; Tue, 6 Jan 2026 13:41:33 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Tiezhu Yang , 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 v2 06/18] rtla: Use strncmp_static() in more places Date: Tue, 6 Jan 2026 08:49:42 -0300 Message-ID: <20260106133655.249887-7-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-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 recently introduced strncmp_static() helper provides a safer way to compare strings with static strings by determining the length at compile time. Replace several open-coded strncmp() calls with strncmp_static() to improve code readability and robustness. This change affects the parsing of command-line arguments and environment variables. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/osnoise.c | 2 +- tools/tracing/rtla/src/timerlat.c | 4 ++-- tools/tracing/rtla/src/trace.c | 2 +- tools/tracing/rtla/src/utils.c | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/tracing/rtla/src/osnoise.c b/tools/tracing/rtla/src/osno= ise.c index c5b41ec26b0a4..f2ec2da7b6d3a 100644 --- a/tools/tracing/rtla/src/osnoise.c +++ b/tools/tracing/rtla/src/osnoise.c @@ -1219,7 +1219,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 (strncmp_static(argv[1], "-") =3D=3D 0) { /* 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 df4f9bfe34331..ac2ec89d3b6ba 100644 --- a/tools/tracing/rtla/src/timerlat.c +++ b/tools/tracing/rtla/src/timerlat.c @@ -34,7 +34,7 @@ timerlat_apply_config(struct osnoise_tool *tool, struct t= imerlat_params *params) * 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 (getenv("RTLA_NO_BPF") && strncmp_static(getenv("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")) { @@ -271,7 +271,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 (strncmp_static(argv[1], "-") =3D=3D 0) { /* the user skipped the tool, call the default one */ run_tool(&timerlat_top_ops, argc, argv); exit(0); diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index b22bb844b71f3..45328c5121f79 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -356,7 +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:")); + retval =3D strncmp_static(tevent->trigger, "hist:"); if (retval) return; =20 diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index f3e129d17a82b..e0f31e5cae844 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 (!strncmp_static(end, "ns")) { return t; - } else if (!strncmp(end, "us", 2)) { + } else if (!strncmp_static(end, "us")) { t *=3D 1000; return t; - } else if (!strncmp(end, "ms", 2)) { + } else if (!strncmp_static(end, "ms")) { t *=3D 1000 * 1000; return t; - } else if (!strncmp(end, "s", 1)) { + } else if (!strncmp_static(end, "s")) { t *=3D 1000 * 1000 * 1000; return t; } --=20 2.52.0 From nobody Sat Feb 7 15:40:24 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 EC9DA33F368 for ; Tue, 6 Jan 2026 13:42:19 +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=1767706941; cv=none; b=Z5PjhOUtIyegnTg2IzY71zN3nVeY0aufA4kc7f+qJ3DX4G2B+aTNq1yviszSdNtnh7Ob8/mVBj8BQuirPtyNfZdKyayINpsf+5wqraIgSpyOIzIuHMCI7TmVP3DONX0iqyFQEl2Zjj2JfuLeQJQ9IIyasw52sfw7oxlcUfvZaU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767706941; c=relaxed/simple; bh=0WUPyK+qfDEixMaCU5x9MQ2nD7F+MVzr1/647jwgHt4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z3IqcO2F535boCEICtus9ihzCx9BzyoyiLQJhoiAVmamIkB8OxFfKC4xKT+o9L+7cZcSJF6cMOeV11q1qaCOUFeUOcW1bx+8JPNB6QhPqQfvyEXNibxkK1hzk/ltZMiFuc/xCecpwfwpach2ywlH3xsNg4Cy2r9Qbbf3nxzmhvk= 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=dJD6salG; 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="dJD6salG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767706938; 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=8ICpCfMygw2MMFHUKfb4+us+NT7ItdUncTrnLD4HZzk=; b=dJD6salG/AnWmmxkDbjh8PtI2QDP78VfI3Ny7NgnyWKZoiEnebMm1rk3E72CsuDWG6ouon RGIM83qkz213lM2SQZjlYZJ3Yv6aPrNEwH2QahGXk6vSC2DM4PgyPCrUJepyQFt2BHW9EW 5MxJlK927gaK1RhIOorOfRzr8VhvQKE= 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-524-dUzFzlorOKOf_rrI_PYaNQ-1; Tue, 06 Jan 2026 08:42:14 -0500 X-MC-Unique: dUzFzlorOKOf_rrI_PYaNQ-1 X-Mimecast-MFC-AGG-ID: dUzFzlorOKOf_rrI_PYaNQ_1767706933 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 659AD18011EE; Tue, 6 Jan 2026 13:42:13 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E2604180035A; Tue, 6 Jan 2026 13:42:09 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Tiezhu Yang , 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 v2 07/18] rtla: Introduce common_restart() helper Date: Tue, 6 Jan 2026 08:49:43 -0300 Message-ID: <20260106133655.249887-8-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-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" A few functions duplicate the logic for handling threshold actions. When a threshold is reached, these functions stop the trace, perform actions, and restart the trace if configured to continue. Create a new helper function, common_restart(), to centralize this shared logic and avoid code duplication. This function now handles the threshold actions and restarts the necessary trace instances. Refactor the affected functions main loops to call the new helper. This makes the code cleaner and more maintainable. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/common.c | 65 +++++++++++++++++++------- tools/tracing/rtla/src/common.h | 9 ++++ tools/tracing/rtla/src/timerlat_hist.c | 20 ++++---- tools/tracing/rtla/src/timerlat_top.c | 20 ++++---- 4 files changed, 78 insertions(+), 36 deletions(-) diff --git a/tools/tracing/rtla/src/common.c b/tools/tracing/rtla/src/commo= n.c index b197037fc58b3..d608ffe12e7b0 100644 --- a/tools/tracing/rtla/src/common.c +++ b/tools/tracing/rtla/src/common.c @@ -95,6 +95,37 @@ common_apply_config(struct osnoise_tool *tool, struct co= mmon_params *params) } =20 =20 +/** + * common_restart - handle threshold actions and optionally restart tracing + * @tool: pointer to the osnoise_tool instance containing trace contexts + * @params: timerlat parameters with threshold action configuration + * + * Return: + * RESTART_OK - Actions executed successfully and tracing restarted + * RESTART_STOP - Actions executed but 'continue' flag not set, stop tra= cing + * RESTART_ERROR - Failed to restart tracing after executing actions + */ +enum restart_result +common_restart(const struct osnoise_tool *tool, struct common_params *para= ms) +{ + actions_perform(¶ms->threshold_actions); + + if (!params->threshold_actions.continue_flag) + /* continue flag not set, break */ + return RESTART_STOP; + + /* 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 RESTART_OK; + +err: + err_msg("Error restarting trace\n"); + return RESTART_ERROR; +} + int run_tool(struct tool_ops *ops, int argc, char *argv[]) { struct common_params *params; @@ -272,17 +303,16 @@ int top_main_loop(struct osnoise_tool *tool) /* stop tracing requested, do not perform actions */ return 0; =20 - actions_perform(¶ms->threshold_actions); + enum restart_result result; + + result =3D common_restart(tool, params); =20 - if (!params->threshold_actions.continue_flag) - /* continue flag not set, break */ + if (result =3D=3D RESTART_STOP) 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); + if (result =3D=3D RESTART_ERROR) + return -1; + trace_instance_start(trace); } =20 @@ -323,18 +353,17 @@ int hist_main_loop(struct osnoise_tool *tool) /* stop tracing requested, do not perform actions */ break; =20 - actions_perform(¶ms->threshold_actions); + enum restart_result result; =20 - if (!params->threshold_actions.continue_flag) - /* continue flag not set, break */ - break; + result =3D common_restart(tool, params); + + if (result =3D=3D RESTART_STOP) + 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); + if (result =3D=3D RESTART_ERROR) + return -1; + + 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 9ec2b7632c376..f2c9e21c03651 100644 --- a/tools/tracing/rtla/src/common.h +++ b/tools/tracing/rtla/src/common.h @@ -143,6 +143,15 @@ struct tool_ops { void (*free)(struct osnoise_tool *tool); }; =20 +enum restart_result { + RESTART_OK, + RESTART_STOP, + RESTART_ERROR =3D -1, +}; + +enum restart_result +common_restart(const struct osnoise_tool *tool, struct common_params *para= ms); + 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 226167c88c8d6..27fc98270da59 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; @@ -1100,18 +1101,19 @@ 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); + enum restart_result result; =20 - if (!params->common.threshold_actions.continue_flag) - /* continue flag not set, break */ + result =3D common_restart(tool, ¶ms->common); + if (result =3D=3D RESTART_STOP) 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 (result =3D=3D RESTART_ERROR) + return -1; + + 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 31e1514a2528d..f7e85dc918ef3 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -18,6 +18,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; @@ -869,18 +870,19 @@ timerlat_top_bpf_main_loop(struct osnoise_tool *tool) =20 if (wait_retval !=3D 0) { /* Stopping requested by tracer */ - actions_perform(¶ms->common.threshold_actions); + enum restart_result result; =20 - if (!params->common.threshold_actions.continue_flag) - /* continue flag not set, break */ + result =3D common_restart(tool, ¶ms->common); + if (result =3D=3D RESTART_STOP) 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 (result =3D=3D RESTART_ERROR) + return -1; + + if (timerlat_bpf_restart_tracing()) { + err_msg("Error restarting BPF trace\n"); + return -1; + } } =20 /* is there still any user-threads ? */ --=20 2.52.0 From nobody Sat Feb 7 15:40:24 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 E1AB733FE09 for ; Tue, 6 Jan 2026 13:42:51 +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=1767706973; cv=none; b=tkc5lf0pvW07qCwLrJH6JsEG5umb6CvYMEwweXAfUmQ0DxvhqZTjIEhIDZa4yIev25mxYUzYkdfAApHbpiAVQ1m0jsGv/CqWmF/S0VOPU5caPQqsN8s/zmp1yCVnA5X9tdNfb4olZzCqoFGsa95odwB5thTCGQuiFiFs6D7/Hus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767706973; c=relaxed/simple; bh=GdNVqyvUvcHuf/HcL1GjWVzimf5pBVb6UaPWIEtgTpw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kG+lhPkLuJx7ZrLSpf9hc0Imm7X/X+zfd5E1SX+zIBs7LxCcPfgAYOr1hyGEv4wZy62W0COjOLubPgzhJhHmIdNZj/gMFJc8/OZvSmJ/muwPkxtpMWqsugnHWC2pBxyWaj2wmbeW8dyyco+6x5IuVrmFD7Xt3HW5bhkhpPgLxkU= 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=GPH6kh6q; 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="GPH6kh6q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767706970; 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=BMb5EeLAGOztdhNhPXPhwLEVSwERWiY6H9aj3v+zftA=; b=GPH6kh6q+52Q+i3NJ7sE+lpWasJp8JkNtfyYnWRKEe4azv9NVZd3wEGjOm2Aa5/PPs32zV dvcp6yXvMk5aOqo9jJT8quMwSpf+Unir0mZbxTNpDRWhtPinVmL4gyTVjswgJdUcJaczGR xIfThHrS1xCXGAfVvcZA3p4As6oGIrw= 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-591-qdtbuPjjOZOqkzBt6YrKeQ-1; Tue, 06 Jan 2026 08:42:49 -0500 X-MC-Unique: qdtbuPjjOZOqkzBt6YrKeQ-1 X-Mimecast-MFC-AGG-ID: qdtbuPjjOZOqkzBt6YrKeQ_1767706968 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 4C616195609E; Tue, 6 Jan 2026 13:42:48 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6B3AB1800367; Tue, 6 Jan 2026 13:42:44 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Ivan Pravdin , Crystal Wood , Costa Shulyupin , John Kacur , Tiezhu Yang , 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 v2 08/18] rtla: Use standard exit codes for result enum Date: Tue, 6 Jan 2026 08:49:44 -0300 Message-ID: <20260106133655.249887-9-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-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 result enum defines custom values for PASSED, ERROR, and FAILED. These values correspond to standard exit codes EXIT_SUCCESS and EXIT_FAILURE. Update the enum to use the standard macros EXIT_SUCCESS and EXIT_FAILURE to improve readability and adherence to standard C practices. The FAILED value is implicitly assigned EXIT_FAILURE + 1, so there is no need to assign an explicit value. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/utils.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h index 7fa3ac5e0bfb6..5286a4c7165d3 100644 --- a/tools/tracing/rtla/src/utils.h +++ b/tools/tracing/rtla/src/utils.h @@ -4,6 +4,7 @@ #include #include #include +#include =20 /* * '18446744073709551615\0' @@ -102,7 +103,7 @@ __attribute__((__warn_unused_result__)) int strtoi(cons= t char *s, int *res); #define ns_to_per(total, part) ((part * 100) / (double)total) =20 enum result { - PASSED =3D 0, /* same as EXIT_SUCCESS */ - ERROR =3D 1, /* same as EXIT_FAILURE, an error in arguments */ - FAILED =3D 2, /* test hit the stop tracing condition */ + PASSED =3D EXIT_SUCCESS, + ERROR =3D EXIT_FAILURE, + FAILED, /* test hit the stop tracing condition */ }; --=20 2.52.0 From nobody Sat Feb 7 15:40:24 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 27EA5341ADD for ; Tue, 6 Jan 2026 13:43: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=1767707010; cv=none; b=SGbdE3n5iYOGY8AuALBT9rK6PRasZ7kDFBwaR+U4G63RUaQvs8hqbR5ZstACn8qTNw8pQdqKGNZoo4ntlLM7Jn/uTaFB1UCvwspxP0CaeaVEYY0al7mXytDElTwkAtdh4syZBJVihwr1L4b1GQFKmp3znqliyaHT/gDfcEwFAxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767707010; c=relaxed/simple; bh=32UhQmIuVg7RFlQt1JWZY3VmEmTIMShoXJksn4Mgi48=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sc61nO9Jcc7K9b63pkm/YIQUhpo+mliOMbCWrE0YNf+szUk8PZg/+/q1FxzcSjCnmfel+SANi8P8wY2KdTkqXeWdCHAC61MLVS776Et9bsUDX9qvHHuZJpUERtgDnwMjmRm5S1K5RUSz93P29EXHyeP4Fqm9AlGPTCGLcBbcTSM= 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=ZEdB7EhL; 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="ZEdB7EhL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767707008; 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=cLArHPeP1sDYwq27BLpCMkE5lpVuL1KHGveKa/KTPcs=; b=ZEdB7EhL2WmEfjSuspr7lIWXdoAysStT3HMFQnfAl3WRk71aQs2V8if5RJyOBpwhfY8LXg /kSLNgl83xm4kcCpILPqKM90Gdeo7846/I5MOVXrZHtnZKkKWBgwQ/v5MYA/webGCYE3Eq xNhnPBS8AK3a1EH1PWC/YOGBE9KWVeY= 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-696-UZ2tysFYMMG8f5pf0ytBog-1; Tue, 06 Jan 2026 08:43:25 -0500 X-MC-Unique: UZ2tysFYMMG8f5pf0ytBog-1 X-Mimecast-MFC-AGG-ID: UZ2tysFYMMG8f5pf0ytBog_1767707004 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 D678019560A1; Tue, 6 Jan 2026 13:43:23 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 427151800666; Tue, 6 Jan 2026 13:43:19 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Tiezhu Yang , 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 v2 09/18] rtla: Remove redundant memset after calloc Date: Tue, 6 Jan 2026 08:49:45 -0300 Message-ID: <20260106133655.249887-10-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-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 struct is allocated using calloc, which already returns zeroed memory. The subsequent memset call to zero the 'present' member is therefore redundant. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/actions.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/tracing/rtla/src/actions.c b/tools/tracing/rtla/src/acti= ons.c index b50bf9f9adf28..00bbc94dec1bd 100644 --- a/tools/tracing/rtla/src/actions.c +++ b/tools/tracing/rtla/src/actions.c @@ -19,8 +19,6 @@ actions_init(struct actions *self) self->len =3D 0; self->continue_flag =3D false; =20 - memset(&self->present, 0, sizeof(self->present)); - /* This has to be set by the user */ self->trace_output_inst =3D NULL; } --=20 2.52.0 From nobody Sat Feb 7 15:40:24 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 51C68343D75 for ; Tue, 6 Jan 2026 13:44:05 +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=1767707046; cv=none; b=qDJ8jLAjkxRZ9H0qbsCTEURdSYfz34o/cBSzQIw07imbt+ijSYebkzeyZV+Uow0hw/fO2awDE/nqJjb8rMupHXv3cBqYCfCdk0jfCYesrjJ+3QiK3ePqnbXM9J7mq3iIvMPTsOmgOqykKnilFee2d3q/fKM3I58TUNtArprQb3g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767707046; c=relaxed/simple; bh=2U4r2XRmpmt1WppRdog4l707g0lRT881+Ovs94/4edM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mnclF9fVq++SPqBhQw0TxY04bSWOXePHfPfi/VKk6nTH3a8jTJAfxJZ+dlcr1QxAqbBZiv+tq9YvjV1ejvMuAyf4H7UIpPtphlMm9Ti6Ta2XqW9mc8+sWl5WcdWcz5+lrw7AZBiQOkq8iKo+y68L49Ut7Z7JQ3i9YqEamus0M0k= 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=K6AeM9g2; 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="K6AeM9g2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767707044; 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=O/mLUsFgLgHuGHJkWjp3gM3O8QtESBk5+FkGgdYbFbM=; b=K6AeM9g2LQQiIFPEvETBXOApEk4DXtu+ASOy+++vGkHi8npTA84rNArpWdc6ZzSHy5cN0V pb+e1HQKEQasU1qCU2cXpyCn00S/HOopOiachjuKb5rDVH+zKlJfMo1WnxEDgYfJ+iC2c6 9ArKZoGa/1M7ZuveFbLx/fj6sj5kH/A= 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-111-PRmrgqd9MwKXz6FBrBlZew-1; Tue, 06 Jan 2026 08:44:01 -0500 X-MC-Unique: PRmrgqd9MwKXz6FBrBlZew-1 X-Mimecast-MFC-AGG-ID: PRmrgqd9MwKXz6FBrBlZew_1767707040 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 1594D1956058; Tue, 6 Jan 2026 13:44:00 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7091B1800367; Tue, 6 Jan 2026 13:43:56 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Ivan Pravdin , Crystal Wood , Costa Shulyupin , John Kacur , Tiezhu Yang , 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 v2 10/18] rtla: Replace magic number with MAX_PATH Date: Tue, 6 Jan 2026 08:49:46 -0300 Message-ID: <20260106133655.249887-11-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-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 f2ec2da7b6d3a..68927d799dde5 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 45328c5121f79..0a81a2e4667ef 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -314,7 +314,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) @@ -326,7 +326,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); @@ -345,7 +345,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) @@ -360,7 +360,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 @@ -392,7 +392,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) @@ -406,7 +406,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); @@ -445,7 +445,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) @@ -457,7 +457,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); @@ -480,7 +480,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) @@ -492,7 +492,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 Sat Feb 7 15:40:24 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 EE3783446B0 for ; Tue, 6 Jan 2026 13:44:41 +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=1767707083; cv=none; b=lKjGgDT4oICQdvf5lyD6OZn+fRmwn/fkgHFTdd0kUotrdFTeEnYTcQLJyS2hrm4+x8sCx9D4xqiGCvyNAcr8SgWDxCCe/Iu+L6vXs5nlkiekgYQnLEdf/tv9J2KN56a7fdnX1IKGZshnt4S7nbEYAWFTLiWIUfB5v8oKV+7lPwU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767707083; c=relaxed/simple; bh=WXnCGYc+gwvQe0yvnlFsYFUDt9lQeVOnfPCOO+Gr3hY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t/sH62tRtfxEw8S6Rg49MoB+vGkLvn8OtN9zGGsRAyYfZaXBuaydKoShibmtVxy9KlwqP7s0XjipzRjVD/HudjNU2uc4417bNk8De5SCLUtu/ERUW45OHxOBuK+2vNa/cpUMwFtlFF+19OgYp/mzCxeX6FhNca4GuxSdaV/beds= 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=JkGl6N5/; 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="JkGl6N5/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767707080; 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=qlj+8dE+8UhnMtv9WnHlh2eX/Ry+9eXzJV0pLxebN3M=; b=JkGl6N5/kurjQD3qQCKs77vDOn3xhPaX6tcjwcVudNo7PLj5Q4kfiGht4f72zbbZ5HZctk CDAvWqAsWFRFlIudhPv8kp+JQzYBDQbXkHSh4j+RvxiUgQ9hmtobtyRUSy2CXOHeGekRrX 83fC46N3Q24kvExlM2tM5fZY0u79SRY= 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-615-GOLBlbopOFyqibhnNvNWdQ-1; Tue, 06 Jan 2026 08:44:39 -0500 X-MC-Unique: GOLBlbopOFyqibhnNvNWdQ-1 X-Mimecast-MFC-AGG-ID: GOLBlbopOFyqibhnNvNWdQ_1767707078 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 624B818011FB; Tue, 6 Jan 2026 13:44:37 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DB4701800663; Tue, 6 Jan 2026 13:44:32 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Tiezhu Yang , 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 v2 11/18] rtla: Remove unused headers Date: Tue, 6 Jan 2026 08:49:47 -0300 Message-ID: <20260106133655.249887-12-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-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" Remove unused includes for and to clean up the code and reduce unnecessary dependencies. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/osnoise_hist.c | 1 - tools/tracing/rtla/src/timerlat.c | 1 - tools/tracing/rtla/src/timerlat_top.c | 1 - tools/tracing/rtla/src/trace.c | 1 - 4 files changed, 4 deletions(-) diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src= /osnoise_hist.c index af7d8621dd9d7..c8e681f732315 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include =20 diff --git a/tools/tracing/rtla/src/timerlat.c b/tools/tracing/rtla/src/tim= erlat.c index ac2ec89d3b6ba..b3d63506c4a62 100644 --- a/tools/tracing/rtla/src/timerlat.c +++ b/tools/tracing/rtla/src/timerlat.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src= /timerlat_top.c index f7e85dc918ef3..79ee66743bf1d 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include =20 diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index 0a81a2e4667ef..092fcab77dc4c 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -2,7 +2,6 @@ #define _GNU_SOURCE #include #include -#include #include #include #include --=20 2.52.0 From nobody Sat Feb 7 15:40:24 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 EE0761D90DD for ; Tue, 6 Jan 2026 13:45:17 +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=1767707119; cv=none; b=qZrv+7VoO/IQ7jACeo9wZo3dOiY0HmwyGg7P4QN9MH6XjzjcHIyBB3bR0N4dYR/cUIxSm8/00mJelxVH2CD2H9Q+ZddE2P9qyZM8bMy/cNF2Pqf8X3ePaJwSWTPAdJON2Q2hDDNI7Duokoj6EfGvdjl/TvVDzZSvLB9loHqwbug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767707119; c=relaxed/simple; bh=s2TZMSh4wNlugwQUb/grB4j80JCmYqggHPpNTuBQUks=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WXsqOUdwS0D/uL7U2/0LwqatIEeq35prOHOCMkUAp6nZB8LS+/Y/D1/fxPg/4rY/XnDFHJXnl9sl3VB2W7AfyyyOkfYwNUJkKwpv8eFSUoiZio6vhduI4Xio1FKLxCRYjxcyaL0LWQg/OLHsI3WvXSGrom4xT0gRcl9CJ75VcGc= 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=UDbPH3RF; 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="UDbPH3RF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767707117; 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=5BanPd8d6y/CBsOyxFKDYt9T0QkVzk6reOpvMykHk2A=; b=UDbPH3RFw9Xejbp4Qzlv5FI1L3mVfjBGEAab0EATf2qkij8hNBF/yWDoPC5an88T++RoTY SiQIR748D/uv+XsWy/54Vl3hBZE1IldlpEfl3JfZrIq3gdHyIY5Po8NSrn7PAWUJVvl/Cg lhqe7gyjzrvQDbu+ReKfL5+6cr/HTIM= 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-494-2v_Wx45JO3eXZdm8xw726A-1; Tue, 06 Jan 2026 08:45:14 -0500 X-MC-Unique: 2v_Wx45JO3eXZdm8xw726A-1 X-Mimecast-MFC-AGG-ID: 2v_Wx45JO3eXZdm8xw726A_1767707112 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 C94D9195DE56; Tue, 6 Jan 2026 13:45:12 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0E27D1800367; Tue, 6 Jan 2026 13:45:08 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Ivan Pravdin , Crystal Wood , Costa Shulyupin , John Kacur , Tiezhu Yang , 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 v2 12/18] rtla: Fix NULL pointer dereference in actions_parse Date: Tue, 6 Jan 2026 08:49:48 -0300 Message-ID: <20260106133655.249887-13-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-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 strtok() to tokenize the trigger string, but does not check if the returned token is NULL before passing it to strcmp(). If the trigger parameter is an empty string or contains only delimiter characters, strtok() returns NULL, causing strcmp() to dereference a NULL pointer and crash the program. This issue can be triggered by malformed user input or edge cases in trigger string parsing. Add a NULL check immediately after the strtok() call to validate that a token was successfully extracted before using it. If no token is found, the function now returns -1 to indicate a parsing error. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/actions.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/tracing/rtla/src/actions.c b/tools/tracing/rtla/src/acti= ons.c index 00bbc94dec1bd..b0d68b5de08db 100644 --- a/tools/tracing/rtla/src/actions.c +++ b/tools/tracing/rtla/src/actions.c @@ -153,6 +153,8 @@ actions_parse(struct actions *self, const char *trigger= , const char *tracefn) =20 strcpy(trigger_c, trigger); token =3D strtok(trigger_c, ","); + if (!token) + return -1; =20 if (strcmp(token, "trace") =3D=3D 0) type =3D ACTION_TRACE_OUTPUT; --=20 2.52.0 From nobody Sat Feb 7 15:40:24 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 CC648255F57 for ; Tue, 6 Jan 2026 13:45:57 +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=1767707159; cv=none; b=Iv7JX27r1fj4l/+YbgXeMGulKZFmyQ3D9ugh8ZaIDDEKVrf7yZqRrYuK2YV1TKu7BvyG1Ox07p5sZ/Ri4/iosjeqEGEmcD7gBaHGSMAnQ3co7JkMG0AON7Dl0qccnWPY6HVPOBnoriR4EyNl5NihlvegBQb3JSjcTzd4BJbFveA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767707159; c=relaxed/simple; bh=8gnOH+Eo89f+VcICPmqndkLq6lSKcePozRGfu/ZjDQc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QmxRRpgq+0T96Vje89F82Gu2L7NK7Ro1ujnlJALxgj789zjkQkKBNKnvEoaYvwIEeUD8xmSFHG8NJTWrH9uHK6iaUrO/Zcvnh2HDwwRjK7eAW7OfQ0wNGFcqQSa/YSSlWbw9GfkQaLLShi/FBa+OsL7tMr2eDFHnhRzE0esdtEA= 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=Y/fm/vM2; 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="Y/fm/vM2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767707156; 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=wa3BDtkXy0XBMcTKcISXu7dZ5d/WNRYV5EhDhDMbaJA=; b=Y/fm/vM269g34ZJAouiuzxfKbG8DyAfz9SEw2nBkygOovAmCvkktjDKEhkmC0ZuAwWYEgk y2sh6eUFJTOi4A8UwSGi5dBvSmk/iccQw9a+c63GhfW8/bI6FMZtwH6W8hpqimzmgXxtan 7ccbatHAmGt0Ra6aBg2+JILTIh6cT0g= 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-224-3okzsnYrPyC0qyTG8nV0Gw-1; Tue, 06 Jan 2026 08:45:51 -0500 X-MC-Unique: 3okzsnYrPyC0qyTG8nV0Gw-1 X-Mimecast-MFC-AGG-ID: 3okzsnYrPyC0qyTG8nV0Gw_1767707150 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 36C001956096; Tue, 6 Jan 2026 13:45:50 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7E414180035A; Tue, 6 Jan 2026 13:45:45 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Tiezhu Yang , 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 v2 13/18] rtla: Fix buffer size for strncpy in timerlat_aa Date: Tue, 6 Jan 2026 08:49:49 -0300 Message-ID: <20260106133655.249887-14-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-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 run_thread_comm and current_comm character arrays in struct timerlat_aa_data are defined with size MAX_COMM (24 bytes), but strncpy() is called with MAX_COMM as the size parameter. If the source string is exactly MAX_COMM bytes or longer, strncpy() will copy exactly MAX_COMM bytes without null termination, potentially causing buffer overruns when these strings are later used. Increase the buffer sizes to MAX_COMM+1 to ensure there is always room for the null terminator. This guarantees that even when strncpy() copies the maximum number of characters, the buffer remains properly null-terminated and safe to use in subsequent string operations. 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 31e66ea2b144c..d310fe65abace 100644 --- a/tools/tracing/rtla/src/timerlat_aa.c +++ b/tools/tracing/rtla/src/timerlat_aa.c @@ -47,7 +47,7 @@ struct timerlat_aa_data { * note: "unsigned long long" because they are fetch using tep_get_field_= val(); */ unsigned long long run_thread_pid; - char run_thread_comm[MAX_COMM]; + char run_thread_comm[MAX_COMM+1]; unsigned long long thread_blocking_duration; unsigned long long max_exit_idle_latency; =20 @@ -88,7 +88,7 @@ struct timerlat_aa_data { /* * Current thread. */ - char current_comm[MAX_COMM]; + char current_comm[MAX_COMM+1]; unsigned long long current_pid; =20 /* --=20 2.52.0 From nobody Sat Feb 7 15:40:24 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 94A3B31352F for ; Tue, 6 Jan 2026 13:46:31 +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=1767707193; cv=none; b=J/BCyq1OBDoMBKv7mcOOeo+Erandibuc6WFHmuceVXFSoqmDtBilLY0ghT/MDpyH9e7b3KYvztWzJgnDL7aEYgRF/q0GJtle2+dhe+a2E5JgLHUXgZ5J1/fdkMOCARdORgJysYwhQSGN4n1Jtdlyc6BXlmGFJQaU/fMOfKglia8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767707193; c=relaxed/simple; bh=XeCKCQslN/bQhvxqvkYZrAg7y9wmgEVBBNPHBVI3M0c=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z61vLNRrWojyjXUy3uxyzw03dys/7zZFuhf4B1c+FIjIqCBOQqbdXzBo+X+SQtJJ4YreaTOWCbZ7FD4pnhhTDKaICJVCDB/cbpagOoP2JarIezUtaN+StYoRCv70NQ91mPsRWrobKIAYbiyn9XfIuYa5P49tjwcASnirq8ghwzw= 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=PR2yuQ2H; 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="PR2yuQ2H" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767707190; 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=jeWOzu4MzcAw4CDL5ZObANt/PvdTfv+Z8kd/Q22vWhY=; b=PR2yuQ2HRWo5FDQVtVOk1a4ZuUhIPhPcuFkbDupyqWtga7N7fzZnqYB8yYreWoruatLO1n QFIA2oJiAcv7iPRMcAcYJYzwOqAj9TNq5cbW53dHTyVFhrCyF3d48nPC9AqVD0fVIjIVwk plt2h/sSLbiJudjvJaBcVl8g/W3NAVk= 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-632-vsjNaMk4PzqAZ2E8dMoj0A-1; Tue, 06 Jan 2026 08:46:27 -0500 X-MC-Unique: vsjNaMk4PzqAZ2E8dMoj0A-1 X-Mimecast-MFC-AGG-ID: vsjNaMk4PzqAZ2E8dMoj0A_1767707186 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 5845D1801210; Tue, 6 Jan 2026 13:46:26 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6E2A0180035A; Tue, 6 Jan 2026 13:46:22 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Tiezhu Yang , 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 v2 14/18] rtla: Add generated output files to gitignore Date: Tue, 6 Jan 2026 08:49:50 -0300 Message-ID: <20260106133655.249887-15-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-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 rtla tool generates various output files during testing and execution, including custom trace outputs and histogram data. These files are artifacts of running the tool with different options and should not be tracked in version control. Add gitignore entries for custom_filename.txt, osnoise_irq_noise_hist.txt, osnoise_trace.txt, and timerlat_trace.txt to prevent accidentally committing these generated files. This aligns with the existing pattern of ignoring build artifacts and generated headers like *.skel.h. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/.gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/tracing/rtla/.gitignore b/tools/tracing/rtla/.gitignore index 1a394ad26cc1e..4d39d64ac08c0 100644 --- a/tools/tracing/rtla/.gitignore +++ b/tools/tracing/rtla/.gitignore @@ -5,3 +5,7 @@ fixdep feature FEATURE-DUMP *.skel.h +custom_filename.txt +osnoise_irq_noise_hist.txt +osnoise_trace.txt +timerlat_trace.txt --=20 2.52.0 From nobody Sat Feb 7 15:40:24 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 4239E21CC51 for ; Tue, 6 Jan 2026 13:47:11 +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=1767707232; cv=none; b=WNtX0x0dK7CONmmGhRm965jK3bLf8+jzQY7X5YVVuMTDv8p0P/Cz/MK6K8EahEBO/9nLRxqGHUjwqYIW5RoYG2eSHy5Qz4ADHbhZzwyw/pZ+NVEEVMsvfHAKAVSacxE49C5z/Rx3F/q7SuSNx0DPqY/jT9iqJGb/6XlSn31uZ/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767707232; c=relaxed/simple; bh=kLhmG8r8/G/ZBzcMsD21dGTit7z/QexGf+BuN2OdGGU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qaWVLNbx0A6424irFqIZbWttU8KrsOk73NZtlzbOOY/5GD3j5G9R6X19J2C0DpX09zpAiRsk7gUnuJfAqiVwKxbUXZpBeik0cHrtp94JEODekpO9UuIhTLWkvsn28Ij32diJI5+jsue1pl1IbHIP0eglQyjHZV1hWYZe/fqP8BQ= 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=MHApe9ZD; 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="MHApe9ZD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767707230; 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=K2MacZa0tkiAD+rR0g1h1MHJtgQHxTFEHFa+WubSNqk=; b=MHApe9ZDjr2DPHn51HOnvOcOmk2YtgeymV0QMCrN2xA0/HU8E2fjyAg+zCvxxGdLyibcDg m+HSlL7RATcTMBHUW2V3Uq9H4thPA80yK5m6Erz6xwgJhBLNk7gwW8mVqeGfOccGiBqJw+ ator3pgG+2ZWtpA5vkivgYID6XKyj9w= 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-404-U3IkJEZZNYiniFGAwG_s1A-1; Tue, 06 Jan 2026 08:47:06 -0500 X-MC-Unique: U3IkJEZZNYiniFGAwG_s1A-1 X-Mimecast-MFC-AGG-ID: U3IkJEZZNYiniFGAwG_s1A_1767707225 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 117521956068; Tue, 6 Jan 2026 13:47:05 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8A7DD1800367; Tue, 6 Jan 2026 13:47:01 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Tiezhu Yang , 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 v2 15/18] rtla: Make stop_tracing variable volatile Date: Tue, 6 Jan 2026 08:49:51 -0300 Message-ID: <20260106133655.249887-16-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-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 stop_tracing global variable is accessed from both the signal handler context and the main program flow without synchronization. This creates a potential race condition where compiler optimizations could cache the variable value in registers, preventing the signal handler's updates from being visible to other parts of the program. Add the volatile qualifier to stop_tracing in both common.c and common.h to ensure all accesses to this variable bypass compiler optimizations and read directly from memory. This guarantees that when the signal handler sets stop_tracing, the change is immediately visible to the main program loop, preventing potential hangs or delayed shutdown when termination signals are received. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/common.c | 2 +- tools/tracing/rtla/src/common.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/tracing/rtla/src/common.c b/tools/tracing/rtla/src/commo= n.c index d608ffe12e7b0..1e6542a1e9630 100644 --- a/tools/tracing/rtla/src/common.c +++ b/tools/tracing/rtla/src/common.c @@ -8,7 +8,7 @@ #include "common.h" =20 struct trace_instance *trace_inst; -int stop_tracing; +volatile int stop_tracing; =20 static void stop_trace(int sig) { diff --git a/tools/tracing/rtla/src/common.h b/tools/tracing/rtla/src/commo= n.h index f2c9e21c03651..283641f3e7c9b 100644 --- a/tools/tracing/rtla/src/common.h +++ b/tools/tracing/rtla/src/common.h @@ -54,7 +54,7 @@ struct osnoise_context { }; =20 extern struct trace_instance *trace_inst; -extern int stop_tracing; +extern volatile int stop_tracing; =20 struct hist_params { char no_irq; --=20 2.52.0 From nobody Sat Feb 7 15:40:24 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 6F300333431 for ; Tue, 6 Jan 2026 13:47:48 +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=1767707270; cv=none; b=HPISXATqI26IIrjHAq2kHjjOJPis7hTKQEF9MJpR8udqM9kpxCv08S8h/FO1Myd2wYRjjGerboMoLTOfjZMM50CV/2PPI9InK1GFviyDcd+6VOBkF+g61rMEd2qxLyZ4IvGz1RresoupJz9jG3b6IVl+FJX0jWDkTziPPGBHksc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767707270; c=relaxed/simple; bh=X0mhfphzyzLPUFjrtvGZjqO0h8g5+dpKSw/dmcSM54k=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wa37nZ/3fjDtbW5OTX6hgXffdRrsA9pnY2lIRRTjCtbOSIBweodS221f7+MlIYOMWgvpMwoiDFjFYzBnTdPEq0SvYWN1sXapGtWC5pjwueFYVHTF/fMRIDri61KKjWmcKaqVg48/slSEXH6FIdi+E9oPRFwxIkN9358E3pezH64= 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=KPPaAPma; 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="KPPaAPma" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767707267; 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=D2PckU0JC5Ea9d4GrF2OBPBlpYWIkdOC3Apu6J3z5gQ=; b=KPPaAPma2cqjIyvdqjKi1abyWQ/ZuYNHapwSOBjnBbJkqXapGx/Qq4r4L5s6DPYKskyfT3 uakOlQOnEl3MA6ivus+fn9G/aEhcqeTeAdw5/mr9woSdlOKpN5FJQhG1A+W0m7vKf0oS9c hoQhrnMSdCoCTmxXRnW9m39BZizjcIM= 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-354-oRXwTd-_OTqtkSl4qfStLA-1; Tue, 06 Jan 2026 08:47:44 -0500 X-MC-Unique: oRXwTd-_OTqtkSl4qfStLA-1 X-Mimecast-MFC-AGG-ID: oRXwTd-_OTqtkSl4qfStLA_1767707263 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 5D0191956068; Tue, 6 Jan 2026 13:47:43 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 42DE21800667; Tue, 6 Jan 2026 13:47:39 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Ivan Pravdin , Crystal Wood , Costa Shulyupin , John Kacur , Tiezhu Yang , 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 v2 16/18] rtla: Ensure null termination after read operations in utils.c Date: Tue, 6 Jan 2026 08:49:52 -0300 Message-ID: <20260106133655.249887-17-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-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 explicit null termination and buffer initialization for read() operations in procfs_is_workload_pid() and get_self_cgroup() functions. The read() system call does not null-terminate the data it reads, and when the buffer is filled to capacity, subsequent string operations will read past the buffer boundary searching for a null terminator. In procfs_is_workload_pid(), explicitly set buffer[MAX_PATH-1] to '\0' to ensure the buffer is always null-terminated before passing it to strncmp(). In get_self_cgroup(), use memset() to zero the path buffer before reading, which ensures null termination when retval is less than MAX_PATH. Additionally, set path[MAX_PATH-1] to '\0' after the read to handle the case where the buffer is filled completely. These defensive buffer handling practices prevent potential buffer overruns and align with the ongoing buffer safety improvements across the rtla codebase. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/utils.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index e0f31e5cae844..508b8891acd86 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -317,6 +317,7 @@ static int procfs_is_workload_pid(const char *comm_pref= ix, struct dirent *proc_e if (retval <=3D 0) return 0; =20 + buffer[MAX_PATH-1] =3D '\0'; retval =3D strncmp(comm_prefix, buffer, strlen(comm_prefix)); if (retval) return 0; @@ -750,6 +751,7 @@ static int get_self_cgroup(char *self_cg, int sizeof_se= lf_cg) if (fd < 0) return 0; =20 + memset(path, 0, sizeof(path)); retval =3D read(fd, path, MAX_PATH); =20 close(fd); @@ -757,6 +759,7 @@ static int get_self_cgroup(char *self_cg, int sizeof_se= lf_cg) if (retval <=3D 0) return 0; =20 + path[MAX_PATH-1] =3D '\0'; start =3D path; =20 start =3D strstr(start, ":"); --=20 2.52.0 From nobody Sat Feb 7 15:40:24 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 9867B33D6CA for ; Tue, 6 Jan 2026 13:48: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=1767707307; cv=none; b=tqUy+uyXrjC1JXuo0RYyRO+P+UblRykj5jIKQgvvYeCSX7f4nBowZG9hiPofQJHjbpSLdrL3oRYScp52j3RvrO8SzwRc47tRa8M1tL1hEmsciZ3Gx9n2+2cLias1LNfAvC3gyOJpV3C4sMcF7RsI/JROi6gHOYRuyQWNWE5A3Ek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767707307; c=relaxed/simple; bh=SQR+A6Rt1nFESNQ3gMr0olAyt1eeqZOPR2xNeMz1fRI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kJdCCl38eZ4p7lcuW4DHETtJ5CWLr3df38mFsiBI66JWXUv78TqIZUCfO2wXUL0kfrRTeHcXecspMYkjbCoUA2ecX4xL7RG1ctEv8cWlVS9N6H35quXDmB8yOonwqQhXr3DFnalZ67A1N7uIY04hF3Fk8c175nKpo6lux7KPIbA= 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=Zgo5J61+; 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="Zgo5J61+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767707304; 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=FNP90wk4H8rdVkur8zqT0itxOHKAzLeaufg8KGIEo/w=; b=Zgo5J61+BPnoY1H7d88WeysuWMTX93EIX+GtTZ5xFXbK9ofeGofZN59u5My277Etiixa1X GTXEi3CJiDMI8B0xu7j3x+T1P8HhJ3wNhDhza3RIVZRtHgSJaU/byMVZRfaacZM2XXJiwH DkD6Q+mAYw7z2N7dStAUUOhwCMMe93I= 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-695-fylWa2GDO0moLpfc42uI_g-1; Tue, 06 Jan 2026 08:48:23 -0500 X-MC-Unique: fylWa2GDO0moLpfc42uI_g-1 X-Mimecast-MFC-AGG-ID: fylWa2GDO0moLpfc42uI_g_1767707302 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 3ABF21956063; Tue, 6 Jan 2026 13:48:22 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 64C941800576; Tue, 6 Jan 2026 13:48: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 , 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 v2 17/18] rtla: Fix parse_cpu_set() return value documentation Date: Tue, 6 Jan 2026 08:49:53 -0300 Message-ID: <20260106133655.249887-18-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-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" Correct the return value documentation for parse_cpu_set() function in utils.c. The comment incorrectly stated that the function returns 1 on success and 0 on failure, but the actual implementation returns 0 on success and 1 on failure, following the common error-on-nonzero convention used throughout the codebase. This documentation fix ensures that developers reading the code understand the correct return value semantics and prevents potential misuse of the function's return value in conditional checks. 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 508b8891acd86..4093030e446ab 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -113,7 +113,7 @@ void get_duration(time_t start_time, char *output, int = output_size) * Receives a cpu list, like 1-3,5 (cpus 1, 2, 3, 5), and then set * filling cpu_set_t argument. * - * Returns 1 on success, 0 otherwise. + * Returns 0 on success, 1 otherwise. */ int parse_cpu_set(char *cpu_list, cpu_set_t *set) { --=20 2.52.0 From nobody Sat Feb 7 15:40:24 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 F271A33DEE3 for ; Tue, 6 Jan 2026 13:49: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=1767707348; cv=none; b=m5rbaemYt2QSFWJ6LRne5utDaaPnS7gEQgX9BV3BDhysaXmYOistv8vc1gkjeellEbwGEV8zpJNzpJl7kRUFqdNDfICKiZ53tBUxk0tr2I3YA4owECo5wwG5jKfmtp1O7TCfVwamU8uS3EXMirHTU3apAdyJ3eK7qkXT6DTVGJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767707348; c=relaxed/simple; bh=khr4HXouOlKmupfOwr1RNYMaHRidP4N+XAnyKcMrmB4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wgh5A2LvsXqxZ7fd91pkFJv9ZXyvpMH3shearQPwQPkIAMv9GT0/PHOsNkc7HDzVba/GAxoQT9AZn9+ZkipzCcPTn4EQUmXAiOqEmXn52uhuEbODNad0e61RYPdL8pzI+BU9PPONJYv42PNL/06VWqvlxro/boIdm5L2IbMyFvI= 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=XZumnRRX; 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="XZumnRRX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767707346; 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=Km5rA7vjuSWs0NIc9MqaKbnKolitv5jNiI4g81bW+B4=; b=XZumnRRX6/8C886DOhnY1olrsjgvOSPc5Inf4yHRoemtxk9ycseAXRtwsCsNY1tu69dni8 pFQcDA0MFzY/2y1nDl5qbvS9hG2Z/eUMRIOYAy8vvYETDcnR6Qkz+v2Afz7EdBDEONn3jA EWM3j7lWExfSynUYTCIyM6jG0TTn5GQ= 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-396-ES6CsnRGPX2AIcy5TtcRvw-1; Tue, 06 Jan 2026 08:49:03 -0500 X-MC-Unique: ES6CsnRGPX2AIcy5TtcRvw-1 X-Mimecast-MFC-AGG-ID: ES6CsnRGPX2AIcy5TtcRvw_1767707342 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 083B81801207; Tue, 6 Jan 2026 13:49:02 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9A3181800576; Tue, 6 Jan 2026 13:48:57 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Tiezhu Yang , 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 v2 18/18] rtla: Simplify code by caching string lengths Date: Tue, 6 Jan 2026 08:49:54 -0300 Message-ID: <20260106133655.249887-19-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-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 092fcab77dc4c..223ab97e50aed 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 4093030e446ab..aee7f02b1e9b4 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -870,6 +870,7 @@ int set_comm_cgroup(const char *comm_prefix, const char= *cgroup) DIR *procfs; int retval; int cg_fd; + size_t cg_path_len; =20 if (strlen(comm_prefix) >=3D MAX_PATH) { err_msg("Command prefix is too long: %d < strlen(%s)\n", @@ -883,16 +884,18 @@ int set_comm_cgroup(const char *comm_prefix, const ch= ar *cgroup) return 0; } =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 0; } } 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