From nobody Tue Dec 2 02:52:39 2025 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 0F27C339B43 for ; Mon, 17 Nov 2025 18:54:16 +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=1763405659; cv=none; b=F1Z/0NftzrBmDWj8DfqRgB1ckK7eJL9bYYEg9iuH/teivNJOHhFE6p4hNPjMLrRCD+07sU0jiRJkk5FxszlZ+ms06GQ+Nhj8Pry4R7XZkJuKHjI1+0NNdQuuab74laTi3G3OE+Dn443VEYH0aueWMF6bDqXSXBkjO4TBPD31B5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405659; c=relaxed/simple; bh=YWrSV4nY4LocEp7mCnwqF5xXNyBYnRwLmTPE4sU0cPE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KxbVswITi2yTNmWoBm38DhEiCFCOpK2xXOsqwfCne4taCnUcz1vc3IRsoAuRIHmf3TQIFP1TxvioeT+2zfBWBcdl90qoLM9+kAjq4J+a/ffYK8yBmMOAQuLwfVW9LDhGnN0iD+PZ7yf+qrM3bYwpfLpvZRIoB93knYLcQLaeiCk= 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=HccpLtMB; 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="HccpLtMB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763405655; 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=bFNQ6BM0IW516zJK11WM40Y2bQSeuES9ESqJWTtS0po=; b=HccpLtMBcfvysZ2MyG1Yw80NwpD/ZoeqzSo0e2DyI5vftyaOySuxmVa8/DQrSxxuplW/rC kL0t+Q7h3jUY0DrTRaGv2cENYtuLknroef/EhMyxyTyiKG3V7wMmNPoCh3kvIeJgW/Cg3D Atqn6NOPuO8fr7crpGC29QaiEW+fXC8= 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-328-4Ygaa0CeP7-nYKrFBbDUbQ-1; Mon, 17 Nov 2025 13:54:12 -0500 X-MC-Unique: 4Ygaa0CeP7-nYKrFBbDUbQ-1 X-Mimecast-MFC-AGG-ID: 4Ygaa0CeP7-nYKrFBbDUbQ_1763405651 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 8356C1801308; Mon, 17 Nov 2025 18:54:11 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.81.153]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C3536180049F; Mon, 17 Nov 2025 18:54:05 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Wander Lairson Costa , Tomas Glozar , Ivan Pravdin , Crystal Wood , John Kacur , Costa Shulyupin , Tiezhu Yang , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [rtla 01/13] rtla: Check for memory allocation failures Date: Mon, 17 Nov 2025 15:41:08 -0300 Message-ID: <20251117184409.42831-2-wander@redhat.com> In-Reply-To: <20251117184409.42831-1-wander@redhat.com> References: <20251117184409.42831-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_init() and actions_new() functions did not check the return value of calloc() and realloc() respectively. In a low memory situation, this could lead to a NULL pointer dereference. Add checks for the return value of memory allocation functions and return an error in case of failure. Update the callers to handle the error properly. Signed-off-by: Wander Lairson Costa Reviewed-by: Masami Hiramatsu (Google) --- tools/tracing/rtla/src/actions.c | 26 +++++++++++++++++++++++--- tools/tracing/rtla/src/actions.h | 2 +- tools/tracing/rtla/src/timerlat_hist.c | 7 +++++-- tools/tracing/rtla/src/timerlat_top.c | 7 +++++-- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/tools/tracing/rtla/src/actions.c b/tools/tracing/rtla/src/acti= ons.c index 8945aee58d511..01648a1425c10 100644 --- a/tools/tracing/rtla/src/actions.c +++ b/tools/tracing/rtla/src/actions.c @@ -11,11 +11,13 @@ /* * actions_init - initialize struct actions */ -void +int actions_init(struct actions *self) { self->size =3D action_default_size; self->list =3D calloc(self->size, sizeof(struct action)); + if (!self->list) + return -1; self->len =3D 0; self->continue_flag =3D false; =20 @@ -23,6 +25,7 @@ actions_init(struct actions *self) =20 /* This has to be set by the user */ self->trace_output_inst =3D NULL; + return 0; } =20 /* @@ -50,8 +53,13 @@ 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; + void *p =3D reallocarray(self->list, new_size, sizeof(struct action)); + + if (!p) + return NULL; + self->list =3D p; + self->size =3D new_size; } =20 return &self->list[self->len++]; @@ -65,6 +73,9 @@ actions_add_trace_output(struct actions *self, const char= *trace_output) { struct action *action =3D actions_new(self); =20 + if (!action) + return -1; + self->present[ACTION_TRACE_OUTPUT] =3D true; action->type =3D ACTION_TRACE_OUTPUT; action->trace_output =3D calloc(strlen(trace_output) + 1, sizeof(char)); @@ -83,6 +94,9 @@ actions_add_signal(struct actions *self, int signal, int = pid) { struct action *action =3D actions_new(self); =20 + if (!action) + return -1; + self->present[ACTION_SIGNAL] =3D true; action->type =3D ACTION_SIGNAL; action->signal =3D signal; @@ -99,6 +113,9 @@ actions_add_shell(struct actions *self, const char *comm= and) { struct action *action =3D actions_new(self); =20 + if (!action) + return -1; + self->present[ACTION_SHELL] =3D true; action->type =3D ACTION_SHELL; action->command =3D calloc(strlen(command) + 1, sizeof(char)); @@ -117,6 +134,9 @@ actions_add_continue(struct actions *self) { struct action *action =3D actions_new(self); =20 + if (!action) + return -1; + self->present[ACTION_CONTINUE] =3D true; action->type =3D ACTION_CONTINUE; =20 diff --git a/tools/tracing/rtla/src/actions.h b/tools/tracing/rtla/src/acti= ons.h index a4f9b570775b5..439bcc58ac93a 100644 --- a/tools/tracing/rtla/src/actions.h +++ b/tools/tracing/rtla/src/actions.h @@ -42,7 +42,7 @@ struct actions { struct tracefs_instance *trace_output_inst; }; =20 -void actions_init(struct actions *self); +int 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); diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/sr= c/timerlat_hist.c index 606c1688057b2..09a3da3f58630 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -798,8 +798,11 @@ static struct common_params if (!params) exit(1); =20 - actions_init(¶ms->common.threshold_actions); - actions_init(¶ms->common.end_actions); + if (actions_init(¶ms->common.threshold_actions) || + actions_init(¶ms->common.end_actions)) { + err_msg("Error initializing actions"); + exit(EXIT_FAILURE); + } =20 /* disabled by default */ params->dma_latency =3D -1; diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src= /timerlat_top.c index fc479a0dcb597..7679820e72db5 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -556,8 +556,11 @@ static struct common_params if (!params) exit(1); =20 - actions_init(¶ms->common.threshold_actions); - actions_init(¶ms->common.end_actions); + if (actions_init(¶ms->common.threshold_actions) || + actions_init(¶ms->common.end_actions)) { + err_msg("Error initializing actions"); + exit(EXIT_FAILURE); + } =20 /* disabled by default */ params->dma_latency =3D -1; --=20 2.51.1 From nobody Tue Dec 2 02:52:39 2025 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 C7537329E55 for ; Mon, 17 Nov 2025 18:54:33 +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=1763405675; cv=none; b=oRcGOsTE04h6EcZqjKKPUNDWyta4dyCI1kpWD24745NdkMoWBL4ZPfBgwVWXPIPytNgcAbyVEF/OSWtFP/RsBBU0g6RAWsyNCNm8ZPOgKVMcpONrzNNENWE5m4QPTTVa3XZjXak/hOTlngNUH0ydLs7HOJH4O3S/Ck+SnaecVJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405675; c=relaxed/simple; bh=YPixvNi32P13IxIqq7e56t+ezsA5HQVE4Nde4+v41lY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WkoZS0igLfZ7irUHiZfI/ooF9ZtoZ5HbMISg7yqSqqXs6e2loPO/d0dvVNWbFD9dkKp2pQs66PDwCv21Z/nsIDGhMF3pYQSxCxKtr4ddIqZLpUUaFYSU/ER/yQzNyDbK1XQQPWDZ0CRRFhmu88/0kNDrhBVp1l2G5OTGaIwM3tE= 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=R3dC8cZz; 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="R3dC8cZz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763405672; 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=lYplZIckiwqMSukeuleTlKYUvfjWjNZOEwl16HghBAQ=; b=R3dC8cZzn5LvedCD1TBM2QUIjhfjFM/Pe01IQ/JYRAZvEG5PvU0VU4nsVirDHnk+11klXr lNFrHIW1WFXmzJRrZrzoJddKxafGEkmAQbhmvNinZ/T3944vxesb0ZKpi5mKw6p2m1wX6z GwZqsun7+E8zlqSNm7n7DX1Zii8kpLs= 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-638-_X1R_qNuM26uU3_Td8F7cQ-1; Mon, 17 Nov 2025 13:54:29 -0500 X-MC-Unique: _X1R_qNuM26uU3_Td8F7cQ-1 X-Mimecast-MFC-AGG-ID: _X1R_qNuM26uU3_Td8F7cQ_1763405668 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 041E31956094; Mon, 17 Nov 2025 18:54:28 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.81.153]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8B031180049F; Mon, 17 Nov 2025 18:54:23 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Wander Lairson Costa , Tomas Glozar , Ivan Pravdin , Crystal Wood , John Kacur , Costa Shulyupin , Tiezhu Yang , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [rtla 02/13] rtla: Use strdup() to simplify code Date: Mon, 17 Nov 2025 15:41:09 -0300 Message-ID: <20251117184409.42831-3-wander@redhat.com> In-Reply-To: <20251117184409.42831-1-wander@redhat.com> References: <20251117184409.42831-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 01648a1425c10..696dd1ed98d9a 100644 --- a/tools/tracing/rtla/src/actions.c +++ b/tools/tracing/rtla/src/actions.c @@ -78,10 +78,9 @@ actions_add_trace_output(struct actions *self, const cha= r *trace_output) =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)); + action->trace_output =3D strdup(trace_output); if (!action->trace_output) return -1; - strcpy(action->trace_output, trace_output); =20 return 0; } @@ -118,10 +117,9 @@ actions_add_shell(struct actions *self, const char *co= mmand) =20 self->present[ACTION_SHELL] =3D true; action->type =3D ACTION_SHELL; - action->command =3D calloc(strlen(command) + 1, sizeof(char)); + action->command =3D strdup(command); if (!action->command) return -1; - strcpy(action->command, command); =20 return 0; } --=20 2.51.1 From nobody Tue Dec 2 02:52:39 2025 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 B5D7F33DED1 for ; Mon, 17 Nov 2025 18:54:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405691; cv=none; b=gq3Ov2m0eYmoxlqRCT0hf9xrFRLbTrbR4fc71JboZQN75U0UEpP0jsPQxrQdUYyoWtgFhfsBN2j7OzufJBeByco0TRm9iKJ+SKX3hf+J3iJ/6lCALb4VRzRjGfY1vD6jWzao/DWoczqI5Iu4p7mwDl40PXrFUwttBYsDGEZBdqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405691; c=relaxed/simple; bh=KZNGCErladIv7DUjLnlytiY04Zips/SMhtaQ8kxPwp0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bq5iFaD31rkMLLApJKoijKR7vV4gUavrwCRHIL1IIQb2rd+2Cv3g3GLNpI3uOBMtLNMZHP2oVHa/rz3f4kKXGG1b6L1eum7Z6ouatST8Wb1ZPDT3/pJvUwnEojyEFgIhV2DLxIjd7Zp8OUPaGAG1hyJj72qHW/N47sKSBeYF4oY= 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=KEjPyLoo; 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="KEjPyLoo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763405688; 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/91aqlMG90jMVYPWMYCXSLUYrI0o0P8LIA3DXEBJJo=; b=KEjPyLoolyE7lmbuMrW8BWERgAb/+o6lu4dYEP8mlxrE8BUzb5/L1dB89auV6/dELL7/Pd er0TKaQ1+MHKInuIyavjMHUrONMrj8doQgr0E1FVPqsGfa38/OJAUQptT6gYqAzqYcQ2GK EwwG30U4vc6e60zsBD+pJac4SUiGN9c= 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-348-rw7XQ3AoO8GbsHSx7CCgmg-1; Mon, 17 Nov 2025 13:54:45 -0500 X-MC-Unique: rw7XQ3AoO8GbsHSx7CCgmg-1 X-Mimecast-MFC-AGG-ID: rw7XQ3AoO8GbsHSx7CCgmg_1763405684 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 464D1195608E; Mon, 17 Nov 2025 18:54:44 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.81.153]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D4035180049F; Mon, 17 Nov 2025 18:54:39 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Wander Lairson Costa , Tomas Glozar , Ivan Pravdin , Crystal Wood , John Kacur , Costa Shulyupin , Tiezhu Yang , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [rtla 03/13] rtla: Introduce for_each_action() helper Date: Mon, 17 Nov 2025 15:41:10 -0300 Message-ID: <20251117184409.42831-4-wander@redhat.com> In-Reply-To: <20251117184409.42831-1-wander@redhat.com> References: <20251117184409.42831-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 696dd1ed98d9a..efa17290926da 100644 --- a/tools/tracing/rtla/src/actions.c +++ b/tools/tracing/rtla/src/actions.c @@ -35,7 +35,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) @@ -241,7 +243,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 439bcc58ac93a..9b9df57a0cb34 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)++) + int actions_init(struct actions *self); void actions_destroy(struct actions *self); int actions_add_trace_output(struct actions *self, const char *trace_outpu= t); --=20 2.51.1 From nobody Tue Dec 2 02:52:39 2025 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 2046F33DEF9 for ; Mon, 17 Nov 2025 18:55:07 +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=1763405708; cv=none; b=so0ucA13/I4fZM3hV9Kfzh+F3f1Brkc2LANV8pSUWTCxGL8mqCsFFTyxtXXat4/UK4ecdttCznr6ccieCONoZMjuv8YTtUgfKZbouagbCqvqRggaVKuqPWgIqUK00pZOWE2THZeGBHpPHmfUi/lvHhyBI6aBFpTWvqb5P92myY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405708; c=relaxed/simple; bh=5RJNINwKOegC+TYpBlH+UqIoj0Tco8gREjTvbLletXM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MJ8pj/BpMoSE6EFay3cfUbBHS4P3TmxCjpaif+CiBWN1ZEKQMSbMau95hCa9wLeTh5ZJu6AcoTexuj6dir+jVlpeoTKWfpXFX9afi4Z/aXon7I5E9I+HDEkJixrZm9OIiOsUuNvL4dxqUyz3554jroIMgiIoE6oH0piwvvjzBRo= 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=YL0zPlTM; 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="YL0zPlTM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763405706; 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=Tw35bMbNHdoPeMQhssL+Q3vPkPpSkCeP8NPmrUEswf4=; b=YL0zPlTMMpUSXQP5hc/G/DQgjr94sMe5HMNG4SF2pqYoCEETPwOkx/47ZQOumHsiShXAhR V6MTTK3LVwvPe/6iYqvlD16rV9VXfkpnCqSxAQB7PQZFXaeWoXbpiJTJbVPLlMOMfYlrKc /RIaSMDP/6yxW3D+UTMJdoJeKqD5+W4= 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-592-IrTOle35N5mH1AHUXqKtyA-1; Mon, 17 Nov 2025 13:55:02 -0500 X-MC-Unique: IrTOle35N5mH1AHUXqKtyA-1 X-Mimecast-MFC-AGG-ID: IrTOle35N5mH1AHUXqKtyA_1763405701 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 2C4BE1800EF6; Mon, 17 Nov 2025 18:55:01 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.81.153]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 19F0F180049F; Mon, 17 Nov 2025 18:54:55 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Wander Lairson Costa , Tomas Glozar , Ivan Pravdin , Crystal Wood , John Kacur , Costa Shulyupin , Tiezhu Yang , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [rtla 04/13] rtla: Replace atoi() with a robust strtoi() Date: Mon, 17 Nov 2025 15:41:11 -0300 Message-ID: <20251117184409.42831-5-wander@redhat.com> In-Reply-To: <20251117184409.42831-1-wander@redhat.com> References: <20251117184409.42831-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 boolean to indicate success or 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 | 6 +++-- tools/tracing/rtla/src/utils.c | 40 ++++++++++++++++++++++++++++---- tools/tracing/rtla/src/utils.h | 2 ++ 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/tools/tracing/rtla/src/actions.c b/tools/tracing/rtla/src/acti= ons.c index efa17290926da..e23d4f1c5a592 100644 --- a/tools/tracing/rtla/src/actions.c +++ b/tools/tracing/rtla/src/actions.c @@ -199,12 +199,14 @@ 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); + 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 d6ab15dcb4907..4cb765b94feec 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 @@ -112,16 +113,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++; @@ -322,6 +325,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", @@ -341,8 +345,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; @@ -959,3 +967,25 @@ int auto_house_keeping(cpu_set_t *monitored_cpus) =20 return 1; } + +/* + * strtoi - convert string to integer with error checking + * + * Returns true on success, false if conversion fails or result is out of = int range. + */ +bool strtoi(const char *s, int *res) +{ + char *end_ptr; + long lres; + + if (!*s) + return false; + + errno =3D 0; + lres =3D strtol(s, &end_ptr, 0); + if (errno || *end_ptr || lres > INT_MAX || lres < INT_MIN) + return false; + + *res =3D (int) lres; + return true; +} diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h index a2a6f89f342d0..160491f5de91c 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' @@ -80,6 +81,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); +bool 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.51.1 From nobody Tue Dec 2 02:52:39 2025 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 60D1133E377 for ; Mon, 17 Nov 2025 18:55:26 +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=1763405728; cv=none; b=SYECg03/COt/KkjYQSQVPA8nGKKIEZF6W4zmS8BJilrM9di+hZAWeDyGGuvQmTgjMnAv+zridaMPJBfrIBb2W3Zyp6+GhzOLz5t+69KsWkKA0M2qUTNoX2EyLDBr2iAp/GJmK/TyDhwhWd3sKiP9D9LxUcxgcvha21P131WpmLQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405728; c=relaxed/simple; bh=tImqdC5OOuw6pbQKrHUSqD+e0Avl+HgeBq15ztTcD7A=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WWl8oR5pWDawVLZh+KstmX9RHVQDFnZ2tohLFDT0FIfM1L44gRXZt9ZfJ70T8hpyd5rE0QgaKUaysFy/6OGBnmgQsYTMmLe88wuWqX20wFCy9Ta11z0FVX7PHWlzLB6ucJQ42tWGRtq8kL/387c211nCCHCL+LcLbc6MIYSef14= 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=V5XW+Cuq; 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="V5XW+Cuq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763405725; 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=1SPweW+DKunR1tbyeKWNvzzIK414Ai0gzFwnlL2yiZc=; b=V5XW+CuqwCI7Nv5CY5MMBS1aDiCIzeuA7MzyWJbuxxSr1G3Fst0QHYOw9XEyQ4Rv20zwUi /N2rkMrrfCX0pABWcELtxVwR6jO06Tg+UpRgHQaQZUf/gC40GdXdiLhW0u7EnA2pPAO3DP V3a3m9xbpaKckxO5Ha5QV2+B+TRNzD4= 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-1-4zoGgmFzMQS1WKUexE-_XQ-1; Mon, 17 Nov 2025 13:55:20 -0500 X-MC-Unique: 4zoGgmFzMQS1WKUexE-_XQ-1 X-Mimecast-MFC-AGG-ID: 4zoGgmFzMQS1WKUexE-_XQ_1763405717 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 7D51E18002D1; Mon, 17 Nov 2025 18:55:17 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.81.153]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AFCB3180049F; Mon, 17 Nov 2025 18:55:12 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Wander Lairson Costa , Tomas Glozar , Ivan Pravdin , Crystal Wood , John Kacur , Costa Shulyupin , Tiezhu Yang , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [rtla 05/13] rtla: Simplify argument parsing Date: Mon, 17 Nov 2025 15:41:12 -0300 Message-ID: <20251117184409.42831-6-wander@redhat.com> In-Reply-To: <20251117184409.42831-1-wander@redhat.com> References: <20251117184409.42831-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 | 37 ++++++++++++++++++++++---------- tools/tracing/rtla/src/utils.h | 14 ++++++++++-- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/tools/tracing/rtla/src/actions.c b/tools/tracing/rtla/src/acti= ons.c index e23d4f1c5a592..2a01ece78454c 100644 --- a/tools/tracing/rtla/src/actions.c +++ b/tools/tracing/rtla/src/actions.c @@ -143,15 +143,30 @@ actions_add_continue(struct actions *self) return 0; } =20 +/* + * 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) ( \ + strlen(token) > STRING_LENGTH(opt "=3D") && \ + !strncmp_static(token, opt "=3D") \ + ? (token) + STRING_LENGTH(opt "=3D") : NULL ) + /* * actions_parse - add an action based on text specification */ int actions_parse(struct actions *self, const char *trigger, const char *trace= fn) { + 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; @@ -182,12 +197,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) @@ -198,14 +211,15 @@ 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)) + arg_value =3D extract_arg(token, "num"); + if (arg_value) { + if (!strtoi(arg_value, &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) + } else if ((arg_value =3D extract_arg(token, "pid"))) { + if (strncmp_static(arg_value, "parent") =3D=3D 0) pid =3D -1; else - if (!strtoi(token + 4, &pid)) + if (!strtoi(arg_value, &pid)) return -1; } else { /* Invalid argument */ @@ -223,8 +237,9 @@ actions_parse(struct actions *self, const char *trigger= , const char *tracefn) 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); + arg_value =3D extract_arg(token, "command"); + if (arg_value) + return actions_add_shell(self, arg_value); return -1; case ACTION_CONTINUE: /* Takes no argument */ diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h index 160491f5de91c..f7ff548f7fba7 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.51.1 From nobody Tue Dec 2 02:52:39 2025 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 4640C32AAA4 for ; Mon, 17 Nov 2025 18:55:43 +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=1763405745; cv=none; b=LquVrWy6gR3mqSW2CTTM7gL/LVGRsWJdNhEKOaY4XJSuQ4zbMjbggAXZ5LjWGROtL7ftnlbBw/juNY1fN4oymJNuMvMdyOOCjYJkL03rk0xPR/F7SsyamQN7XEdSFA1drhdtMQs3Rb1OStm6HPy64S9P2vtF9KlvN1pkmbNsHlM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405745; c=relaxed/simple; bh=tnI1EaKbMieNMigeQvtO8p5L3U+og8rdEkrT0BhVuXs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jDZD4krq9jOtabloJh0+4kHF74nIV0rGz87S/fEfMT9LxCTSO3dwaYHmwyo8CWCKMjNcYLwEDulNIHAgDNDEvtQUS+X+hi7FceEb75t/aCy0wi0fpydQpGgOGUkuT0zT4vVUOsNQGIFPwDYY9clVbjNLUFtfJcg7z2msQYn6Vyc= 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=cvSSYKHD; 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="cvSSYKHD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763405743; 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=S3e7CVvlx3nIx4QGPbhLxrbC/FxCpFgytr2n93bg8nU=; b=cvSSYKHD0MR2d231aIDZLjyO9ArBR5alA1uPCRhrz8AIbUqhfslkB0nre9EhTTvdYFEceu WwjO069noyFNJlB3TcmBN1rbJ5+oEqAJIhfm/Jyo5VUnA2zTA2ZABVqcYGYQGIlUBET9Ky aDIbN2QCsah7oznx8GhZeCxyq3EaL14= 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-376-Lz-5stYsN4ur77cBx3ANnA-1; Mon, 17 Nov 2025 13:55:38 -0500 X-MC-Unique: Lz-5stYsN4ur77cBx3ANnA-1 X-Mimecast-MFC-AGG-ID: Lz-5stYsN4ur77cBx3ANnA_1763405733 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 6CED518A1B1A; Mon, 17 Nov 2025 18:55:33 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.81.153]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F04F41800367; Mon, 17 Nov 2025 18:55:28 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Wander Lairson Costa , Tomas Glozar , Ivan Pravdin , Crystal Wood , John Kacur , Costa Shulyupin , Tiezhu Yang , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [rtla 06/13] rtla: Use strncmp_static() in more places Date: Mon, 17 Nov 2025 15:41:13 -0300 Message-ID: <20251117184409.42831-7-wander@redhat.com> In-Reply-To: <20251117184409.42831-1-wander@redhat.com> References: <20251117184409.42831-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 312c511fa0044..5075e0f485c77 100644 --- a/tools/tracing/rtla/src/osnoise.c +++ b/tools/tracing/rtla/src/osnoise.c @@ -1229,7 +1229,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 b692128741279..56e0b8af041d7 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")) { @@ -275,7 +275,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 69cbc48d53d3a..813f4368f104b 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -372,7 +372,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 4cb765b94feec..f13d00d7b6bfe 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -196,15 +196,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.51.1 From nobody Tue Dec 2 02:52:39 2025 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 46307330323 for ; Mon, 17 Nov 2025 18:55:55 +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=1763405757; cv=none; b=QwLQnc1uBTI+iiVE1WWZXs77pnz1YUP4lu1VjVjRvtL0JhyU8BF1z3a6+/GdVN2/kCajgAXFvQkftD2qyRBZu6U1EVAuFZflv8HH2nzzpsf6pCJQOEg5OkbkrVP/Jgg3SVvmkK/tWHq98HqMUQbZI0gu23aMSpaY+a50vVks5hA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405757; c=relaxed/simple; bh=0DUJjjpWGFu3cxwZ4U+Q5JEjqJrK7b/UDtBTQaqQouw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c+EnQHnTugF+TAattwEy2wfxrmz8McClB+NKE0mShb/r+gaEB+JNE8dktNgMWeMjeH5RoF7iTIvNKvi3VvCQgDH6JDq6eZPkkV4w4yJcb4f190Q8mFZl2EVC68/MJmh02dsRtd+SrNJ500BWEUJC1EpNAHjqmKfT7y/xVjLcUYg= 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=JIhPXMGA; 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="JIhPXMGA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763405754; 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=fWTz1t3u2xCVa15Vvd3x9H1q+7O4K8arNn0cRNPfP4M=; b=JIhPXMGAZzkpMOgzazl+fl5Uh99xbuN1xN+1kkdDDBWwAWGDX1y2fq4Tw+huUhVe1qGffk HEPsKQRV5Sh7pgewLsx38xxDosoE63E9oxCqygwS9diVVag7BnAwNIYAHLzr3wKY7tuTkt Gk0F1U2NkFhsNglQbNz+40kS5nk8FXA= 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-323-kTKo6WKPM9-VZrKAIcFSUg-1; Mon, 17 Nov 2025 13:55:50 -0500 X-MC-Unique: kTKo6WKPM9-VZrKAIcFSUg-1 X-Mimecast-MFC-AGG-ID: kTKo6WKPM9-VZrKAIcFSUg_1763405749 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 9161A180047F; Mon, 17 Nov 2025 18:55:49 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.81.153]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2AA531800367; Mon, 17 Nov 2025 18:55:44 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Wander Lairson Costa , Tomas Glozar , Crystal Wood , Ivan Pravdin , John Kacur , Costa Shulyupin , Tiezhu Yang , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [rtla 07/13] rtla: Introduce timerlat_restart() helper Date: Mon, 17 Nov 2025 15:41:14 -0300 Message-ID: <20251117184409.42831-8-wander@redhat.com> In-Reply-To: <20251117184409.42831-1-wander@redhat.com> References: <20251117184409.42831-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 timerlat_hist and timerlat_top commands duplicate the logic for handling threshold actions. When a threshold is reached, both commands stop the trace, perform actions, and restart the trace if configured to continue. Create a new helper function, timerlat_restart(), to centralize this shared logic and avoid code duplication. This function now handles the threshold actions and restarts the necessary trace instances. Refactor timerlat_hist_main() and the timerlat_top 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/timerlat.c | 31 ++++++++++++++++++++++++++ tools/tracing/rtla/src/timerlat.h | 9 ++++++++ tools/tracing/rtla/src/timerlat_hist.c | 19 ++++++++-------- tools/tracing/rtla/src/timerlat_top.c | 19 ++++++++-------- 4 files changed, 60 insertions(+), 18 deletions(-) diff --git a/tools/tracing/rtla/src/timerlat.c b/tools/tracing/rtla/src/tim= erlat.c index 56e0b8af041d7..50c7eb00fd6b7 100644 --- a/tools/tracing/rtla/src/timerlat.c +++ b/tools/tracing/rtla/src/timerlat.c @@ -22,6 +22,37 @@ =20 static int dma_latency_fd =3D -1; =20 +/** + * timerlat_restart - handle threshold actions and optionally restart trac= ing + * @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 +timerlat_restart(const struct osnoise_tool *tool, struct timerlat_params *= params) +{ + actions_perform(¶ms->common.threshold_actions); + + if (!params->common.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; +} + /* * timerlat_apply_config - apply common configs to the initialized tool */ diff --git a/tools/tracing/rtla/src/timerlat.h b/tools/tracing/rtla/src/tim= erlat.h index fd6065f48bb7f..47a34bb443fa0 100644 --- a/tools/tracing/rtla/src/timerlat.h +++ b/tools/tracing/rtla/src/timerlat.h @@ -31,6 +31,15 @@ struct timerlat_params { =20 #define to_timerlat_params(ptr) container_of(ptr, struct timerlat_params, = common) =20 +enum restart_result { + RESTART_OK, + RESTART_STOP, + RESTART_ERROR =3D -1, +}; + +enum restart_result +timerlat_restart(const struct osnoise_tool *tool, struct timerlat_params *= params); + int timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_param= s *params); int timerlat_main(int argc, char *argv[]); int timerlat_enable(struct osnoise_tool *tool); diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/sr= c/timerlat_hist.c index 09a3da3f58630..f14fc56c5b4a5 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -1165,18 +1165,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 timerlat_restart(tool, params); + 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 7679820e72db5..d831a9e1818f4 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -921,18 +921,19 @@ timerlat_top_bpf_main_loop(struct osnoise_tool *tool) =20 if (wait_retval =3D=3D 1) { /* 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 timerlat_restart(tool, params); + 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.51.1 From nobody Tue Dec 2 02:52:39 2025 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 6987533291B for ; Mon, 17 Nov 2025 18:56:11 +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=1763405772; cv=none; b=moPgqp49cx27zmrJ+0oW10MDvIvyqQxaPfQ9jXsAvDmqjWXLIEuEalM3bQLVPlKlB5E1GDChjfE/JWABydpftrCfdLxF4lYeuXkYDVa+blsH3+JA652wlmXKnerMfMsnZ4Tg+AtZETCcwScXRb/hIGJUmv6N/zttYNkzBp9Jyj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405772; c=relaxed/simple; bh=zuQMygyE/fNMvfguYZAXLubepSrga+iMRwkhc12myPo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lniG4sXd9GyrG9l24761sNQ2k/H53kwfzkyq8m4f+GsXxPWhwC9RhR4J7n6j36+dG71YOONHJH5JnzE0JkVOOts3rcuyUpNgPvhMZHLnCFWRpRRW872HvGzQSltsWO2uMzCC2KgqD6LTvY20rJG671FqiR6pWeCEESEyCMa7Dqk= 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=N6jSf2/9; 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="N6jSf2/9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763405770; 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=rkhAYW9mMK6YIr6jWOVp1CntEtvFvQsO6wElJ8Bztr0=; b=N6jSf2/9L+GQPFKg+dcUInw+ToTvcGWPhvA64JMTDi9/UhKRPbtlNmPNGwlMKEPlBm6eUC oI2OickUgBewkOoGN/+OXMgq+/O0euvKe+yrQ3atcPZmSBa329BlOeLF0MPNcOp86jSVCt yrGTC5fHEzRuYsbo0P3iXyyCNBJ+J9c= 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-641-coE_3v_4Om-tNrqBEl3pSw-1; Mon, 17 Nov 2025 13:56:07 -0500 X-MC-Unique: coE_3v_4Om-tNrqBEl3pSw-1 X-Mimecast-MFC-AGG-ID: coE_3v_4Om-tNrqBEl3pSw_1763405766 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 00D97180122F; Mon, 17 Nov 2025 18:56:06 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.81.153]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 22E041800298; Mon, 17 Nov 2025 18:56:00 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Wander Lairson Costa , Tomas Glozar , Ivan Pravdin , Crystal Wood , John Kacur , Costa Shulyupin , Tiezhu Yang , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [rtla 08/13] rtla: Use standard exit codes for result enum Date: Mon, 17 Nov 2025 15:41:15 -0300 Message-ID: <20251117184409.42831-9-wander@redhat.com> In-Reply-To: <20251117184409.42831-1-wander@redhat.com> References: <20251117184409.42831-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 f7ff548f7fba7..beff211fdae2d 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' @@ -97,7 +98,7 @@ bool strtoi(const 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.51.1 From nobody Tue Dec 2 02:52:39 2025 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 C1EA833556C for ; Mon, 17 Nov 2025 18:56: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=1763405789; cv=none; b=RjaaA9RH5UjbVoQZDEImla6OCDb/6qK31cb66K9E+DlDuZSeUNPX2ibYxvDkmQg9tfL9l1QVWKs89h9wq4khK5dETAPSS7wGbQzMy1U8LdF121lY7Cv/QJ3d0ZqKo2m7eD8jLVSpHW8ttEr0Cngvo9RbzDhjZUQzSJnk06wlRAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405789; c=relaxed/simple; bh=CTdSNQ9m4FPvDhaSyS7Md1HPseLc+GpMIEzjQiW7vDA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UzTFJ0xupoJH3/Mhdz9deDfu0P8DOWPKNL7vx4gsOOn7S9HUbDcTg3dgc6C7jO5afhxpXp01gIlMD4twVG0xU8r0T6ihpp2JSvw1pVwdxgdrRXBL5IAUZ4VqIA9D0iU9sQWuNAqy+V3rx6CGDwWerHAt/ktFOoFeU2hGUix0ZJY= 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=H8P89Eyy; 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="H8P89Eyy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763405786; 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=uCgxjdsl8Wp3jn7o2t/1VJkVLnufqkF/Oop+RfBQfkU=; b=H8P89EyyqsweFYpiFJVltl1jwMyXpoTWA5r0I0kzy9heHVlR8veKBXKdsRkg+SeGsQHQOk UUFZNR4CVphAZcAl7YuR8X2J8x7bu4IlZcCuUATKyj4srkeV1pDv+9XNdULC0D4/uUSHiC N/5lzokvOFEJZ5sxo8+Xv/tc5AnfdKA= 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-302-dJDrf3cHMTaPgzt3K_eI9A-1; Mon, 17 Nov 2025 13:56:23 -0500 X-MC-Unique: dJDrf3cHMTaPgzt3K_eI9A-1 X-Mimecast-MFC-AGG-ID: dJDrf3cHMTaPgzt3K_eI9A_1763405782 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 13FB51956057; Mon, 17 Nov 2025 18:56:22 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.81.153]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B9F45180087C; Mon, 17 Nov 2025 18:56:17 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Wander Lairson Costa , Tomas Glozar , Ivan Pravdin , Crystal Wood , John Kacur , Costa Shulyupin , Tiezhu Yang , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [rtla 09/13] rtla: Exit if trace output action fails Date: Mon, 17 Nov 2025 15:41:16 -0300 Message-ID: <20251117184409.42831-10-wander@redhat.com> In-Reply-To: <20251117184409.42831-1-wander@redhat.com> References: <20251117184409.42831-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() function can fail if it's unable to allocate memory for a new action. Currently, the return value is not checked, and the program continues to run, which can lead to unexpected behavior. Add a check to the return value of actions_add_trace_output() and exit with a proper error message if it fails. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/timerlat_hist.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/sr= c/timerlat_hist.c index f14fc56c5b4a5..39a14c4e07de8 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -1070,8 +1070,10 @@ static struct common_params } } =20 - if (trace_output) - actions_add_trace_output(¶ms->common.threshold_actions, trace_output= ); + if (trace_output && actions_add_trace_output(¶ms->common.threshold_ac= tions, trace_output)) { + err_msg("Could not add a new trace output"); + exit(EXIT_FAILURE); + } =20 if (geteuid()) { err_msg("rtla needs root permission\n"); --=20 2.51.1 From nobody Tue Dec 2 02:52:39 2025 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 A445E32E12A for ; Mon, 17 Nov 2025 18:56:43 +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=1763405805; cv=none; b=kcdRXIn4GMGN894cDqRhzj1+egbY9pBAUnQyPmTIGhNwAZBglkrP3dj7aM4gfB1Z2VYO29hItpJ0Z05/UqR9h615oiM+/qDdMzn+oXnhdjRv9I2Q4z1+QxHaeWJSTScaLnLe1fWGmSGtKGGVssHgDy6kHYPt3q/2Fcr+4mrU4E8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405805; c=relaxed/simple; bh=TGCoCAcq2y7OxivunBKMIbeWuNFR98CZQ62cm5S07F4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C2v+vmsUeFtJ1MW3ctSrn1gkzXjKNxULGg+fN4rV1hpaNigy0KaGzDIAi+6xJuOnTfUiXI2jCYUQ+nvmOqkck8yGBvBl1znD0zXkTVnkzGmQAIWdtlmi/J7pTi4vsxwmTjGIEXzzXfwTG3UObqsaA4AYBPvi5zEQy1cS3IvGgKQ= 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=YrCsJzTs; 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="YrCsJzTs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763405802; 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=8aE5DbYVi2HZztUMg23QDXtKPFVnuO/XlPsKz1PiYi4=; b=YrCsJzTsgsn6dDyrJEnIpyQFULHNjN7Cpud62iFY2mcv9vQAyt3AJtUnG9opsaMqpZaxvB km3W7ZG525iZCEZFBj3Hs+GNRXtye4PkPmVo7nehVBRiE4y4iPCuYzIWq/sdElbQdw2Yql lQy+99ikQsjvMnszEws6VzBtZNw1++Y= 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-634-gB1xQUfCP9WI-rotCyQuxA-1; Mon, 17 Nov 2025 13:56:39 -0500 X-MC-Unique: gB1xQUfCP9WI-rotCyQuxA-1 X-Mimecast-MFC-AGG-ID: gB1xQUfCP9WI-rotCyQuxA_1763405798 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 5C0371956096; Mon, 17 Nov 2025 18:56:38 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.81.153]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4173B180049F; Mon, 17 Nov 2025 18:56:33 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Wander Lairson Costa , Tomas Glozar , Crystal Wood , Ivan Pravdin , John Kacur , Costa Shulyupin , Tiezhu Yang , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [rtla 10/13] rtla: Remove redundant memset after calloc Date: Mon, 17 Nov 2025 15:41:17 -0300 Message-ID: <20251117184409.42831-11-wander@redhat.com> In-Reply-To: <20251117184409.42831-1-wander@redhat.com> References: <20251117184409.42831-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 2a01ece78454c..2d153d5efdea2 100644 --- a/tools/tracing/rtla/src/actions.c +++ b/tools/tracing/rtla/src/actions.c @@ -21,8 +21,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; return 0; --=20 2.51.1 From nobody Tue Dec 2 02:52:39 2025 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 A7BD9338F2F for ; Mon, 17 Nov 2025 18:56:59 +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=1763405822; cv=none; b=IJSZGz6IVJcV9bnHVrAmSUAvHr19pL4XVSIg2MsXmhpDh6qU+ZhJrsfZ3hCNTaVYJfG0GluU/4yd1hRobNQkib6fmJtqXUDjP1mhEiklUjRE0QxSq+7txKKu7IvHYtn0+rKZXq8BgFqBi6ecONAtArJUlsEm6fp3Fg7qUUsPQM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405822; c=relaxed/simple; bh=dKoUYxM8LL9t2vzI/PpW0eLOO45rOCFrE/qFP2Mf2do=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mXcp3AOoRyrZKWPj4MFRAtjyvtG5/+ih93uNDSwzF+lkC+qN1tmEKOuFaUwyUjjvtUJJovGALJKbNd2w+1a2eJnVfNVrAxwr1loPSMsdNZEw8LF8R4ttbX/+6ctdeThoaEjtxxdr4qS7IrtdykHNnZWjKcrA65matXt1NhAO1Po= 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=dic/6yfV; 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="dic/6yfV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763405818; 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=W92+hDsPlnWwpf3RV+flsE4eFQLqmU6MxoptDwLVLG4=; b=dic/6yfVAf4nWZDPPLjDikWlnTj4tlnnzlEClFdYPtcYgSEBJMRPyuco9JRCMc9b7/KSRr 6XTJIN+KPvyhbqK39lu1uxQYZ98XTNypBugJsOXqx/MNVIJmf2NLuQkyEnr2JZ/Pg0VQs8 y01wJis4QUFB9jtQuMT7HEAYk/nivWw= 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-544-WJFHpT6FO62vQGJQD6W6Rw-1; Mon, 17 Nov 2025 13:56:55 -0500 X-MC-Unique: WJFHpT6FO62vQGJQD6W6Rw-1 X-Mimecast-MFC-AGG-ID: WJFHpT6FO62vQGJQD6W6Rw_1763405814 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 3962E1956094; Mon, 17 Nov 2025 18:56:54 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.81.153]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1FB8D180049F; Mon, 17 Nov 2025 18:56:49 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Wander Lairson Costa , Tomas Glozar , Ivan Pravdin , Crystal Wood , John Kacur , Costa Shulyupin , Tiezhu Yang , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [rtla 11/13] rtla: Replace magic number with MAX_PATH Date: Mon, 17 Nov 2025 15:41:18 -0300 Message-ID: <20251117184409.42831-12-wander@redhat.com> In-Reply-To: <20251117184409.42831-1-wander@redhat.com> References: <20251117184409.42831-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 5075e0f485c77..d502cbbcea91b 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 01dbf9a6b5a51..52977e725c79c 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; @@ -87,7 +87,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 813f4368f104b..658a6e94edfba 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -330,7 +330,7 @@ int 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) @@ -342,7 +342,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); @@ -361,7 +361,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) @@ -376,7 +376,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 @@ -408,7 +408,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) @@ -422,7 +422,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); @@ -461,7 +461,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) @@ -473,7 +473,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); @@ -496,7 +496,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) @@ -508,7 +508,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.51.1 From nobody Tue Dec 2 02:52:39 2025 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 7490933E341 for ; Mon, 17 Nov 2025 18:57:15 +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=1763405837; cv=none; b=ClTBgBqLB9vIX/2C92N4G7/Bz3njuu95lu+QbGtvYLYmaEIBKR1IjvZXpLFrBtkpDnjTsYF1tsT9N238EF3aCunHOeg4Qjxc27SgZXge34Igt29SQSDf7AQ5r2IMAkY+Hz2Y8VKOr5zY3E5RH987S/7o+aGNAFM5G48ZkGNoK8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405837; c=relaxed/simple; bh=9LHwH85GVx+dILDMq0gSzAtnCgezKegZ1fVjvhUvgA4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nOfyVjx0j+HeQUMnrbyCLeLJL3B14e9Q0rPtRhoJxJiA5LF60LYyqvEIr01YYUrd1XIIifdTqXZ9V0v8VlZjDWVx778WarMZp7sU+hmP/FzewZFbmqh2gAGBMQeDeb7PI0e4A8LNBmQvF8yuGHDR9JSNXYkmeRwMPeWMm5QVVu8= 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=ZD5/qfAX; 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="ZD5/qfAX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763405834; 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=rUJiSXgP7OYZRNQjJLoq/fTS0neWpO/zNbumzcyTMMc=; b=ZD5/qfAXJOVngGLzp+SlHFi6zlj2P6AiIyxj3gkXfleIwa+8k5oJNWkJMbjyOTqMBH9zXQ WrJEUsXAzPDwfdyvutONKU4lO3LVF3Spe4cmAFf39uG0FrcqGbvKnblcMqCj+m2a6PTVd/ tDa7/QpwfMX0u1/+e5NlEtPf/sx2JAQ= 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-536-U9qG0fP1OjWxBOf_WPUeJA-1; Mon, 17 Nov 2025 13:57:11 -0500 X-MC-Unique: U9qG0fP1OjWxBOf_WPUeJA-1 X-Mimecast-MFC-AGG-ID: U9qG0fP1OjWxBOf_WPUeJA_1763405830 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 034FB18AB414; Mon, 17 Nov 2025 18:57:10 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.81.153]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EF9FB180049F; Mon, 17 Nov 2025 18:57:05 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Wander Lairson Costa , Tomas Glozar , Crystal Wood , Ivan Pravdin , John Kacur , Costa Shulyupin , Tiezhu Yang , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [rtla 12/13] rtla: Remove unused headers Date: Mon, 17 Nov 2025 15:41:19 -0300 Message-ID: <20251117184409.42831-13-wander@redhat.com> In-Reply-To: <20251117184409.42831-1-wander@redhat.com> References: <20251117184409.42831-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 dffb6d0a98d7d..44614f56493f2 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 50c7eb00fd6b7..9b77dbcbd1375 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 d831a9e1818f4..7f2491e72e495 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 658a6e94edfba..ab2bf6d04f2ee 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.51.1 From nobody Tue Dec 2 02:52:39 2025 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 53F2C33CEA4 for ; Mon, 17 Nov 2025 18:57:31 +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=1763405852; cv=none; b=XLlvDbAf2sitTpWLJc8wQyB55eODl39oimuP7IOWfeidFTHeuLZT/jFF58QaFYQcx3+AvATH713lmNhAO+asYWbsh+ldWAqJ012WAnU14Rt+cYjfkBOEIdDXTj66s4YkRCtw7iXer+YuGKBqogSX6mRHEEq6Do2lRbAs45yEar4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405852; c=relaxed/simple; bh=bD12Zma+HqAn33iDOUsFKDSv5z71KSEUkEEij0/v2hg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eI9Y2+F7Ye8och49Zf3N3i6IorZrzWlskugsNs0FHePBFMQcCuevZUxYIDqHk3I2qJ53p+f1j/Auu62R8/EKHV1lfsZQFundo0T5kNxLohaBv1lSD1bDJuVG1J0AMLCNc9UDZTuEH6sOg1VPAj6E1DJXC4r10T+a0D0dzmcM7BY= 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=d1V8jRIw; 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="d1V8jRIw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763405850; 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=iJgzWUqlEf8G/5190vKWYurdG9FvRAIrgrn7gi1E2RQ=; b=d1V8jRIwiSffn9wR11QT75XAY9V6UDdduJ6KLsD48yxywbJgWLMXMZVRf2vqjVO+Sy8mBe Fz8m5PgKiG7FLB+3JLfh3kW3CmxO9HnDfhjHX1YTVmnP4mMVHb7dkT5wHdXUjXS45VNE1/ hDbuVWdptmkCEvhInfl14gzKQHiObBU= 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-675-k3ENyNDvN7KLae-DJ5KLZg-1; Mon, 17 Nov 2025 13:57:27 -0500 X-MC-Unique: k3ENyNDvN7KLae-DJ5KLZg-1 X-Mimecast-MFC-AGG-ID: k3ENyNDvN7KLae-DJ5KLZg_1763405846 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 E867E1956069; Mon, 17 Nov 2025 18:57:25 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.81.153]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C1255180049F; Mon, 17 Nov 2025 18:57:21 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Wander Lairson Costa , Tomas Glozar , Ivan Pravdin , Crystal Wood , John Kacur , Costa Shulyupin , Tiezhu Yang , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [rtla 13/13] rtla: Fix inconsistent state in actions_add_* functions Date: Mon, 17 Nov 2025 15:41:20 -0300 Message-ID: <20251117184409.42831-14-wander@redhat.com> In-Reply-To: <20251117184409.42831-1-wander@redhat.com> References: <20251117184409.42831-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 leave the action list in an inconsistent state when strdup() fails. The actions_new() function increments self->len before returning a pointer to the new action slot, but if the subsequent strdup() allocation fails, the function returns an error without decrementing self->len back. This leaves an action object in an invalid state within the list. When actions_destroy() or other functions iterate over the list using for_each_action(), they will access this invalid entry with uninitialized fields, potentially leading to undefined behavior. Fix this by decrementing self->len when strdup() fails, effectively returning the allocated slot back to the pool and maintaining list consistency even when memory allocation fails. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/actions.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/tracing/rtla/src/actions.c b/tools/tracing/rtla/src/acti= ons.c index 2d153d5efdea2..4aaaedadcc42a 100644 --- a/tools/tracing/rtla/src/actions.c +++ b/tools/tracing/rtla/src/actions.c @@ -76,11 +76,13 @@ actions_add_trace_output(struct actions *self, const ch= ar *trace_output) if (!action) return -1; =20 - self->present[ACTION_TRACE_OUTPUT] =3D true; action->type =3D ACTION_TRACE_OUTPUT; action->trace_output =3D strdup(trace_output); - if (!action->trace_output) + if (!action->trace_output) { + self->len--; // return the action object to the pool return -1; + } + self->present[ACTION_TRACE_OUTPUT] =3D true; =20 return 0; } @@ -115,11 +117,13 @@ actions_add_shell(struct actions *self, const char *c= ommand) if (!action) return -1; =20 - self->present[ACTION_SHELL] =3D true; action->type =3D ACTION_SHELL; action->command =3D strdup(command); - if (!action->command) + if (!action->command) { + self->len--; return -1; + } + self->present[ACTION_SHELL] =3D true; =20 return 0; } --=20 2.51.1